Function Standard
The handler is known as the entry point for your EXM function. This handler is a method named
handle
in the language you are writing your EXM function in. A few examples are shown below:Javascript
AssemblyScript
export async function handle(state, action) {}
import { JSON, JSONEncoder } from "assemblyscript-json";
export function handle(state: JSON.Obj, action: JSON.Obj): JSONEncoder {}
For a write operation to be able to change the state of the function, it needs to return an object with
state
property in it. export async function handle(state, action) {
return { state: /* state */ }
}
In the example above, an array of objects (
users
) is returned inside the state
property, this means, the new state of the function is equal to users
.It is not mandatory to return JSON objects or arrays but anything can be returned for the state of the function.
A write operation can execute code and return it in the same way a serverless function would. To do this, you can return an object with the property
result
export async function handle(state, action) {
return { result: ' Some Value' }
}
- A function can return
state
withoutresult
- A function can return
result
withoutstate
(No updates will be made to the state) - A function can return both
result
andstate
Last modified 2mo ago