Debian Codegraph @

node/rxjs/src/internal/NotificationFactories.ts

raw
1 import { CompleteNotification, NextNotification, ErrorNotification } from './types';
2
3 /**
4 * A completion object optimized for memory use and created to be the
5 * same "shape" as other notifications in v8.
6 * @internal
7 */
8 export const COMPLETE_NOTIFICATION = (() => createNotification('C', undefined, undefined) as CompleteNotification)();
9
10 /**
11 * Internal use only. Creates an optimized error notification that is the same "shape"
12 * as other notifications.
13 * @internal
14 */
15 export function errorNotification(error: any): ErrorNotification {
16 return createNotification('E', undefined, error) as any;
17 }
18
19 /**
20 * Internal use only. Creates an optimized next notification that is the same "shape"
21 * as other notifications.
22 * @internal
23 */
24 export function nextNotification<T>(value: T) {
25 return createNotification('N', value, undefined) as NextNotification<T>;
26 }
27
28 /**
29 * Ensures that all notifications created internally have the same "shape" in v8.
30 *
31 * TODO: This is only exported to support a crazy legacy test in `groupBy`.
32 * @internal
33 */
34 export function createNotification(kind: 'N' | 'E' | 'C', value: any, error: any) {
35 return {
36 kind,
37 value,
38 error,
39 };
40 }