rxjs

NgRx selector emits when anything on the state changes/memoization of selector not working

孤者浪人 提交于 2019-12-13 01:18:02
问题 I'm using Angular 7 along with NgRx. I have created a selector to get some data from the store using filter , but this selector emits when anything on the store changes, even if it is not related to my selector. I have created a demonstration of my issue. Here is my selector: export const getMyArrayFilter = createSelector( getCounterState, state => state.myArray.filter(x => x === 'new Item') ); And here I am using my getMyArrayFilter selector: this.store.pipe(select(fromRoot.getMyArrayFilter)

Sort nested observable

社会主义新天地 提交于 2019-12-13 00:46:45
问题 I have here a JSON file which looks like this: [ { "question": "What is your age range?", "options": ["10-20","20-30","30-40","40-50"] }, { "question": "How did you find us?", "options": ["Friend recommendation","Google","Other"] }, { "question": "Are you interested in etcetc?", "options": ["No","Yes","Meh"] } ] In my project I've got a model with the same structure which looks like this: export interface Test { question: string; options: string[]; } in my service file, I read the file like

Best way to query all documents from a mongodb collection in a reactive way w/out flooding RAM

◇◆丶佛笑我妖孽 提交于 2019-12-12 20:29:00
问题 I want to query all the documents in a collection in a reactive way. The collection.find() method of the mongodb nodejs driver returns a cursor that fires events for each document found in the collection. So I made this: function giant_query = (db) => { var req = db.collection('mycollection').find({}); return Rx.Observable.merge(Rx.Observable.fromEvent(req, 'data'), Rx.Observable.fromEvent(req, 'end'), Rx.Observable.fromEvent(req, 'close'), Rx.Observable.fromEvent(req, 'readable')); } It will

RxJS - Do I need to unsubscribe

爷,独闯天下 提交于 2019-12-12 20:22:58
问题 If I have something like this: class MyComponent { constructor() { this.interval = Observbale.interval(1000); } } const c = new MyComponent(); const subscription = c.interval.subscribe(() => { ... }) Now let's say that at a certain point I'm doing this: c = null; I still need to call subscription.unsubscribe() before or the GC will take care for this "leak"? 回答1: Yes. You need to call unsubscribe on the returned subscription. Internally, there is a call to window.setInterval and its

Query data relationship on Firebase Realtime Database with angularfire2

泪湿孤枕 提交于 2019-12-12 20:14:18
问题 I need to query comments and request only user that listed in the comment by userId. My database structure in Firebase realtime db: { "comments" : { "c_id1" : { "commentId" : "c_id1", "commentText" : "text", "userId" : "u_id1" }, "c_id2" : { "commentId" : "c_id2", "commentText" : "text", "userId" : "u_id3" }, }, "users" : { "u_id1" : { "userId" : "u_id1", "userName" : "name1", }, "u_id1" : { "userId" : "u_id2", "userName" : "name2", }, "u_id1" : { "userId" : "u_id3", "userName" : "name3", } }

Angular 2 & RxJs catch function callback binding to 'this' causes http request to be repeated over and over

拈花ヽ惹草 提交于 2019-12-12 19:53:04
问题 I have a method for handle our errors from http requests and it looks like this public handleError(err: any, caught: Observable<any>): Observable<any> { //irrelevant code removed this.logger.debug(err);//example of problem return caught; } It is invoked like this (example method, but shows the error) public makeHttpCall() { this.http.get("http://api.exmaple.com/getsomedata") .map(r=> r.json()) .catch(this.handleError); } The problem with the above code is that when calling this.logger.debug

rx data driven subwidgets

一曲冷凌霜 提交于 2019-12-12 18:28:01
问题 Following up on How to structure rxjs code, concerning how to structure a widget with subwidget when using rx, how would you structure rx code where the subwidgets are data-driven? As a toy problem, suppose you have an external source (e.g. web service) streaming a list of stocks to watch, with value, high, low, etc. So you have an Observable stream like (time goes down): [{id: 'csco', value: 12, high: 20, low: 10}] [{id: 'csco', value: 12, high: 20, low: 8}, {id: 'aapl', value: 29, high: 30,

React + Redux-Observable Timeout Marble Testing

强颜欢笑 提交于 2019-12-12 18:24:09
问题 I am creating a web app using React and Redux Observables and I would like to create a unit test for the timeout scenario of one of my epics. Here is the Epic: export const loginUserEpic = (action$: ActionsObservable<any>, store, { ajax, scheduler }): Observable<Action> => action$.pipe( ofType<LoginAction>(LoginActionTypes.LOGIN_ACTION), switchMap((action: LoginAction) => ajax({ url, method: 'POST', headers: { 'Content-Type': 'application/json' }, body: { email: action.payload.username,

Observable and how to control results pace

喜夏-厌秋 提交于 2019-12-12 17:51:06
问题 I am looking for an operator that would help me pace the results emitted from an observable, it would look like this : [--A-BC--D-E----------------] [--A----B----C----D----E----] I tried AuditTime() but it does not replay the results that was emitted between intervals, it does something like this : [--A-BC--D-E----------------] [--A----C----E--------------] Thanks for your help. 回答1: I think this should do what you need: const e1 = cold('--A-BC--D-E----------------|'); const expected = '--A--

RxJS to combine attributes from triples to a table

大城市里の小女人 提交于 2019-12-12 17:42:44
问题 I have a service producing objects that are like triples. They will be in this format: { country, attribute, value } Example: { country: 'usa', attribute: 'population', value: 100 } { country: 'mexico', attribute: 'population', value: 200 } { country: 'usa', attribute: 'areaInSqM', value: 3000 } Ultimately I want to display these as a table. Rows are countries, columns are attributes. So the table would look like: | country | population | areaInSqM | | usa | 100 | 3000 | | mexico | 200 | | My