Hello Worldlink

To create a basic "hello world" program, click on the "New" button and select "Blank"

The New Program Button

It will ask you to name your brand new program, try "hello-world".

A new program will be created in you workspace with two files:

  • index.ts where the code lives
  • memconfig.json where the schema, dependencies and expressions go.

This program is now in your local workspace but it's not immediately running in your account.

To run it, use the command Membrane: Update current program from the Visual Studio Code command palette (cmd+p). Alternatively use or mctl update hello-world from the command line. This command can be used again to update the program once you've changed it.

The 'Membrane: Update current program' command

Understanding "hello-world"link

In the newly created memconfig.json file you'll find the schema of the program. It declares a Root type (all programs must have a Root type) with an action called setup:

{
  "schema": {
    "types": [
      {
        "name": "Root",
        "actions": [
          {
            "name": "setup",
            "type": "Void"
          }
        ]
      }
    ]
  }
}

In index.ts you'll see the function that handles setup:

export async function setup() {
  console.log("Hello World");
}

This function doesn't need to be async, but we generate it async becuase you'll most likely use it to interact with the graph, which is always done asynchronously.

Invoking the Actionlink

Finally, to invoke the setup action you can use the Membrane Explorer.

If you haven't yet, open the Membrane Explorer using the View: Focus on Membrane Explorer View. For convenience, we recommend moving this view to the right side of Visual Studio

Click on the hello-world program and then on the setup action. This will let you invoke the action. You should see "Hello World" printed in the logs below:

Logs pane showing the 'Hello World' output

Adding a parameterlink

Let's make it a bit more interesting by adding a parameter to setup. In memconfig.json add a parameter to the action:

...
          {
            "name": "setup",
            "type": "Void",
            "params": [
              { "name": "name", "type": "String" }
            ]
          }
...

And then modify index.ts to handle this new parameter:

export async function setup({ args }) {
  console.log(`Hello ${args.name}`);
}

Update your program again and you should see a field in the Membrane Explorer that lets you pass the parameter value:

Logs pane showing the 'Hello World' output

Finally, clicking "Invoke" again should print whatever argument is passed.

...