ngrx

Is the ngrx store persistent?

回眸只為那壹抹淺笑 提交于 2019-12-13 09:11:07
问题 Is the ngrx store persistent? In other words can we close the browser reopen it, and retrieve state that was added to the ngrx store? 回答1: Currently ngrx/store doesn't support such functionality. But you can maintain state by using a library like ngrx-store-persist to save data to the browsers indexedDB, localStorage or WebStorage. This library automatically saves and restores ngrx/store's data. You just need to add redux keys that you want to store in the config (see "Usage" section). 回答2:

Piping inside a subscribe in ngrx

喜欢而已 提交于 2019-12-13 06:29:38
问题 I have a selector that takes a parameter to filter values. The parameter depends on an observable's return. export class LineSynopticComponent implements OnInit, AfterViewInit { schedules$: Observable<ISchedule[]>; ngOninit(){ this.selectedDate$.subscribe(elm => { this.schedules$ = this.store.pipe(select(selectSchedulingsTimes, { time: elm.timeSelect })); }); } the selectSchedulingsTimes selector is defined as well: const schedulings = (state: IAppState) => state.schedulings; export const

How to get the correct slice data using selectors for multiple pieces of state and use them inside component | ngRx | Redux | Angular 6 | typescript

时间秒杀一切 提交于 2019-12-13 03:25:30
问题 I am going to create an application using angular 6 and ngrx v6. I have created the following app state. app.module.ts StoreModule.forRoot({'user': userReducer, 'events': eventsReducer}), app.state.ts import { UsersState } from '@app/reducers/users.reducers'; import { EventsState } from '@app/reducers/events.reducers'; export interface AppState{ user:UsersState, events:EventsState } users.reducers.ts export interface UsersState { lastInteractionTime: number, bookmarksId: object } const

Property 'replaceReducer' does not exist on type 'Store<State>' After upgrading @ngrx/store

大憨熊 提交于 2019-12-13 03:23:53
问题 In my Angular app, I have a function which replaces replaces the current reducer used by the Store. However, after upgrade from @ngrx/store v2.2.2 to v6.1.0, "replaceReducer" function seems to have been removed from the Store interface. I've gone through the NGRX migration guide (https://github.com/ngrx/platform/blob/master/MIGRATION.md) hoping to find a possible solution or an alternative way to go around the issue but I can't find any reference to the removed "replaceReducer" function

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)

i18n with ngrx store - translating angular application

丶灬走出姿态 提交于 2019-12-12 23:38:41
问题 I'm writing to ask you for advice. We build store based angular application, which requires translation. The request is to use official angular i18n method, although I have no idea how to connect my translations with values from the store. Is it even possible, does anyone have any experience with this or should I straight away go to the solutions like ngx-translate library..? I must say I researched quite a bit, but have not found understandable (I'm a junior and it's pretty hard for me to

TypeScript type not working with spread operator

余生颓废 提交于 2019-12-12 18:03:16
问题 I have a redux style reducer (I'm using ngrx) that is returning a specific type. When I use the spread operator in my return object, the typescript linter is not catching invalid properties. Here is my interface: interface MyState { firstName: string; lastName: string; age: number; } Here is my reducer. Action is an ngrx action: function reducer(state = initialState, action: Action): MyState { switch (action.type) { case Actions.COOL_ACTION: return { ...state, propertyDoesNotExist: action

Angular ngrx migration error “Property 'select' does not exist on type 'Observable<State>'”

落爺英雄遲暮 提交于 2019-12-12 17:12:57
问题 I am attempting to migrate an existing application from ngrx v2 to v4, and am having a bit of trouble with a scenario I do not see covered in the migration document. The migration document has you remove @ngrx/core, but I am not sure what to do with my reducers that import from @ngrx/core/add/operator/select and select from an Observable. I am getting the error "Property 'select' does not exist on type 'Observable'" from all of the reducers. /actions/action-with-payload.ts -- Workaround for

changing the store state from component ngrx

こ雲淡風輕ζ 提交于 2019-12-12 16:54:52
问题 I'm using selectors to select from the store this.quizz = this.store.select(getSelectedQuizz); I use the async pipe to read from this observable like this in the template [*ngIf="quizz | async; let quizz"] I only define the action and I didn't modify the reducer yet the template is a form when I save the form I dispatch an update action which is only defined in my actions with readonly but I notice that when ever I save the form and dispatch the action the store changed and I didn't specify

How to test ngrx pipe select in Rxjs 6

被刻印的时光 ゝ 提交于 2019-12-12 13:57:39
问题 Previously I could test the below store select this.store.select(fromRoot.someselector).pipe(map(r => this.store.dispatch(new Action()))); This was in my test {provide: Store, useValue: jasmine.createSpyObj('store', ['select']); store.select.and.returnValue(of({})); But now it has changed to pipes this.store.pipe(select(fromRoot.someselector)); this.store.pipe( select(fromRoot.someselector), filter(result => !!result), map(r => { if (result === ' hello') { this.store.dispatch(new Action()); }