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
| /* | |
| * Note: This is just for fun. | |
| */ | |
| type Split<T extends string, Delimiter extends string = ""> = | |
| "" extends T | |
| ? [] | |
| : T extends `${infer Head}${Delimiter}${infer Tail}` | |
| ? [Head, ...Split<Tail, Delimiter>] | |
| : [T]; |
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, interval, merge, of, Subject, zip } from "rxjs"; | |
| import { filter, map } from "rxjs/operators"; | |
| const chars$ = zip(interval(1000), of("A", "b", "C", "D", "e", "f", "G")).pipe( | |
| map(([, char]) => char) | |
| ); | |
| const connectableChars$ = connectable(chars$, { | |
| connector: () => new Subject(), | |
| resetOnDisconnect: true | |
| }); |
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 { EMPTY } from "rxjs"; | |
| import { first } from "rxjs/operators"; | |
| EMPTY.pipe(first()).subscribe({ error: console.warn }); | |
| // (synchronously) EmptyErrorImpl | |
| // v6.6.7 has no call stack, but v7 does |
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 { config, throwError } from "rxjs"; | |
| config.onUnhandledError = console.warn; | |
| throwError(() => "TEST ERROR 1").subscribe(); | |
| throwError(() => "TEST ERROR 2").subscribe({ error: console.warn }); | |
| // (synchronously) TEST ERROR 2 | |
| // (asynchronously) TEST ERROR 1 |
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 { animationFrames, combineLatest, concat } from "rxjs"; | |
| import { endWith, map, takeWhile } from "rxjs/operators"; | |
| const h1 = document.querySelector("h1")!; | |
| combineLatest({ | |
| x: tween(0, 200, 3600), | |
| y: wave(25, 1200, 3) | |
| }).subscribe(({ x, y }) => { | |
| h1.style.transform = `translate3d(${x}px, ${y}px, 0)`; |
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()}`) | |
| ); |
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 { merge, of } from "rxjs"; | |
| import { connect, filter, map } from "rxjs/operators"; | |
| const chars$ = of("A", "b", "C", "D", "e", "f", "G"); | |
| chars$ | |
| .pipe( | |
| connect(shared$ => | |
| merge( | |
| shared$.pipe( |
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 { defer, from } from "rxjs"; | |
| import { retry, tap } from "rxjs/operators"; | |
| const values = ["_", 0, 1, 0, 2, 0, 3, 0, 0, 0, 4]; | |
| defer(() => { | |
| values.shift(); | |
| return from(values); | |
| }) | |
| .pipe( |
NewerOlder