Skip to content

Latest commit

 

History

History
39 lines (27 loc) · 1.16 KB

replaysubject.md

File metadata and controls

39 lines (27 loc) · 1.16 KB

ReplaySubject

"Replays" or emits old values to new subscribers

Ultimate RxJS

Examples

Example 1: simple ReplaySubject

( Stackblitz )

// RxJS v6+
import { ReplaySubject } from 'rxjs';

const sub = new ReplaySubject(3);

sub.next(1);
sub.next(2);
sub.subscribe(console.log); // OUTPUT => 1,2
sub.next(3); // OUTPUT => 3
sub.next(4); // OUTPUT => 4
sub.subscribe(console.log); // OUTPUT => 2,3,4 (log of last 3 values from new subscriber)
sub.next(5); // OUTPUT => 5,5 (log from both subscribers)

Additional Resources


📁 Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/ReplaySubject.ts