rxjs

How to unsubscribe from EventEmitter in Angular 2?

爷,独闯天下 提交于 2019-12-09 00:28:51
问题 export declare class EventEmitter<T> extends Subject<T> { /** * Creates an instance of [EventEmitter], which depending on [isAsync], * delivers events synchronously or asynchronously. */ constructor(isAsync?: boolean); emit(value: T): void; /** * @deprecated - use .emit(value) instead */ next(value: any): void; subscribe(generatorOrNext?: any, error?: any, complete?: any): any; } In Official Angular 2 Typescript definition, seems it has no way to mute or unsubscribe from EventEmitter. I got

RxJs subscribers, passing null values?

扶醉桌前 提交于 2019-12-08 23:14:58
问题 I've spent the day diving into RxJS with Angular2, as the practice of modeling user interfaces as streams is new to me. I'm experimenting with a user service that provides a stream of User objects. The first User object will be provided when the user is authenticated. Additional User Objects may be provided when the User is updated, e.g. they update their profile. If the user is not logged when the application loads, or they logout, then null is emitted. As such, an observer implementation in

How do you return new Observable(function(observer) { … with RxJS v5?

♀尐吖头ヾ 提交于 2019-12-08 20:43:14
问题 I am trying to replace all the promises that my functions return with Observables. From this post, I learned that I should no longer use "new Observable" Observable.forkJoin and array argument What is the RxJS v5 syntax to achieve this as such to achieve asynchronous waiting? thirdFunction() { let _self = this; return new Observable(function(observer) { ... observer.next( responseargs ); observer.complete(); }); } Thank you greatly for help you can offer. 回答1: There are a set of methods to

RxJS reduce doesn't continue

三世轮回 提交于 2019-12-08 20:23:14
问题 Why doesn't the flatMap cause downstream reductions to fire? I got code like: handleFiles.flatMap(files => Rx.Observable.from(files). flatMap((file, i) => fileReader(file, i)). reduce((form, file, i) => { form.append('file[' + i + ']', result); console.log('reduce step', file); return form; }, new FormData()). tap(console.log.bind(console, 'after reduce')) ). subscribe(console.log.bind(console, 'response')); And the problem is that the 'after reduce' tap is never hit. Why? The log is like:

How to handle request on interceptor after getting the value from an observable on rxjs and angular?

☆樱花仙子☆ 提交于 2019-12-08 19:52:27
So I'm coming from an AngularJS background while learning Angular 5, I still can't wrap my head around observables. I'm trying to write an HTTP interceptor for my authentication service. However when I try to get a value from the localstorage service (or any observable at this point) I'm not quite sure how to properly return the next.handle(req) method from the observable after getting the data (using subscribe?) Here's my current code (which does not work): @Injectable() export class AuthinterceptorService implements HttpInterceptor { constructor(private storage: LocalStorage) { } intercept

Accessing the state from within a redux-observable epic

牧云@^-^@ 提交于 2019-12-08 19:47:37
问题 I am using redux to build a little fusball-manager. Basically it's a page that shows the score of both teams and some buttons to increment them. I have actions like { type:"GOAL_UP", team:"red" } for which the reducer will change the corresponding value (score) in the state. Now I want to add an epic that whenever it encounters a GOAL_UP checks if one of the two teams has won the game. If a team has reached a score of 8, I want it to dispatch a GAME_WON action. My problem is that I have to

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

RxJS append observable to observable array list in typescript

╄→гoц情女王★ 提交于 2019-12-08 18:26:25
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 am appending to an arrray. Fan Cheung You can use scan to accumulate news news$:Observable<any>

AngularJs - RXJS Observable unsubscribe

我是研究僧i 提交于 2019-12-08 16:35:30
问题 I have setup an RXJS observable. I have two components which subscribe to a subject in service factory. How do I unsubscribe a selected component to the subject so that a button is pressed it stops listening to the subject broadcast? See my jsfiddle Unsubscribe App My code: <div ng-app="myApp" ng-controller="mainCtrl"> <script type="text/ng-template" id="/boxa"> BoxA - Message Listener: </br> <strong>{{boxA.msg}}</strong></br> <md-button ng-click='boxA.unsubcribe()' class='md-warn'