Created
May 3, 2021 09:20
-
-
Save armanozak/464dd55418cf33a79d6f6f826af40ae1 to your computer and use it in GitHub Desktop.
[What's New in RxJS 7] RxJS 7 connectable #blog #rxjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { connectable, merge, of } from "rxjs"; | |
import { filter, map } from "rxjs/operators"; | |
const chars$ = of("A", "b", "C", "D", "e", "f", "G"); | |
const connectableChars$ = connectable(chars$); | |
const lower$ = connectableChars$.pipe( | |
filter(x => x.toLowerCase() === x), | |
map(x => `lower ${x.toUpperCase()}`) | |
); | |
const upper$ = connectableChars$.pipe( | |
filter(x => x.toLowerCase() !== x), | |
map(x => `upper ${x}`) | |
); | |
merge(lower$, upper$).subscribe(console.log); | |
connectableChars$.connect(); | |
// (synchronously) upper A | |
// (synchronously) lower B | |
// (synchronously) upper C | |
// (synchronously) upper D | |
// (synchronously) lower E | |
// (synchronously) lower F | |
// (synchronously) upper G |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment