Skip to main content
Version: 0.17

Class: Notifier

The Notifier class can emit messages to an array of subscribed listeners. Here's a simple example:

import { Notifier } from '@orbit/core';

let notifier = new Notifier();
notifier.addListener((message: string) => {
console.log("I heard " + message);
});
notifier.addListener((message: string) => {
console.log("I also heard " + message);
});

notifier.emit('hello'); // logs "I heard hello" and "I also heard hello"

Calls to emit will send along all of their arguments.

Constructors​

constructor​

• new Notifier()

Defined in​

packages/@orbit/core/src/notifier.ts:26

Properties​

listeners​

• listeners: Listener[]

Defined in​

packages/@orbit/core/src/notifier.ts:24

Methods​

addListener​

â–¸ addListener(listener): () => void

Add a callback as a listener, which will be triggered when sending notifications.

Parameters​

NameType
listenerListener

Returns​

fn

â–¸ (): void

Add a callback as a listener, which will be triggered when sending notifications.

Returns​

void

Defined in​

packages/@orbit/core/src/notifier.ts:34


emit​

â–¸ emit(...args): void

Notify registered listeners.

Parameters​

NameType
...argsunknown[]

Returns​

void

Defined in​

packages/@orbit/core/src/notifier.ts:57


removeListener​

â–¸ removeListener(listener): void

Remove a listener so that it will no longer receive notifications.

Parameters​

NameType
listenerListener

Returns​

void

Defined in​

packages/@orbit/core/src/notifier.ts:43