Skip to content

Events

Any Membrane program can emit events and subscribe to events.

For example, if you have a program that handles GitHub webhooks, your program could emit a ghWebhookReceived event, and another program that forwards GitHub notifications to Slack could subscribe to that event.

Emitting an event

import type { const root: Root

A gref to the root of this program.

root
} from "membrane";
export const
const endpoint: (req: {
    method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
    path: string;
    body?: string;
    query?: string;
    headers: string;
}) => string
endpoint
: resolvers.interface resolvers.RootRoot["endpoint"] = (
req: {
    method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
    path: string;
    body?: string;
    query?: string;
    headers: string;
}
req
) => {
switch (`${
req: {
    method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
    path: string;
    body?: string;
    query?: string;
    headers: string;
}
req
.method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS"method} ${
req: {
    method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
    path: string;
    body?: string;
    query?: string;
    headers: string;
}
req
.path: stringpath}`) {
case "POST /gh-webhook-path": const root: Root

A gref to the root of this program.

root
.ghWebhookReceived.$emit();
/* ... */ } };

Subscribing to an event

import type { import nodesnodes } from "membrane";

export async function 
function sendToSlack(_: any, { event }: {
    event: any;
}): Promise<void>
sendToSlack
(_: any_, { event: anyevent }) {
await import nodesnodes.slack.channel(/* ... */).sendMessage(/* ... */); } export async function function configure(): Promise<void>configure() { import nodesnodes.ghWebhookReceived.$subscribe(
function sendToSlack(_: any, { event }: {
    event: any;
}): Promise<void>
sendToSlack
)
;
}