rxjs5

Rxjs Subject next() after complete()

我的未来我决定 提交于 2019-12-08 19:08:36
问题 I have service which connects with Subject() to do paging. I'm using next(newData) to pass to subject, which keeps things alive, now I need to use complete() on each ajax call and pass it to subject. but after doing one complete() I'm started get error. I wanted to know, can we still pass Subject observables still next(newData) if once completed() is already been triggered? 回答1: There is some information on subjects from a former question on stack overflow : here. I encourage you to review it

Any need to call unsubscribe for RxJS first()

瘦欲@ 提交于 2019-12-08 18:48:20
问题 In the following code:- RxJS.Observable.of(1,2).first().subscribe((x) => console.log(x);); is it necessary to unsubscribe given the operator first() ? 回答1: No. It unsubscribes automatically after calling first() . The current syntax is observable.pipe(first()).subscribe(func); for RxJS 6. 回答2: For the example provided, you dont need to unsubscribe , and neither you need to call first , as Observable.of(1) actually completes after emitting its first (and last) value. 回答3: first() will complete

How can I ensure that async initialization in the Angular service constructor is completed?

你离开我真会死。 提交于 2019-12-08 14:14:41
问题 Experts, please tell me how to make sure that asynchronous initialization in the service constructor is complete when calling other functions in the class? constructor() { var sock = new SockJS(this._chatUrl); this.stompClient = Stomp.over(sock); this.stompClient.connect({}, function () { }); } public subscribe(topicName: string, messageReceived) { this.stompClient.subscribe('/topic/' + topicName, function (message) { messageReceived(message); }) } public sendMessage(msgDestId: string,

RxJS5 TypeScript typings fail

折月煮酒 提交于 2019-12-08 07:21:02
问题 I run tsc on my project, and I get these errors relating to the RxJS5 lib: $ tsc node_modules/rxjs/observable/FromEventObservable.d.ts(11,39): error TS2304: Cannot find name 'EventTarget'. node_modules/rxjs/observable/FromEventObservable.d.ts(11,103): error TS2304: Cannot find name 'NodeList'. node_modules/rxjs/observable/FromEventObservable.d.ts(11,114): error TS2304: Cannot find name 'HTMLCollection'. node_modules/rxjs/observable/dom/AjaxObservable.d.ts(16,23): error TS2304: Cannot find

Angular2 NGRX Performance Issues On Dispatch?

岁酱吖の 提交于 2019-12-08 03:16:40
问题 I've been working on an application in Angular2/CLI/NGRX and things have been going well until recently. I'm noticing some pretty big spikes in performance especially with consecutive dispatches within the same container. For example lets say I have the following defined: public appEnvironment$: Observable<IEnvironment>; public assessment$: Observable<IAssessment>; public assessmentComments$: Observable<ICommentActivity[]>; public assessmentEvidence$: Observable<IEvidenceActivity[]>; public

Execute dynamically created array of observables in series

北城余情 提交于 2019-12-08 02:49:46
问题 I am working on a project (Angular2) where I am creating Observables dynamically and putting them in an array var ObservableArray : Observable<any>[] = []; //filling up Observable array dynamically for (var i = 0; i < this.mainPerson.children.length; i++) { ObservableArray.push(Observable.fromPromise(this.determineFate(this.mainPerson.children[i]))); } } var finalObservable: Observable<any> = Observable.concat(ObservableArray); finalObservable .subscribe( data => { //here I expected to

Chained redux-observable epic only fires correctly once

ぐ巨炮叔叔 提交于 2019-12-08 02:05:18
问题 I've set up an epic that waits for another epic to complete, much like @jayphelps' answer here: Invoking epics from within other epics However I've found that it only seems to run once. After that I can see the CART_CONFIG_READY action in the console but the DO_THE_NEXT_THING action is not triggered. I've tried various combinations of mergeMap and switchMap , with and without take but nothing seems to help. This is (kind of) what my code looks like. import { NgRedux } from '@angular-redux

How to use retryWhen with a function that returns a Boolean?

≯℡__Kan透↙ 提交于 2019-12-07 20:55:52
问题 Here's my code: this._http.post(this._url_get + extension, '', { headers: headers }) .map(res => res['_body']) .retryWhen(errors => {return responseErrorProcess(errors)}) now I need to catch exceptions and pass them to my responseErrorProcess() which returns true if it needs to retry I could not figure out how to retrieve the exceptions from errors , this is how it looks: Subject_isScalar: falseclosed: falsehasError: falseisStopped: falseobservers: Array[0]thrownError: null__proto__:

error TS2339: Property 'partition' does not exist on type 'Observable<boolean>'

情到浓时终转凉″ 提交于 2019-12-07 17:04:21
问题 Previously I was using rxjs-5 and I was using observable.partition as follows: const [isTiming$, isNotTiming$] = this.store.select(state => state.tetris.isTiming) .partition(value => value); After upgrade angular to 8 rxjs got upgraded to rxjs-6 which started throwing following error: providers/timer.provider.ts(27,5): error TS2339: Property 'partition' does not exist on type 'Observable<boolean>'. when I checked in older rxjs implementation it was implemented as follows: import { Observable

Continue the subscription after error

守給你的承諾、 提交于 2019-12-07 15:31:02
问题 I have a code where for each of the ids I am making an ajax request and processing them as results come in. Here is a simple replica of my actual code and jsfiddle: var ids = [1,2,3,4,5,6]; var ids$ = (id) => { return Observable.of(id); }; var loadIds$ = (id) => { if(id == 4) return xhr('/echo/jsoneee/', {id: id}); return xhr('/echo/json/', {id: id}); }; Observable.from(ids) .concatMap(id => Observable.forkJoin(ids$(id), loadIds$(id))) .catch((err, caught) => { //get the id for which loadIds