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
| const findAddresses = actions$ => actions$.pipe( | |
| ofType(actions.FIND_ADDRESSES), | |
| map(action => action.partialAddress), | |
| debounceTime(400), | |
| distinctUntilChanged(), | |
| switchMap(partialAddress => this.backend | |
| .findAddresses(partialAddress) | |
| .pipe( | |
| map(results => actions.findAddressesFulfilled(results)), | |
| catchError(error => of(actions.findAddressesRejected(error))) |
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
| @Effect() | |
| public findAddresses = this.actions.pipe( | |
| ofType(LocationActionTypes.FindAddresses), | |
| map(action => action.partialAddress), | |
| debounceTime(400), | |
| distinctUntilChanged(), | |
| switchMap(partialAddress => this.backend | |
| .findAddresses(partialAddress) | |
| .pipe( | |
| map(results => new FindAddressesFulfilled(results)), |
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
| const removeFromCart = actions$ => actions$.pipe( | |
| ofType(actions.REMOVE_FROM_CART), | |
| switchMap(action => backend | |
| .removeFromCart(action.payload) | |
| .pipe( | |
| map(response => actions.removeFromCartFulfilled(response)), | |
| catchError(error => of(actions.removeFromCartRejected(error))) | |
| ) | |
| ) | |
| ); |
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
| @Effect() | |
| public removeFromCart = this.actions.pipe( | |
| ofType(CartActionTypes.RemoveFromCart), | |
| switchMap(action => this.backend | |
| .removeFromCart(action.payload) | |
| .pipe( | |
| map(response => new RemoveFromCartFulfilled(response)), | |
| catchError(error => of(new RemoveFromCartRejected(error))) | |
| ) | |
| ) |
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/observable/empty"; | |
| import { concatMap, expand } from "rxjs/operators"; | |
| import { get } from "./get"; | |
| const url = "https://api.github.com/users/sindresorhus/repos"; | |
| const repos = get(url).pipe( | |
| expand(({ next }) => next ? get(next) : empty()), | |
| concatMap(({ content }) => content) | |
| ); | |
| repos.subscribe(repo => console.log(repo)); |
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 { Observable } from "rxjs/Observable"; | |
| import { ajax } from "rxjs/observable/dom/ajax"; | |
| import { AjaxResponse } from "rxjs/observable/dom/AjaxObservable"; | |
| import { map } from "rxjs/operators"; | |
| export function get(url: string): Observable<{ | |
| content: object[], | |
| next: string | null | |
| }> { | |
| return ajax.get(url).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
| const published = publish<T>()(source) as ConnectableObservable<T>; | |
| const prioritized = new Subject<T>(); | |
| const subscription = published.subscribe(prioritized); | |
| subscription.add(selector(prioritized, published).subscribe(observer)); | |
| subscription.add(published.connect()); | |
| return subscription; |
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
| interface AnonymousSubscription { | |
| unsubscribe(): void; | |
| } | |
| type TeardownLogic = AnonymousSubscription | Function | void; | |
| interface ISubscription extends AnonymousSubscription { | |
| unsubscribe(): void; | |
| readonly closed: boolean; | |
| } |
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
| function subsequent<T>( | |
| count: number, | |
| operator: (source: Observable<T>) => Observable<T> | |
| ): (source: Observable<T>) => Observable<T> { | |
| return (source: Observable<T>) => new Observable<T>(observer => { | |
| const published = source.pipe(publish()) as ConnectableObservable<T>; | |
| const concatenated = concat( | |
| published.pipe(take(count)), | |
| published.pipe(operator) | |
| ); |
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
| function prioritize<T, R>( | |
| selector: ( | |
| prioritized: Observable<T>, | |
| deprioritized: Observable<T> | |
| ) => Observable<R> | |
| ): (source: Observable<T>) => Observable<R> { | |
| return (source: Observable<T>) => new Observable<T>(observer => { | |
| const published = publish<T>()(source) as ConnectableObservable<T>; | |
| const prioritized = new Subject<T>(); | |
| const subscription = new Subscription(); |