Skip to main content

notificationObserver

Types

function notificationObserver<GNotificationsUnion extends IGenericNotification>(
map: TInferNotificationsObserverMapFromNotificationsUnion<GNotificationsUnion>,
): IObserver<GNotificationsUnion>

Definition

Creates an Observer of Notifications dispatching the incoming values to a map of named functions. This is an elegant manner to handle the different notifications.

Example

Filter notifications' state

const subscribe = fromPromise(Promise.resolve(5));

subscribe(
notificationObserver({
next: (value: number) => {
console.log('next', value);
},
complete: () => {
console.log('resolved');
},
error: (error: any) => {
console.log('rejected', error);
},
}),
);

Output:

next: 5
resolved