ngrx-store

Ngrx store immutable state with an array?

别说谁变了你拦得住时间么 提交于 2019-12-10 18:27:17
问题 I'm planning to create a large application with Angular 5. I want to use Ngrx too to store the state of my app. But there is one thing I don't understand. Let's say that I have an object (I don't use classes or interfaces now for simplicity), that represents my state in a Store : let state = { x: 10, y: [1, 2, 3] }; In every article that I read the writers are using Object.assign() to create a copy of the state in a reducer. For example: ... case SET_X: return Object.assign({}, state, {x: 123

Angular 6 ngrx, how to add new item to array in state object?

心不动则不痛 提交于 2019-12-10 02:29:26
问题 I have a simple situation, I have actions Like CreatUser, CreateSuccess, CreateFail. How should I add new object to array and when Create action is dispatched or CreateSuccess ? And how should I do that? export function reducer(state = init, action: Actions): State { switch (action.type) { case ActionsTypes.CREATE: return { ...state, inProgress: true }; case ActionsTypes.CREATE_SUCCESS: return { ...state, users: state.users.push(action.payload), inProgress: false }; case ActionsTypes.CREATE

NullInjectorError: No provider for ReducerManager

浪尽此生 提交于 2019-12-08 15:57:41
问题 I am using the new ngrx 5. This is the file that holds the reducers and the featureSelector: import AppState from '../interfaces/app.state' import { ActionReducerMap, createFeatureSelector } from '@ngrx/store' import { partnerReducer } from './partner.reducer' export const reducers: ActionReducerMap<AppState> = { partnerState: partnerReducer } export const getAppState = createFeatureSelector<AppState>('appState') This is how I am importing the storeModule @NgModule({ declarations: [...],

What is the meaning of square brackets in the enum declaration in typescript?

一世执手 提交于 2019-12-08 07:58:15
问题 I was going through a typescript file in an Angular ngrx project named as collection.ts and there, I saw the following enum constant being declared. import { Action } from '@ngrx/store'; import { Book } from '../models/book'; export enum CollectionActionTypes { AddBook = '[Collection] Add Book', AddBookSuccess = '[Collection] Add Book Success', AddBookFail = '[Collection] Add Book Fail', RemoveBook = '[Collection] Remove Book', RemoveBookSuccess = '[Collection] Remove Book Success',

NgRx - How are states combined and initialized

血红的双手。 提交于 2019-12-07 22:14:53
问题 When we initialize our Store: StoreModule.provideStore({r1: Reducer1, r2: Reducer2, ...}) we do pass the reducers to the Store to be stored. But we never actually pass the initial states to the store, except defining it in the reducers functions: const someReducer = (state = initialState, act: Action) => { ... } SO, is it that when application bootstraps, all the reducers are called once to acquire the initial state from reducer definition, and then store the state in the NgRx Store? If so,

Denormalizing ngrx store- setting up selectors?

冷暖自知 提交于 2019-12-07 12:35:03
问题 I am currently working with a somewhat complicated (deep) structure within an ngrx project. It can be thought of as an array of parent objects, with multiple levels of child objects. It is normalized/flattened on the server side, and my the feature within my store looks something like this: rootObjs: { level1: { byId: { 'lvl1_1': {id: 'lvl1_1', label: '[Lvl 1]: 1', ui_open: true, children: ['lvl2_1', 'lvl2_3']}, 'lvl1_2': {id: 'lvl1_2', label: '[Lvl 1]: 2', ui_open: false, children: ['lvl2_2'

How to set initialState in @ngrx/core with a promise from indexedDB

青春壹個敷衍的年華 提交于 2019-12-06 08:25:58
I wanted to set the initial state in ngrx using the idb package which uses promise to fetch data, but am getting an error every time I tried to set it up. I read that @ngrx is synchronous does that mean it does not work with promises. The different methods I tried: this is my wrapper method for idb that loads in the data it works fine export function getInitialState(): Promise<any> { return StorageService.dB.loadInitialState('app-state'); } and the different methods I tried set the initial state method: 1 StoreModule.forRoot(reducers, {initialState: getInitialState}) method: 2 import { INITIAL

NgRx - How are states combined and initialized

南笙酒味 提交于 2019-12-06 08:04:38
When we initialize our Store: StoreModule.provideStore({r1: Reducer1, r2: Reducer2, ...}) we do pass the reducers to the Store to be stored. But we never actually pass the initial states to the store, except defining it in the reducers functions: const someReducer = (state = initialState, act: Action) => { ... } SO, is it that when application bootstraps, all the reducers are called once to acquire the initial state from reducer definition, and then store the state in the NgRx Store? If so, is it that every reducer must have an initial state value? otherwise the states will always be undefined

Denormalizing ngrx store- setting up selectors?

半城伤御伤魂 提交于 2019-12-05 22:56:43
I am currently working with a somewhat complicated (deep) structure within an ngrx project. It can be thought of as an array of parent objects, with multiple levels of child objects. It is normalized/flattened on the server side, and my the feature within my store looks something like this: rootObjs: { level1: { byId: { 'lvl1_1': {id: 'lvl1_1', label: '[Lvl 1]: 1', ui_open: true, children: ['lvl2_1', 'lvl2_3']}, 'lvl1_2': {id: 'lvl1_2', label: '[Lvl 1]: 2', ui_open: false, children: ['lvl2_2']} }, allIds: [ 'lvl1_1', 'lvl1_2' ] }, level2: { byId: { 'lvl2_1': {id: 'lvl2_1', label: '[Lvl 2]: 1',

Angular 6 ngrx, how to add new item to array in state object?

依然范特西╮ 提交于 2019-12-05 02:01:22
I have a simple situation, I have actions Like CreatUser, CreateSuccess, CreateFail. How should I add new object to array and when Create action is dispatched or CreateSuccess ? And how should I do that? export function reducer(state = init, action: Actions): State { switch (action.type) { case ActionsTypes.CREATE: return { ...state, inProgress: true }; case ActionsTypes.CREATE_SUCCESS: return { ...state, users: state.users.push(action.payload), inProgress: false }; case ActionsTypes.CREATE_FAIL: return { ...state, error: action.payload, inProgress: false }; default: return state; } In code