This is an automated email from the ASF dual-hosted git repository.

tardieu pushed a commit to branch example
in repository https://gitbox.apache.org/repos/asf/openwhisk-composer.git

commit 1b6674752722dbe98f681bf1031a2556e53cf60a
Author: Olivier Tardieu <[email protected]>
AuthorDate: Tue Dec 10 14:54:58 2019 -0500

    Add example for dynamic combinator
---
 docs/COMBINATORS.md | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/docs/COMBINATORS.md b/docs/COMBINATORS.md
index 1294944..83f5d7e 100644
--- a/docs/COMBINATORS.md
+++ b/docs/COMBINATORS.md
@@ -69,10 +69,14 @@ assumed.
 
 Examples:
 ```javascript
-composer.action('hello')
+composer.action('hello') // default package
 composer.action('myPackage/myAction')
 composer.action('/whisk.system/utils/echo')
 ```
+To be clear, if no package is specified, the default package is assumed even if
+the composition itself is not deployed to the default package. To invoke an
+action from the same package as the composition the [`dynamic`](#dynamic)
+combinator may be used as illustrated [below](#example).
 
 ### Action definition
 
@@ -532,3 +536,29 @@ Other fields of the input parameter object are ignored.
 The `dynamic` combinator invokes the action named _name_ with the input
 parameter object _params_. The output parameter object for the composition is
 the output parameter object of the action invocation.
+
+### Example
+
+The `dynamic` combinator may be used for example to invoke an action that
+belongs to the same package as the composition, without having to specify the
+package name beforehand.
+
+```javascript
+const composer = require('openwhisk-composer')
+
+function invoke (actionShortName) {
+  return composer.let(
+    { actionShortName },
+    params => ({ type: 'action', params, name: 
process.env.__OW_ACTION_NAME.split('/').slice(0, 
-1).concat(actionShortName).join('/') }),
+    composer.dynamic())
+}
+
+module.exports = composer.seq(
+  composer.action('echo'), // echo action from the default package
+  invoke('echo')           // echo action from the same package as the 
composition
+)
+```
+In this example, `let` captures the target action short name at compile time
+without expanding it to a fully qualified name. Then, at run time, the package
+name is obtained from the environment variable `__OW_ACTION_NAME` and combined
+with the action short name. Finally, `dynamic` is used to invoke the action.
\ No newline at end of file

Reply via email to