Class

NotificationManager

NotificationManager()

The NotificationManager is a centralised means to send / receive notifications within an SPA.

The export instantiates a NotificationManager to provide a singleton instance of the manager, so that all subscribers and all senders are using the same manager.

The instantiated notification manager can be imported from the standard webapp library, i.e.

     import { notifications } from '@jcu/spark'`

The notifications object can then be used to attach subscribers to receive notifications:

     notifications.subscribe('myNotifID', (notification) => {//Do Something})

It can also be used to send notifications to any existing subscribers:

     notifications.notify({
         title: 'Email not saved',
         message: 'Your profile settings changed; check your profile to see the updated information.'
     })

By default, the JCU web app framework comes with a popup notification layer automatically subscribed. Therefore all SPAs have capacity for popup notifications to be sent to the user.

Constructor

# new NotificationManager()

View Source services/NotificationManager.ts, line 34

Members

# subscribers

List of objects defining the currently subscribed consumers.

View Source services/NotificationManager.ts, line 39

Array

# subscribers

List of objects defining the currently subscribed consumers.

View Source services/NotificationManager.ts, line 186

Methods

# error(notification, options)

Wrapper function for sending a notification with a level of "error".

Can take a Notification object or a string. If a string is provided, it is converted into the message portion of a standard Notification.

Parameters:
Name Type Description
notification Notification | string

Notification / message to send out to subscribers

options Object

Extra notification options, mostly used by subscribers

View Source services/NotificationManager.ts, line 108

# notify(notification, options)

Wrapper function for sending a notification with a level of "information".

Can take a Notification object or a string. If a string is provided, it is converted into the message portion of a standard Notification.

Parameters:
Name Type Description
notification Notification | string

Notification / message to send out to subscribers

options Object

Extra notification options, mostly used by subscribers

View Source services/NotificationManager.ts, line 133

# publishNotification(notification, options)

Publish a Notification to all current subscribers. Generates UID for each notification for unique identification.

Parameters:
Name Type Description
notification Notification

Notification to send out to subscribers

options Object

Extra notification options, mostly used by subscribers

View Source services/NotificationManager.ts, line 66

# subscribe(id, pushHandle)

Provides the ability for notification consumers to subscribe to the notification engine. Consumers provide a function handle that takes in a Notification object, allowing the consumer to make decisions about how to handle the Notification.

Parameters:
Name Type Description
id string

Identity of notification consumer to subscribe to notifications

pushHandle function

Handle to the consumer function that takes in a Notification

View Source services/NotificationManager.ts, line 49

# success(notification, options)

Wrapper function for sending a notification with a level of "success".

Can take a Notification object or a string. If a string is provided, it is converted into the message portion of a standard Notification.

Parameters:
Name Type Description
notification Notification | string

Notification / message to send out to subscribers

options Object

Extra notification options, mostly used by subscribers

View Source services/NotificationManager.ts, line 158

# unsubscribe(id)

Unsubscribe a consumer from receiving notifications based on the provided ID.

Parameters:
Name Type Description
id string

Identity of notification consumer to unsubscribe

View Source services/NotificationManager.ts, line 57

# warn(notification, options)

Wrapper function for sending a notification with a level of "warn".

Can take a Notification object or a string. If a string is provided, it is converted into the message portion of a standard Notification.

Parameters:
Name Type Description
notification Notification | string

Notification / message to send out to subscribers

options Object

Extra notification options, mostly used by subscribers

View Source services/NotificationManager.ts, line 83