ngrx

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

ngrx, How to have a starting state from an api?

我怕爱的太早我们不能终老 提交于 2019-12-06 07:43:49
I have my reducer with a starting state of an empty array: folderReducer(state:Array<Folder> = [], action: Action) I'd like to populate the starting state, so when I do store.subscribe(s => ..) The first item I get comes from the database. I assume the way of doing this is with ngrx/effects, but I'm not sure how. Your store always has the initial state , that you define in the reducer-function. The initial states main purpose is to ensure that the application is able to start up and not run into any null-pointer-exceptions. And also it sets up your application to start making the first api

NgRX Effect for downloading media file and dispatching progress; how to deal with the stream and throttling

南笙酒味 提交于 2019-12-06 07:30:28
I am struggling a bit with understanding and applying @Effects for my episode Download option. I got some help in another question and this is my latest concoction. Quick overview: User clicks download which dispatches a DOWNLOAD_EPISODE action which is captured in the first Effect. The download call returns a stream of HttpEvents and a final HttpResponse. During the event.type === 3 I want to report download progress. When event.type === 4 the body has arrived and I can call the success which for example can create a Blob. Service episodesService : download( episode: Episode ): Observable

Angular2 NGRX Performance Issues On Dispatch?

故事扮演 提交于 2019-12-06 06:08:40
I've been working on an application in Angular2/CLI/NGRX and things have been going well until recently. I'm noticing some pretty big spikes in performance especially with consecutive dispatches within the same container. For example lets say I have the following defined: public appEnvironment$: Observable<IEnvironment>; public assessment$: Observable<IAssessment>; public assessmentComments$: Observable<ICommentActivity[]>; public assessmentEvidence$: Observable<IEvidenceActivity[]>; public assessmentIssues$: Observable<IIssueActivity[]>; public assessmentSurvey$: Observable<ISurvey>; public

Is it possible to throw errors inside ngrx-effects without completing the Observable stream?

夙愿已清 提交于 2019-12-06 05:45:37
Is there any way to use throw with an Error object inside ngrx-effects streams without completing the stream? I've read these great answers on why the stream is being killed by throwing an error: @ngrx Effect does not run the second time ngrx effects error handling https://github.com/ngrx/platform/issues/646 My question is if I'm implementing the Angular ErrorHandler to catch errors, if I'm going to be able to use that with ngrx effects. @Effect() loginUserEffect: Observable<loginActions.Actions> = this.actions$ .ofType(loginActions.LOGIN_USER) .map((action: loginActions.LoginUser) => action

Ngrx effects on lower version of typescript doesn't work

試著忘記壹切 提交于 2019-12-06 05:01:55
I have an Ionic 3 App where I use ngrx/store and ngrx/effects . But each time I try to run the app it sais this error below: TypeScript Error A computed property name in a type literal must directly refer to a built- in symbol. ...: Cannot find name 'any'. which refers to this folder in my node modules node_modules/@ngrx/effects/src/on_run_effect.d.ts to this block of code below: export declare function isOnRunEffects(sourceInstance: { [onRunEffectsKey]?: onRunEffectsFn; }): sourceInstance is OnRunEffects; This can be fix by installing higher version of typescript but as of now currently I am

Infinite loop with ngrx/effects

允我心安 提交于 2019-12-06 04:54:57
I'm trying to understand ngrx/effects. I have built a simple function that increments number by 1 with each click. But it's going in an infinite loop when clicked, not sure whats going on. I'm sure im making some stupid mistake. monitor.effects.ts @Injectable() export class MonitorEffects { @Effect() compute$: Observable<Action> = this.actions$ .ofType(monitor.ActionTypes.INCREMENT) .map((action: monitor.IncrementAction) => action.payload) .switchMap(payload => { return this.http.get('https://jsonplaceholder.typicode.com/users') .map(data => new monitor.IncrementAction(payload+1)) .catch(err =

Angular & NGRX prevent selector from emitting identical value on state change when values are equal

淺唱寂寞╮ 提交于 2019-12-06 03:28:58
问题 I'm searching for a solution to make my selector only emit a new value when the it has changed compared to the last emitted value, and not only the reference to the store is changed. I have the following state in my store: { items: [], loading: false, selectedItemId: 1 } And I have the following selector: export const getSelectedItem = createSelector(getItemsState, (state) => { return state.selectedItemId === null ? null : state.items.find(item => item.id === state.selectedItemId) } ); When I

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',