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​
Name | Type |
---|---|
listener | Listener |
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​
Name | Type |
---|---|
...args | unknown [] |
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​
Name | Type |
---|---|
listener | Listener |
Returns​
void