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.
Example
Section titled “Example”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`);});Methods
Section titled “Methods”declare()
Section titled “declare()”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 Parameters
Section titled “Type Parameters”| Type Parameter | Default type | Description |
|---|---|---|
T |
undefined |
the type of the data that the event carries |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
name |
string |
the name of the event |
Returns
Section titled “Returns”Topic<T>
the event, which post and subscribe take as an argument
post()
Section titled “post()”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 Parameters
Section titled “Type Parameters”| Type Parameter | Description |
|---|---|
T |
the type of the data that the event carries |
Parameters
Section titled “Parameters”| 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 |
Returns
Section titled “Returns”void
subscribe()
Section titled “subscribe()”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 Parameters
Section titled “Type Parameters”| Type Parameter | Default type | Description |
|---|---|---|
T |
unknown |
the type of the data that the event carries |
Parameters
Section titled “Parameters”| 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 } |
Returns
Section titled “Returns”object
an object with dispose(), which stops the listening
| Name | Type |
|---|---|
dispose() |
() => void |
