- RxSpy.spy();
- RxSpy.log(/user-.+/);
- RxSpy.log('users');
- const names = ['benlesh', 'kwonoj', 'staltz'];
- const users = Rx.Observable.forkJoin(...names.map(name =>
- Rx.Observable
- .ajax
- .getJSON(`https://api.github.com/users/${name}`)
- .tag(`user-${name}`)
- ))
- .tag('users');
- users.subscribe();
- import { Observable } from 'rxjs/Observable';
- import { ajax } from 'rxjs/observable/dom/ajax';
- const getRepos = action$ =>
- action$.ofType('REPOS_REQUEST')
- .map(action => action.payload.user)
- .switchMap(user => ajax.getJSON(`https://api.notgithub.com/users/${user}/repos`))
- .map(repos => { type: 'REPOS_RESPONSE', payload: { repos } })
- .catch(error => Observable.of({ type: 'REPOS_ERROR' }))
- .tag('getRepos');
- import { Observable } from 'rxjs/Observable';
- import { ajax } from 'rxjs/observable/dom/ajax';
- const getRepos = action$ =>
- action$.ofType('REPOS_REQUEST')
- .map(action => action.payload.user)
- .switchMap(user => ajax
- .getJSON(`https://api.notgithub.com/users/${user}/repos`)
- .map(repos => { type: 'REPOS_RESPONSE', payload: { repos } })
- .catch(error => Observable.of({ type: 'REPOS_ERROR' }))
- )
- .tag('getRepos');
来源: https://juejin.im/post/5a0ce22451882534af257faa