Skip to main content

Notifications

Sometimes it is helpful to convey the state of a node such as progress, warnings, or errors. This is called Node Notification and it is very simple to do. The context.notify() function allows your to specify a notification state, and a notification message to display. context.notify() has the following signature:

context.notify(<state>, <message>);

Where state is one of the Notification State values shown below, and message is any string of text you want to display.

Notification States

The following notification states are supported:

  • success - Indicates some successful action or operation.
  • warning - Indicates the node is in a warning state and needs attention.
  • error - Indicates the node is in an error state and failing to execute for some reason.
  • info - Indicates some information to the node user.
  • fetching - Indicates the node is fetching data from an external source. The fetching state is not automatically changed to the fetched state. It is incumbent on the developer to change to the notification states when the fetching operation is done.
  • fetched - Indicates the node completed fetching data from an external source.
  • loading - Indicates some portion of the node is in the loading state. The loading state is not automatically changed to the loaded state. It is incumbent on the developer to change to the notification states when the loading operation is done.
  • loaded - Indicates the the node has loaded completely.
Note

The loading state and the fetching state are not automatically changed to the loaded state or fetched state automatically. It is incumbent on the developer to change to these notification states when the loading/fetching operation is done.

Demo

In this example the node will cycle through a series of loading states to show off the differernt styles.

 

src/main.ts
context.notify('error', 'Error occured!');
context.notify('warning', 'Authentication may be required');
context.notify('success', 'Success!');
context.notify('info', 'Parsing data');
context.notify('fetching', 'Downloading data...');
context.notify('fetched', 'Data downloaded!');
context.notify('loading', 'Calculating...');
context.notify('loaded', 'Done processing!');

Example

In this example the node simulates fetching data from Github, showing a notification it is Fetching data... and then a notification of Data Fetched! when the data is returned and populated into ((Github_Issues)). The simulation will then reset itself after 10 seconds and then run again.

src/main.ts
setTimeout(() => {
context.notify('fetching', 'Fetching data...');
const response = new Promise((resolve) => {
setTimeout(() => resolve({'github': 'results'}), 3000);
})
if (!response.ok) {
response.then((result) => {
context.set('githubIssues', result);
context.notify('fetched', 'Data Fetched!');
})
} else {
context.notify('error', 'Error Fetching Data.');
}
}, 1000)