Skip to content

Instantly share code, notes, and snippets.

@armanozak
Created May 3, 2021 09:19
Show Gist options
  • Save armanozak/4e4451d167de18f85440dd63b070e1aa to your computer and use it in GitHub Desktop.
Save armanozak/4e4451d167de18f85440dd63b070e1aa to your computer and use it in GitHub Desktop.
[What's New in RxJS 7] RxJS 7 share #blog #rxjs
import { interval, of, ReplaySubject, zip } from "rxjs";
import { map, share } from "rxjs/operators";
const shared$ = zip(interval(1000), of("A", "B", "C", "D", "E")).pipe(
map(([, char]) => char),
share({
connector: () => new ReplaySubject(3),
resetOnComplete: false,
resetOnError: false,
resetOnRefCountZero: false
})
);
shared$.subscribe(console.log);
// (~1s apart) A, B, C, D, E
setTimeout(() => shared$.subscribe(console.log), 6000);
// (after ~6s, all at once) C, D, E
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment