rxjs5

How to get RxJS Observable events in zero time?

这一生的挚爱 提交于 2019-11-29 15:22:40
I'm collecting all the events of an Observable to a data array: const obs$ = Rx.Observable .interval(500) .take(4); let data = []; const start = performance.now(); obs$.subscribe( value => { data.push({ time: performance.now() - start, data: value }); }, () => {}, () => { console.log(JSON.stringify(data, null, 2)); } ); <script src="https://unpkg.com/rxjs@5.2.0/bundles/Rx.js"></script> Is it possible to "foresee the future" and get the same data array without waiting 2 seconds ? To clarify, I'm trying to find a way to wrap somehow a given Observable ( obs$ in the example above) with a custom

How to debug rxjs5?

最后都变了- 提交于 2019-11-29 11:46:05
问题 On RxJS - Goals I read that their goal is better debuggability: Goals Provide more debuggable call stacks than preceding versions of RxJS I have just started to use redux-observable which is quite easier for me to understand comparing it to redux-saga as I am already used to the reactive style with lodash and ramda (ok, fp style maybe ;). I was surprised that it's not possible to debug it yet. Is it true? If so, then I gotta switch to redux-saga s maybe or stick with redux-thunk . Edit based

Observable Continue calling API and changing parameters based on condition

对着背影说爱祢 提交于 2019-11-29 11:07:56
I've read the Rx.js repeat Documentation in an effort to find out how I can continue calling an api based upon the response that I receive from the API . I'm calling an API that can only send back 2k records at a time. The API will send back a value for me to send it so that I can continue receiving the records until they return a done value. So the flow goes as follows: Make a GET request a query parameter reqMode='' : retrieve response with the last array containing reqMode with a value or done . If I receive a value then I need to make the same request but send the reqMode parameter with

Rxjs - How can I extract multiple values inside an array and feed them back to the observable stream synchronously

最后都变了- 提交于 2019-11-29 07:56:10
I have created a Rx.Observable from a stream of events: Rx.Observable.fromEvent(recognizeStream, 'data') In which every data event looks like this: { error: null, alternatives: [result1, result2, result3] } I want to pluck every value inside the array of alternatives and merge those into the stream. What operators do I have to look at? As far as I know the flatMap and concatMap could do the job but I don't get the idea from their example. Can somebody explain which operator i should use and provide me with an example? The family of xxxMap() operators all deal with higher-order Observables.

How to wait for guards in Angular

痞子三分冷 提交于 2019-11-29 07:08:29
If i specify three guards on a route, it seems as though all guards are evaluated immediately. {path: '', component: OptionsComponent, canActivate: [ GuardOne, GuardTwo, GuardThree]} The problem I have is I don't want GuardTwo to run until GuardOne has finished. Is there any way to achieve this? I don't think that's possible in the 4.1.3. Here is the code that runs the guards: private runCanActivate(future: ActivatedRouteSnapshot): Observable<boolean> { const canActivate = future._routeConfig ? future._routeConfig.canActivate : null; if (!canActivate || canActivate.length === 0) return of

Testing and mocking lettable operators in RxJS 5.5

家住魔仙堡 提交于 2019-11-29 06:47:43
Before lettable operator, I did a helper to modify debounceTime method, so it uses a TestScheduler: export function mockDebounceTime( scheduler: TestScheduler, overrideTime: number, ): void { const originalDebounce = Observable.prototype.debounceTime; spyOn(Observable.prototype, 'debounceTime').and.callFake(function( time: number, ): void { return originalDebounce.call( this, overrideTime, scheduler, ); }); } So the test of the following Observable was easy: @Effect() public filterUpdated$ = this.actions$ .ofType(UPDATE_FILTERS) .debounceTime(DEFAULT_DEBOUNCE_TIME) .mergeMap(action => [...])

Trying to understand RxJS imports

99封情书 提交于 2019-11-29 04:20:53
I'm having a hard time figuring out how exactly this import statement works (in an Angular application written in Typescript): import 'rxjs/add/operator/toPromise'; I get that rxjs is mapped to the respective node_modules subfolder in the SystemJS config file, but then I'm stuck. I see that there is an index.js file but I don't see whether or how this helps to resolve the add/operator/... part. Similarly, I don't understand this one: import {Observable} from 'rxjs/Observable'; Again, there is no file Observable.* file in this place. I guess that it somehow works via the index.js file but I'd

“async” pipe not rendering the stream updates

浪尽此生 提交于 2019-11-29 01:49:07
Trying to render the window size on window resize through a stream in an angular 2 component utilizing an async pipe: <h2>Size: {{size$ | async | json}}</h2> const windowSize$ = new BehaviorSubject(getWindowSize()); Observable.fromEvent(window, 'resize') .map(getWindowSize) .subscribe(windowSize$); function getWindowSize() { return { height: window.innerHeight, width: window.innerWidth }; } @Component({ selector: 'my-app', providers: [], template: ` <div> <h2>Size: {{size$ | async | json}}</h2> </div> `, directives: [] }) export class App { size$ = windowSize$.do(o => console.log('size:', o));

How to manage state without using Subject or imperative manipulation in a simple RxJS example?

北城以北 提交于 2019-11-29 00:40:44
问题 I have been experimenting with RxJS for two weeks now, and although I love it in principle I just cannot seem to find and implement the correct pattern for managing state. All articles and questions appear to agree: Subject should be avoided where possible in favor of just pushing state through via transformations; .getValue() should be deprecated entirely; and .do should perhaps be avoided except for DOM manipulation? The problem with all such suggestions is that none of the literature

Subscribe to multiple Observables (like chaining then() in Promises)

柔情痞子 提交于 2019-11-28 21:38:47
问题 My Angular 2 application has 2 methods ( GetCategories() and GetCartItems() ) in a service , and both of these methods return Observable s. In order to invoke these two methods one after another from my component, I have written below code: ngOnInit() { this.appService.GetCategories().subscribe( (data) => { this.appService.categories = data; this.appService.GetCartItems().subscribe( { next: (data) => { this.appService.cart = data}, error: (err) => { this.toaster.error('cart==>' + err)} }) });