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 getPostOne$ = Rx.Observable.timer(3000).mapTo({id: 1}); | |
const getPostTwo$ = Rx.Observable.timer(1000).mapTo({id: 2}); | |
Rx.Observable.concat(getPostOne$, getPostTwo$).subscribe(res => console.log(res)); |
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
import {Directive, Input, TemplateRef, ViewContainerRef} from '@angular/core'; | |
@Directive({ | |
selector: '[appDelay]' | |
}) | |
export class DelayDirective { | |
constructor( | |
private templateRef: TemplateRef<any>, | |
private viewContainerRef: ViewContainerRef | |
) { } |
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 getPostOne$ = Rx.Observable.timer(1000).mapTo({id: 1}); | |
const getPostTwo$ = Rx.Observable.timer(2000).mapTo({id: 2}); | |
Rx.Observable.forkJoin(getPostOne$, getPostTwo$).subscribe(res => console.log(res)) |
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 post$ = Rx.Observable.of({id: 1}); | |
const getPostInfo$ = Rx.Observable.timer(3000).mapTo({title: "Post title"}); | |
const posts$ = post$.mergeMap(post => getPostInfo$).subscribe(res => console.log(res)); |
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
// Tracking the scroll delta | |
Rx.Observable | |
.fromEvent(document, 'scroll') | |
.map(e => window.pageYOffset) | |
.pairwise() | |
.subscribe(pair => console.log(pair)); // pair[1] - pair[0] |
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 intervalOne$ = Rx.Observable.interval(1000); | |
const intervalTwo$ = Rx.Observable.interval(2000); | |
Rx.Observable.combineLatest( | |
intervalOne$, | |
intervalTwo$ | |
).subscribe(all => console.log(all)); |
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 clicks$ = Rx.Observable.fromEvent(document, 'click'); | |
const innerObservable$ = Rx.Observable.interval(1000); | |
clicks$.switchMap(event => innerObservable$) | |
.subscribe(val => console.log(val)); |
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
function createStore(reducer, initialState) { | |
var currentReducer = reducer; | |
var currentState = initialState; | |
} |
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
function createStore(reducer, initialState) { | |
var currentReducer = reducer; | |
var currentState = initialState; | |
return { | |
getState() { | |
return currentState; | |
} | |
}; | |
} |
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
function createStore(reducer, initialState) { | |
var currentReducer = reducer; | |
var currentState = initialState; | |
return { | |
getState() { | |
return currentState; | |
}, | |
dispatch(action) { | |
currentState = currentReducer(currentState, action); |