Last active
November 28, 2023 15:51
-
-
Save umutyerebakmaz/b6f991fff5ccec370b97286d5138faad to your computer and use it in GitHub Desktop.
RXJS time based functions
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
// bir sayine sonra bir değer üretir | |
const timer$ = timer(1000); | |
timer$.subscribe(value => { | |
console.log(value); // 0 | |
}); | |
// her bir saniyede bir artan değer üretir | |
const interval$ = interval(1000); | |
interval$.subscribe(value => { | |
console.log(value); // 0, 1, 2, 3, ... | |
}); | |
// her değeri 1 saniye geciktirir | |
const delay$ = of(1, 2, 3).pipe( | |
delay(1000) | |
); | |
delay$.subscribe(value => { | |
console.log(value); // 1, 2, 3 (1 saniye sonra) | |
}); | |
// countdown larda uygulanır geriye sayım yapar. | |
const countdownSeconds = 10; | |
const countDown$ = timer(0, 1000).pipe( | |
map(secondsRemaining => countdownSeconds - secondsRemaining), | |
take(countdownSeconds + 1) | |
); | |
countDown$.subscribe(seconds => { | |
console.log(seconds); // 10, 9, 8, ..., 1, 0 | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment