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 { timer } from "rxjs"; | |
import { timeoutWith } from "rxjs/operators"; | |
timer(5000, 1000) | |
.pipe(timeoutWith(2000, of("timeout"))) | |
.subscribe(console.log); | |
// (after ~2s) timeout |
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 { timer } from "rxjs"; | |
import { timeout } from "rxjs/operators"; | |
timer(5000, 1000) | |
.pipe(timeout({ first: 2000, with: _ => of("timeout") })) | |
.subscribe(console.log); | |
// (after ~2s) timeout |
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( |
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( |
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 { 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 { 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 { 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 |