Skip to content

PluginNotifications

Sends events and listens to events. An event is a message that a plugin or the app sends, and that any plugin can listen to. declare creates an event, post sends it, and subscribe listens to the events of the plugin and to the events of the app. A plugin can only send the events that it declared.

Tell the other plugins that a session is over

const sessionOver = ctx.notifications.declare<{ minutes: number }>('com.example.pomodoro/session-over');
ctx.notifications.post(sessionOver, row.id, { minutes: 25 });
ctx.notifications.subscribe({ topic: sessionOver }, { style: 'asap' }, n => {
ctx.log('info', `${n.object}: ${n.info?.minutes} minutes`);
});
declare<T>(name): Topic<T>;

Creates an event. The name of the event is written here once, and it starts with the id of the plugin.

Type Parameter Default type Description
T undefined the type of the data that the event carries
Parameter Type Description
name string the name of the event

Topic<T>

the event, which post and subscribe take as an argument


post<T>(
topic,
object?,
info?
): void;

Sends an event. A plugin can only send the events that it declared. Using it requires the notifications permission.

Type Parameter Description
T the type of the data that the event carries
Parameter Type Description
topic Topic<T> an event that the plugin declared
object? string what the event is about. A listener can filter on it
info? T the data that the event carries

void


subscribe<T>(
spec,
options,
handler
): object;

Listens to events, either the events of the plugin or the events of the app (ctx.topics). Using it requires the read permission.

Type Parameter Default type Description
T unknown the type of the data that the event carries
Parameter Type Description
spec { object?: string; topic?: Topic<T>; } the event to listen to (topic) and, optionally, the object to listen for
spec.object? string -
spec.topic? Topic<T> -
options { coalesce?: "none" | "onName" | "onSender"; style: "now" | "idle" | "asap"; } style says when the handler is called: now calls it at once, asap calls it as soon as the work in progress is done, and idle calls it when the person stops typing. coalesce joins a burst of events into one call: none, onName or onSender
options.coalesce? "none" | "onName" | "onSender" -
options.style "now" | "idle" | "asap" -
handler (notification) => void receives { name, object, info }

object

an object with dispose(), which stops the listening

Name Type
dispose() () => void