Skip to content

Functions:Implementations

Paul Engel edited this page Dec 17, 2021 · 10 revisions

Function Implementations

In conjunction with the function definition, you have to write the function implementation. That is the Javascript function that gets executed at runtime.

Provided to the function is the input as described in the corresponding function definition. The no-coder should have specified the actual values within de IDE.

The say-hello example

Whenever you have created a new project, it will include the say-hello example.

Its function definition (functions/say-hello/function.json):

{
  "description": "Say Hello to the world",
  "name": "sayHello",
  "label": "Say Hello",
  "category": "Misc",
  "icon": "CreateIcon",
  "options": [
    {
      "meta": {
        "type": "Text"
      },
      "name": "name",
      "label": "Name",
      "info": "The name that's going to be used to say hello to the world!",
      "advanced": false,
      "configuration": {
        "placeholder": "Betty Blocks"
      }
    },
    {
      "meta": {
        "type": "Output",
        "output": {
          "type": "Text"
        }
      },
      "name": "greet",
      "label": "As",
      "info": "The resulting greet to the world."
    }
  ],
  "yields": "NONE"
}

As you can see, the sayHello function definition describes two options:

  • name - the name to say hello to (input of type String)
  • greet - the return value containing the greet (output of type String)

Its function implementation (functions/say-hello/index.js):

import join from 'lodash/join';

const sayHello = async ({ name }) => {
  if (name === 'oops') {
    throw new Error('Ooops. Something went wrong.');
  } else {
    return {
      greet: join(['Hello', name], ', ')
    };
  }
}

export default sayHello;

The rules of the game

The implementation should comply to the following:

  • advised is to create an asynchronous function
  • input options are contained in the first argument as an object - { name }
  • it always has to return an object corresponding to the output options - { greet }
  • it has to default export the function - export default sayHello;

Please note that the name of the function should be the lower camelcased format of the kebabcased directory name.

Clone this wiki locally