diff --git a/README.md b/README.md index fbce079..875b5c4 100644 --- a/README.md +++ b/README.md @@ -25,11 +25,11 @@ Use code is very simple, just do following: ```JavaScript async function run(msg, cfg, snapshot) { - console.log('Incoming message is %s', JSON.stringify(msg)); - const body = { result : 'Hello world!' }; + this.logger.info('Incoming message is %j', msg); + const data = { result : 'Hello world!' }; // You can emit as many data messages as required - await this.emit('data', { body }); - console.log('Execution finished'); + await this.emit('data', { data }); + this.logger.info('Execution finished'); } ``` @@ -40,7 +40,7 @@ of your function, it will be automatically emitted as data. ### Doing complex data transformation -[JSONata](http://jsonata.org/) is great however sometimes it's easier to do things in JavaScript, if you want to transorm +[JSONata](http://jsonata.org/) is great however sometimes it's easier to do things in JavaScript, if you want to transform an incoming message with code, just use following sample: ```JavaScript diff --git a/component.json b/component.json index 0b3c930..f0173ff 100644 --- a/component.json +++ b/component.json @@ -8,7 +8,7 @@ "viewClass": "CodeFieldView", "label": "Code", "required": true, - "default": "// Please note only Node.js code is supported here\nasync function run(msg, cfg, snapshot) {\n\tthis.logger.info('Incoming message is %s', JSON.stringify(msg));\n\tconst body = { result : 'Hello world!' };\n\t// You can emit as many data messages as required\n\tawait this.emit('data', { body });\n\tthis.logger.info('Execution finished');\n}" + "default": "// Please note only Node.js code is supported here\nasync function run(msg, cfg, snapshot) {\n\tthis.logger.info('Incoming message is %j', msg);\n\tconst data = { result : 'Hello world!' };\n\t// You can emit as many data messages as required\n\tawait this.emit('data', { data });\n\tthis.logger.info('Execution finished');\n}" } }, "actions": {