Skip to content

Instantly share code, notes, and snippets.

@armanozak
Created May 3, 2021 09:20
Show Gist options
  • Save armanozak/464dd55418cf33a79d6f6f826af40ae1 to your computer and use it in GitHub Desktop.
Save armanozak/464dd55418cf33a79d6f6f826af40ae1 to your computer and use it in GitHub Desktop.
[What's New in RxJS 7] RxJS 7 connectable #blog #rxjs
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