ngrx

Close subscription on condition with takeUntil()

感情迁移 提交于 2019-12-04 05:51:07
问题 I have a subscription to get providers from a NgRx reducer. I want to use takeUntil() to automatically close the subscription when is finally returns an array that has content: // Fetch providers this.store.pipe(select(reducer.getProviders)) // .takeUntil(reducer.getProviders.length > 0) .subscribe(providers => { if (providers) { this.providers = providers; // takeUntil(/** something **/); } }); Can someone help me with this? I can't figure out how to make use of takeUntil() 回答1: takeUntil

ngrx: how to pass parameters to selector inside createSelector method

a 夏天 提交于 2019-12-04 03:28:57
I have a very simple state in my store: const state = { records: [1,2,3], }; I have a selector for records: export const getRecords = createSelector(getState, (state: State) => state.records)); And what I want now is to have separate selectors for fetching each record by index. For this purpose I want to create one generic selector with props in this way: export const getRecordByIndex = createSelector( getRecords, (state: State, { index }) => state.records[index]), ); And after that create a couple of specific selectors e. g.: export const getFirstRecord = createSelector( getRecordByIndex(/*

Angular NGRX: multiple Entities in one EntityAdapter possible?

喜欢而已 提交于 2019-12-04 02:06:30
Recently NGRX/Entities have been introduced: https://medium.com/ngrx/introducing-ngrx-entity-598176456e15 https://github.com/ngrx/platform/tree/master/example-app And since they are made in a way that an adapter handles a (read: one, single) map-datastructure and on initialization then gets the rest of the reducer state, I was wondering... Is it possible to hold multiple Entities in one reducer/adapter? The interface says no but maybe there is a hack or it is planned for the future? What if I already have multiple maps in one reducer? Am I forced to split it up or avoid the Entities feature?

What is the best structure for app using ngrx?

和自甴很熟 提交于 2019-12-03 23:02:33
Structure 1 reducers index.ts //Combine all reducers user.reducer.ts product.reducer.ts actions index.ts //Combine all actions user.action.ts product.action.ts effects index.ts //Combine all effects user.effect.ts product.effect.ts selector //Combine all selectors user.selector.ts product.selector.ts OR user user.reducer.ts user.action.ts user.effect.ts user.selector.ts product product.reducer.ts product.action.ts product.effect.ts product.selector.ts reducers.ts //Combine all reducers actions.ts //Combine all actions effects.ts //Combine all effects selectors.ts //Combine all selectors I have

Mock ngrx store selectors with parameters in unit tests (Angular)

强颜欢笑 提交于 2019-12-03 22:28:46
I am trying to write unit tests for a service in Angular. I want to mock the store.select function of ngrx, so I can test how let's say, a service, reacts to different values returned by the store selectors. I want to be able to mock each selector individually. My main problem is how to mock parametrised selectors. I have previously used a BehaviourSubject that I map to the select function, but this doesn't allow you to return different values for different selectors. It is not readable because it is not obvious what selector you are mocking. Opt 1: Mock Store using subject: impossible to know

The package rxjs@5.0.0-beta.6 does not satisfy its siblings' peerDependencies requirements?

╄→гoц情女王★ 提交于 2019-12-03 16:48:16
问题 I am trying to install @ngrx/store module in my angular 2 app. I am using npm install and getting the following error: npm ERR! peerinvalid The package rxjs@5.0.0-beta.6 does not satisfy its siblings' peerDependencies requirements! npm ERR! peerinvalid Peer @angular/core@2.0.0-rc.0 wants rxjs@5.0.0-beta.6 npm ERR! peerinvalid Peer @angular/http@2.0.0-rc.0 wants rxjs@5.0.0-beta.6 npm ERR! peerinvalid Peer angular2@2.0.0-beta.16 wants rxjs@5.0.0-beta.2 npm ERR! peerinvalid Peer @ngrx/store@1.5

Angular 4 resolve not completed when using ngrx

十年热恋 提交于 2019-12-03 16:05:22
I'm trying to use ngrx in a resolve in my app and for some reason it's not working. This is how I got it previously, using a simple service in my resolve route: resolve() { return this.service .getData() .map(data => data.pages.filter(page => page.parent === 'home')); } I then changed it into this: resolve() { this.store.dispatch(new LoadConfigAction()); return this.store .select('configuration') .do(data => console.log(data)) .map((data: any) => data.pages.filter(page => page.parent === 'home')); } I get data in my console, so data is being retrieved, but the resolved is apparently not

get single item from ngrx/store

老子叫甜甜 提交于 2019-12-03 15:59:30
问题 I've written the following reducer to store the state items in my Angular 2 app. The Items are price offers for Financial Instruments (e.g. stocks/currencies). My Reducer Implementation is as follows: export const offersStore = (state = new Array<Offer>(), action:Action) => { switch(action.type){ case "Insert": return [ ...state, action.payload ]; case "Update": return state.map(offer => { if(offer.Instrument === action.payload.Instrument) { return Object.assign({}, action.payload); } else

ngrx effect not being called when action is dispatched from component

ぃ、小莉子 提交于 2019-12-03 10:31:11
I am having an issue with the ngrx store not dispatching an action to the effect supposed to deal with it. Here is the component that tries to dispatch: signin() { this.formStatus.submitted = true; if (this.formStatus.form.valid) { this.store.dispatch(new StandardSigninAction(this.formStatus.form.value.credentials)); } } The actions: export const ActionTypes = { STANDARD_SIGNIN: type('[Session] Standard Signin'), LOAD_PERSONAL_INFO: type('[Session] Load Personal Info'), LOAD_USER_ACCOUNT: type('[Session] Load User Account'), RELOAD_PERSONAL_INFO: type('[Session] Reload Personal Info'), CLEAR

Run ngrx/effect outside of Angular's zone to prevent timeout in Protractor

心已入冬 提交于 2019-12-03 08:29:58
问题 I just started to write e2e tests for my app and am running into timeout problems with Protractor and ngrx/effects. I have the following effect dispatching an action every couple of minutes: @Effect() setSessionTimer$ = this.actions$ .ofType(Auth.ActionTypes.SET_SECONDS_LEFT) .map(toPayload) .switchMap(secondsLeft => Observable.concat( Observable.timer((secondsLeft - 60) * 1000).map(_ => new Auth.SessionExpiringAction(60)), Observable.timer(60 * 1000).map(_ => new Auth.SessionExpiredAction())