rxjs

rxjs: - receive values emitted before subscribe

放肆的年华 提交于 2019-12-08 04:10:27
my emit.next(1) is lost, I want my subscriber to get that value. My subscriber can't subscribe until after the emit has already happened. This answer suggests publish and connect RxJs: how to get values emitted before we subscribe? however I wasn't sure how to get it working: console.log('make emit') let emit = new Subject<number>(); console.log('make obs') let obs = emit.asObservable() console.log('emit 1') emit.next(1) console.log('subscribe') obs.subscribe((v)=>console.log(v,'!')) console.log('emit 2') emit.next(2) console.log('set timeout 1000 to emit') setTimeout(()=>emit.next(3),1000)

RxJS append observable to observable array list in typescript

ぐ巨炮叔叔 提交于 2019-12-08 04:03:59
问题 How to add Observable<News> to an array of observable ? newsArray: Observable<Array<any>>; addNews(newsId: number) { let news = this.newsService.getNewNews(newsId); // this returns a Observable<News> type. //I want to add `news` to `newsArray` to display it in UI. } HTML: <li *ngFor="let item of (newsArray | async)"> <div>{{item.Id}}: {{item.DataValue}}</div> </li> Any other operators to use? I tried BehaviourSubject but it displays only one value at a time. I want to display add items that I

What is the expected behaviour Cancelling async request in Redux-observable using takeUntil

只愿长相守 提交于 2019-12-08 03:50:51
问题 i am new to RXJS, i found Redux-observable canceling async request using takeUntil is very useful. but while i was testing it i found that the actual request is still going on even though we cancel the request.. i have this JSbin code snippet to test. https://jsbin.com/hujosafocu/1/edit?html,js,output here the actual request is not canceling, even if you cancel the request by clicking the cancel (multiple times) button. i am not sure this is how it should be.. if yes, then what does it meant

How to correctly pass props to a component with RxJS in Angular 4?

本小妞迷上赌 提交于 2019-12-08 03:38:01
问题 Here is my component: @Component({ selector: 'bc-goods-detail', template: ` <span>good id: {{good?.id}}</span> <input [value]="good?.name" (input)="onInput($event)" /> <button (click)="onClick()">Save</button> `, styles: [] }) export class GoodsDetailComponent { @Input() good: Good; @Output() save = new EventEmitter<Good>(); onClick() { this.save.emit(this.good); } onInput ($event) { this.good.name = $event.target.value; } } When I change the name in input and then I am pressing save button

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

What does observer.complete() do?

末鹿安然 提交于 2019-12-08 02:41:40
问题 In rxjs what exactly does the observer.complete() do after observer.next() ? 回答1: From the documentation observer.complete notifies the Observer that the Observable has finished sending push-based notifications. In the other hand, observer.complete it's a callback function and an Observable calls this method after it has called next() for the final time, if it has not encountered any errors . 回答2: In ReactiveX library, there are two types of messages. First ones are ordinary messages.

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

Transforming Observable with .map

不羁的心 提交于 2019-12-08 02:02:21
问题 I have a problem with transforming my observable. Details below: I have a data like this [ { 'firstName': 'John', 'lastName': 'Cash', 'age': 20 } ]; Then I get this data from api: public getData(): Observable<Data[]> { return this.http.get('xxx') .map( response => response.json() ); } Then, I'm trying to subscribe this: this.service.getData.subscribe( (res) => this.data = res ); And It's ok, it's working. But I need to modify the structure of object and I would like to use .map to transform

Creating a simple scheduler

ぃ、小莉子 提交于 2019-12-08 01:39:09
问题 How would I go about creating a simple Scheduler that say, delays every item by a second? I want to use it for an Observable, and yes, I know that can be done in multiple other ways, I jsut want to accomplish it using a custom Scheduler. There's some related tutorial here: http://codebetter.com/matthewpodwysocki/2010/05/12/introduction-to-the-reactive-extensions-for-javascript-custom-schedulers/ but it is quite outdated and the API looks very different now. The current docs are not very