How to use rxjs

Comprehensive rxjs code examples:

How to use rxjs.mergeAll:

83
84
85
86
87
88
89
90
91
92
    car: cars[i],
    bookings,
  }))
}),
catchError((err) => error('cluster err', err)),
mergeAll(),
filter(({ bookings }) => bookings.length > 0),
tap(({ car, bookings }) =>
  info(
    `Plan ${car.id} (${car.fleet.name}) received ${bookings.length} bookings`

How to use rxjs.scan:

74
75
76
77
78
79
80
81
82
83

const downloadFiles$ = ({files, prefix, downloadDir, deleteAfterDownload}) => {
    return of(files).pipe(
        switchMap(files => of(...files)),
        mergeMap(file => downloadFile$({file, prefix, downloadDir, deleteAfterDownload}), CONCURRENT_FILE_DOWNLOAD),
        scan((currentProgress, fileProgress) => getProgress({
            files,
            currentProgress,
            fileProgress
        }), initialState(files))

How to use rxjs.expand:

117
118
119
120
121
122
123
124
125
126
}

return createDirs$(path.dirname(toFilePath)).pipe(
    switchMap(() =>
        downloadChunk$(0).pipe(
            expand(({end, length}) => {
                let downloaded = isDownloaded({end, length})
                return downloaded ? EMPTY : downloadChunk$(end + 1)
            })
        )

How to use rxjs.share:

89
90
91
92
93
94
95
96
97
98
  })

experiment.bookingUpdates = experiment.dispatchedBookings.pipe(
  mergeMap((booking) => booking.statusEvents),
  catchError((err) => error('bookingUpdates', err)),
  share()
)

experiment.passengerUpdates = experiment.passengers.pipe(
  mergeMap(({ deliveredEvents, pickedUpEvents }) =>

How to use rxjs.repeat:

308
309
310
311
312
313
314
315
316
317
318
319
320
//         answer.engineerEmail,
//         answer.engineerGitHub
//     );


//     team.push(engineer);
//     repeat();
// };




// // Questions for inputting information and adding intern

How to use rxjs.retry:

10
11
12
13
14
15
16
17
18
19
20
    // tap(e => console.info('after', e)),
    catchError(e => {
        console.error('fn errored', e)
        throw new Error()
    }),
    retry(1),
    )


range(10)
.pipe(

How to use rxjs.take:

20
21
22
23
24
25
26
27
28
29
30
31
32




// genrate events of type myEvent


rx.interval(450).pipe(
    rx.take(5)
).forEach(
    i => mee.emit('myEvent', 'Hello event ' + i)
);

How to use rxjs.queueScheduler:

21
22
23
24
25
26
27
28
29
30
exports.asap = rxjs.asap;
exports.asapScheduler = rxjs.asapScheduler;
exports.async = rxjs.async;
exports.asyncScheduler = rxjs.asyncScheduler;
exports.queue = rxjs.queue;
exports.queueScheduler = rxjs.queueScheduler;
exports.animationFrame = rxjs.animationFrame;
exports.animationFrameScheduler = rxjs.animationFrameScheduler;
exports.VirtualTimeScheduler = rxjs.VirtualTimeScheduler;
exports.VirtualAction = rxjs.VirtualAction;

How to use rxjs.queue:

20
21
22
23
24
25
26
27
28
29
exports.AsyncSubject = rxjs.AsyncSubject;
exports.asap = rxjs.asap;
exports.asapScheduler = rxjs.asapScheduler;
exports.async = rxjs.async;
exports.asyncScheduler = rxjs.asyncScheduler;
exports.queue = rxjs.queue;
exports.queueScheduler = rxjs.queueScheduler;
exports.animationFrame = rxjs.animationFrame;
exports.animationFrameScheduler = rxjs.animationFrameScheduler;
exports.VirtualTimeScheduler = rxjs.VirtualTimeScheduler;

How to use rxjs.VirtualAction:

25
26
27
28
29
30
31
32
33
34
exports.queue = rxjs.queue;
exports.queueScheduler = rxjs.queueScheduler;
exports.animationFrame = rxjs.animationFrame;
exports.animationFrameScheduler = rxjs.animationFrameScheduler;
exports.VirtualTimeScheduler = rxjs.VirtualTimeScheduler;
exports.VirtualAction = rxjs.VirtualAction;
exports.Scheduler = rxjs.Scheduler;
exports.Subscription = rxjs.Subscription;
exports.Subscriber = rxjs.Subscriber;
exports.Notification = rxjs.Notification;

How to use rxjs.UnsubscriptionError:

38
39
40
41
42
43
44
45
46
47
exports.identity = rxjs.identity;
exports.isObservable = rxjs.isObservable;
exports.ArgumentOutOfRangeError = rxjs.ArgumentOutOfRangeError;
exports.EmptyError = rxjs.EmptyError;
exports.ObjectUnsubscribedError = rxjs.ObjectUnsubscribedError;
exports.UnsubscriptionError = rxjs.UnsubscriptionError;
exports.TimeoutError = rxjs.TimeoutError;
exports.bindCallback = rxjs.bindCallback;
exports.bindNodeCallback = rxjs.bindNodeCallback;
exports.combineLatest = rxjs.combineLatest;

How to use rxjs.GroupedObservable:

10
11
12
13
14
15
16
17
18
19

const rxjs = require('rxjs');

exports.Observable = rxjs.Observable;
exports.ConnectableObservable = rxjs.ConnectableObservable;
exports.GroupedObservable = rxjs.GroupedObservable;
exports.observable = rxjs.observable;
exports.Subject = rxjs.Subject;
exports.BehaviorSubject = rxjs.BehaviorSubject;
exports.ReplaySubject = rxjs.ReplaySubject;

How to use rxjs.EmptyError:

36
37
38
39
40
41
42
43
44
45
exports.pipe = rxjs.pipe;
exports.noop = rxjs.noop;
exports.identity = rxjs.identity;
exports.isObservable = rxjs.isObservable;
exports.ArgumentOutOfRangeError = rxjs.ArgumentOutOfRangeError;
exports.EmptyError = rxjs.EmptyError;
exports.ObjectUnsubscribedError = rxjs.ObjectUnsubscribedError;
exports.UnsubscriptionError = rxjs.UnsubscriptionError;
exports.TimeoutError = rxjs.TimeoutError;
exports.bindCallback = rxjs.bindCallback;

How to use rxjs.mapTo:

22
23
24
25
26
27
28
29
30
31
    mergeMap(instance =>
        timer(maxIdleMilliseconds).pipe(
            takeUntil(lock$.pipe(
                filter(currentInstance => currentInstance === instance)
            )),
            mapTo(instance)
        )
    )
).subscribe({
    next: instance => dispose(instance),

How to use rxjs.identity:

33
34
35
36
37
38
39
40
41
42
exports.Subscriber = rxjs.Subscriber;
exports.Notification = rxjs.Notification;
exports.NotificationKind = rxjs.NotificationKind;
exports.pipe = rxjs.pipe;
exports.noop = rxjs.noop;
exports.identity = rxjs.identity;
exports.isObservable = rxjs.isObservable;
exports.ArgumentOutOfRangeError = rxjs.ArgumentOutOfRangeError;
exports.EmptyError = rxjs.EmptyError;
exports.ObjectUnsubscribedError = rxjs.ObjectUnsubscribedError;

How to use rxjs.Subscriber:

28
29
30
31
32
33
34
35
36
37
exports.animationFrameScheduler = rxjs.animationFrameScheduler;
exports.VirtualTimeScheduler = rxjs.VirtualTimeScheduler;
exports.VirtualAction = rxjs.VirtualAction;
exports.Scheduler = rxjs.Scheduler;
exports.Subscription = rxjs.Subscription;
exports.Subscriber = rxjs.Subscriber;
exports.Notification = rxjs.Notification;
exports.NotificationKind = rxjs.NotificationKind;
exports.pipe = rxjs.pipe;
exports.noop = rxjs.noop;

How to use rxjs.takeWhile:

49
50
51
52
53
54
55
56
57
58
            (error || state === FAILED)
                ? throwError(() => new Error(error))
                : of(state)
        ),
        distinctUntilChanged(),
        takeWhile(state => isRunning(state)),
        map(toProgress)
    )

const toProgress = state => {

How to use rxjs.generate:

50
51
52
53
54
55
56
57
58
59
exports.empty = rxjs.empty;
exports.forkJoin = rxjs.forkJoin;
exports.from = rxjs.from;
exports.fromEvent = rxjs.fromEvent;
exports.fromEventPattern = rxjs.fromEventPattern;
exports.generate = rxjs.generate;
exports.iif = rxjs.iif;
exports.interval = rxjs.interval;
exports.merge = rxjs.merge;
exports.never = rxjs.never;

How to use rxjs.TimeoutError:

39
40
41
42
43
44
45
46
47
48
exports.isObservable = rxjs.isObservable;
exports.ArgumentOutOfRangeError = rxjs.ArgumentOutOfRangeError;
exports.EmptyError = rxjs.EmptyError;
exports.ObjectUnsubscribedError = rxjs.ObjectUnsubscribedError;
exports.UnsubscriptionError = rxjs.UnsubscriptionError;
exports.TimeoutError = rxjs.TimeoutError;
exports.bindCallback = rxjs.bindCallback;
exports.bindNodeCallback = rxjs.bindNodeCallback;
exports.combineLatest = rxjs.combineLatest;
exports.concat = rxjs.concat;

How to use rxjs.asapScheduler:

17
18
19
20
21
22
23
24
25
26
exports.Subject = rxjs.Subject;
exports.BehaviorSubject = rxjs.BehaviorSubject;
exports.ReplaySubject = rxjs.ReplaySubject;
exports.AsyncSubject = rxjs.AsyncSubject;
exports.asap = rxjs.asap;
exports.asapScheduler = rxjs.asapScheduler;
exports.async = rxjs.async;
exports.asyncScheduler = rxjs.asyncScheduler;
exports.queue = rxjs.queue;
exports.queueScheduler = rxjs.queueScheduler;

How to use rxjs.partition:

58
59
60
61
62
63
64
65
66
67
exports.merge = rxjs.merge;
exports.never = rxjs.never;
exports.of = rxjs.of;
exports.onErrorResumeNext = rxjs.onErrorResumeNext;
exports.pairs = rxjs.pairs;
exports.partition = rxjs.partition;
exports.race = rxjs.race;
exports.range = rxjs.range;
exports.throwError = rxjs.throwError;
exports.timer = rxjs.timer;

How to use rxjs.ArgumentOutOfRangeError:

35
36
37
38
39
40
41
42
43
44
exports.NotificationKind = rxjs.NotificationKind;
exports.pipe = rxjs.pipe;
exports.noop = rxjs.noop;
exports.identity = rxjs.identity;
exports.isObservable = rxjs.isObservable;
exports.ArgumentOutOfRangeError = rxjs.ArgumentOutOfRangeError;
exports.EmptyError = rxjs.EmptyError;
exports.ObjectUnsubscribedError = rxjs.ObjectUnsubscribedError;
exports.UnsubscriptionError = rxjs.UnsubscriptionError;
exports.TimeoutError = rxjs.TimeoutError;

How to use rxjs.asyncScheduler:

19
20
21
22
23
24
25
26
27
28
exports.ReplaySubject = rxjs.ReplaySubject;
exports.AsyncSubject = rxjs.AsyncSubject;
exports.asap = rxjs.asap;
exports.asapScheduler = rxjs.asapScheduler;
exports.async = rxjs.async;
exports.asyncScheduler = rxjs.asyncScheduler;
exports.queue = rxjs.queue;
exports.queueScheduler = rxjs.queueScheduler;
exports.animationFrame = rxjs.animationFrame;
exports.animationFrameScheduler = rxjs.animationFrameScheduler;

How to use rxjs.fromEventPattern:

49
50
51
52
53
54
55
56
57
58
exports.defer = rxjs.defer;
exports.empty = rxjs.empty;
exports.forkJoin = rxjs.forkJoin;
exports.from = rxjs.from;
exports.fromEvent = rxjs.fromEvent;
exports.fromEventPattern = rxjs.fromEventPattern;
exports.generate = rxjs.generate;
exports.iif = rxjs.iif;
exports.interval = rxjs.interval;
exports.merge = rxjs.merge;

How to use rxjs.animationFrameScheduler:

23
24
25
26
27
28
29
30
31
32
exports.async = rxjs.async;
exports.asyncScheduler = rxjs.asyncScheduler;
exports.queue = rxjs.queue;
exports.queueScheduler = rxjs.queueScheduler;
exports.animationFrame = rxjs.animationFrame;
exports.animationFrameScheduler = rxjs.animationFrameScheduler;
exports.VirtualTimeScheduler = rxjs.VirtualTimeScheduler;
exports.VirtualAction = rxjs.VirtualAction;
exports.Scheduler = rxjs.Scheduler;
exports.Subscription = rxjs.Subscription;

How to use rxjs.asap:

16
17
18
19
20
21
22
23
24
25
exports.observable = rxjs.observable;
exports.Subject = rxjs.Subject;
exports.BehaviorSubject = rxjs.BehaviorSubject;
exports.ReplaySubject = rxjs.ReplaySubject;
exports.AsyncSubject = rxjs.AsyncSubject;
exports.asap = rxjs.asap;
exports.asapScheduler = rxjs.asapScheduler;
exports.async = rxjs.async;
exports.asyncScheduler = rxjs.asyncScheduler;
exports.queue = rxjs.queue;

How to use rxjs.VirtualTimeScheduler:

24
25
26
27
28
29
30
31
32
33
exports.asyncScheduler = rxjs.asyncScheduler;
exports.queue = rxjs.queue;
exports.queueScheduler = rxjs.queueScheduler;
exports.animationFrame = rxjs.animationFrame;
exports.animationFrameScheduler = rxjs.animationFrameScheduler;
exports.VirtualTimeScheduler = rxjs.VirtualTimeScheduler;
exports.VirtualAction = rxjs.VirtualAction;
exports.Scheduler = rxjs.Scheduler;
exports.Subscription = rxjs.Subscription;
exports.Subscriber = rxjs.Subscriber;

How to use rxjs.animationFrame:

22
23
24
25
26
27
28
29
30
31
exports.asapScheduler = rxjs.asapScheduler;
exports.async = rxjs.async;
exports.asyncScheduler = rxjs.asyncScheduler;
exports.queue = rxjs.queue;
exports.queueScheduler = rxjs.queueScheduler;
exports.animationFrame = rxjs.animationFrame;
exports.animationFrameScheduler = rxjs.animationFrameScheduler;
exports.VirtualTimeScheduler = rxjs.VirtualTimeScheduler;
exports.VirtualAction = rxjs.VirtualAction;
exports.Scheduler = rxjs.Scheduler;

How to use rxjs.using:

63
64
65
66
67
68
69
70
71
72
exports.partition = rxjs.partition;
exports.race = rxjs.race;
exports.range = rxjs.range;
exports.throwError = rxjs.throwError;
exports.timer = rxjs.timer;
exports.using = rxjs.using;
exports.zip = rxjs.zip;
exports.scheduled = rxjs.scheduled;
exports.EMPTY = rxjs.EMPTY;
exports.NEVER = rxjs.NEVER;

How to use rxjs.observable:

11
12
13
14
15
16
17
18
19
20
const rxjs = require('rxjs');

exports.Observable = rxjs.Observable;
exports.ConnectableObservable = rxjs.ConnectableObservable;
exports.GroupedObservable = rxjs.GroupedObservable;
exports.observable = rxjs.observable;
exports.Subject = rxjs.Subject;
exports.BehaviorSubject = rxjs.BehaviorSubject;
exports.ReplaySubject = rxjs.ReplaySubject;
exports.AsyncSubject = rxjs.AsyncSubject;