rxjs5

How to get RxJS Observable events in zero time?

為{幸葍}努か 提交于 2019-11-28 09:04:09
问题 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

Subjects created with Subject.create can't unsubscribe

守給你的承諾、 提交于 2019-11-28 08:48:52
问题 I have a subject that is responsible for subscriptions to certain observable: var timer$ = Rx.Observable.timer(1000, 2000); When the subject is linked to the subject like that var timerSubject = new Rx.Subject; timer$.subscribe(timerSubject); var subscription1 = timerSubject.subscribe(n => console.log(n)); var subscription2 = timerSubject.subscribe(n => console.log(n)); setTimeout(() => timerSubject.unsubscribe(), 4000); everything is fine, timerSubject.unsubscribe() can be called once and

How to get current value of State object with @ngrx/store?

笑着哭i 提交于 2019-11-28 05:17:12
My service class, before calling a web service, needs to get a property called dataForUpdate from my state. Currently, I'm doing it like this: constructor ( public _store: Store<AppState>, public _APIService:APIService) { const store$ = this._store.select ('StateReducer'); .../... let update = this.actions$.filter ( action => action.type==UPDATE ) .do( (action) => this._store.dispatch({type: REDUCER_UPDATING, payload : action.payload }) ) *** GET STATE ***==> .mergeMap ( action => store$.map ( (state : AppState)=> state.dataForUpdate ).distinctUntilChanged(), (action, dataForUpdate) { return {

Rxjs 5 - Simple Ajax Request

旧巷老猫 提交于 2019-11-28 05:06:31
I'm trying to get the value from a simple ajax request, but I don't understand how to do that. Here is the code: Rx.Observable .ajax({ url: 'https://jsonplaceholder.typicode.com/posts', method: 'GET', responseType: 'json' }) .subscribe(function(data) { return data.response; }); I searched everywhere and there is no simple explanation. Thanks! Observable.ajax can accept string or Object with the following interface: interface AjaxRequest { url?: string; // URL of the request body?: any; // The body of the request user?: string; async?: boolean; // Whether the request is async method?: string; /

Observable Continue calling API and changing parameters based on condition

断了今生、忘了曾经 提交于 2019-11-28 04:32:36
问题 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

Issue with RxJs BehaviorSubject's subscriber not being notified of value change

有些话、适合烂在心里 提交于 2019-11-28 04:15:19
问题 I am trying to use a RxJS BehaviorSubject that contains a boolean representing whether or not a user is connected/logged in the application. Here is the component that subscribes to the new BehaviorSubject value i.e. true when the user has authenticated: import {Component, OnInit} from '@angular/core'; import {CollapseDirective} from 'ng2-bootstrap'; import {PublicNavbarComponent} from './public.navbar.component'; import {PrivateNavbarComponent} from './private.navbar.component'; import

shareReplay in RxJS 5

こ雲淡風輕ζ 提交于 2019-11-28 03:29:37
问题 According to the RxJS 5 MIGRATION.md it looks like shareReplay() been removed. Why? Does .publishReplay(1).refCount() faithfully replicate the behaviour? Basically I need to replay the single most recent data set to any new subscribers. 回答1: The short answer : Quoting Sir Blesh : The problem RxJS 5 is trying to solve is that ConnectableObservables should be "reconnectable", and refCount should return an observable that is cold until subscribed to, then hot until all subscriptions have ended,

Rx.Subject loses events

旧巷老猫 提交于 2019-11-28 02:08:50
Can anybody explain what the differents between these 3 variants? http://jsfiddle.net/8vx2g3fr/2/ First works as excpect, all events are processed. But second loses last event (3) Third loses second event (2) Could you please help me to understand what the issue is and how to make the third variant process all events? 1 let bs = new Rx.Subject(); bs .subscribe(v=>{ console.log("in", v); if (v % 2 == 0) { setTimeout(()=>{ console.log(" out", v, "->" , v + 1); bs.next(v+1); }, 0); } }); bs.next(0); bs.next(2); Output: in 0 in 2 out 0 -> 1 in 1 out 2 -> 3 in 3 2 let bs2 = new Rx.Subject(); bs2

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

巧了我就是萌 提交于 2019-11-28 01:20:16
问题 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

Testing and mocking lettable operators in RxJS 5.5

99封情书 提交于 2019-11-28 00:04:41
问题 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$ =