Last active
August 3, 2021 05:07
-
-
Save jhades/160352a73dba15726b1498576a362e55 to your computer and use it in GitHub Desktop.
Functional Reactive Programming for Angular Developers - RxJs and Observables
This file contains 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
const obs = interval(1000).pipe(take(5)); |
This file contains 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
const obs = interval(1000) | |
.pipe( | |
take(5), | |
tap(i => console.log(i) ) | |
); | |
This file contains 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
const obs = interval(1000) | |
.pipe( | |
take(5), | |
tap(i => console.log("obs value "+ i) ) | |
); | |
obs.subscribe(value => console.log("observer 1 received " + value)); | |
obs.subscribe(value => console.log("observer 2 received " + value)); |
This file contains 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
const obs = interval(500) | |
.pipe( | |
take(5), | |
map(i => 2 * i ) | |
); | |
This file contains 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
<form [ngForm]="form" (ngSubmit)="onSubmit()"> | |
<p> | |
<label>First Name:</label> | |
<input type="text" ngControl="firstName"> | |
</p> | |
</form> |
This file contains 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
this.form.valueChanges | |
.pipe( | |
map((value) => { | |
value.firstName = value.firstName.toUpperCase(); | |
return value; | |
}), | |
filter((value) => this.form.valid) | |
) | |
.subscribe(validValue => ...); | |
This file contains 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
const obs = interval(500).pipe(take(5)); | |
var reduced = obs.pipe( | |
reduce((state, value) => state + value , 0) | |
); | |
reduced.subscribe(total => console.log("total =" + total)); |
This file contains 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
const obs = interval(500).pipe(take(5)); | |
var scanObs = obs.pipe( | |
scan((state, value) => state + value , 0) | |
); | |
scanObs.subscribe(total => console.log(total)); |
This file contains 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
const obs = interval(500) | |
.pipe( | |
take(5), | |
tap(i => console.log("obs value "+ i)), | |
shareReplay() | |
); | |
obs.subscribe(value => console.log("observer 1 received " + value)); | |
obs.subscribe(value => console.log("observer 2 received " + value)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment