热修复ngrx自动在dispach任何存储时覆盖所有其他存储
我需要帮助去Angular ngRx商店。我为此花了几天时间,但我搞不懂(( 我的应用程序中有两个应用商店,当我分派其中一个(store.dispatch(new LoadProperties())时,我以前从另一个应用商店得到的值被高估了 这是我的特效、Requers和app.module 配方.效果.ts热修复ngrx自动在dispach任何存储时覆盖所有其他存储,ngrx,angular8,Ngrx,Angular8,我需要帮助去Angular ngRx商店。我为此花了几天时间,但我搞不懂(( 我的应用程序中有两个应用商店,当我分派其中一个(store.dispatch(new LoadProperties())时,我以前从另一个应用商店得到的值被高估了 这是我的特效、Requers和app.module 配方.效果.ts @Effect() loadRecipes$ = this.dataPersistence.fetch(fromRecipes.LOAD_RECIPES, { run:
@Effect() loadRecipes$ = this.dataPersistence.fetch(fromRecipes.LOAD_RECIPES, {
run: (action: LoadRecipes, state: RecipesState) => {
return this.recipesService.getRecipes()
.pipe(map((res: Recipe[]) => new LoadRecipesSuccess(res)));
},
onError: (action: LoadRecipes, error) => {
this.toaster.errorSnackBar(error.statusText, 'Cant fetch categories');
return of(new LoadRecipesError(error));
}
});
@Effect() loadProperties$ = this.dataPersistence.fetch(fromProperties.LOAD_PROPERTIES, {
run: (action: LoadProperties, state: PropertiesState) => {
return this.propertiesService.getProperties()
.pipe(map((res: Property[]) => new LoadPropertiesSuccess(res)));
},
onError: (action: LoadProperties, error) => {
this.toaster.errorSnackBar(error.statusText, 'Cant fetch properties');
return of(new LoadPropertiesError(error));
}
});
export interface AppState { recipes: fromRecipes.RecipesState; properties: fromProperties.PropertiesState;
}
imports: [
SharedModule,
BrowserModule.withServerTransition({appId: 'my-app'}),
HttpClientModule,
ToastrModule.forRoot(),
BrowserAnimationsModule,
StoreModule.forRoot(fromApp.appReducer),
EffectsModule.forRoot(fromApp.appEffects),
StoreDevtoolsModule.instrument({ maxAge: 10 }),
NxModule.forRoot()
...]
属性.effects.ts
@Effect() loadRecipes$ = this.dataPersistence.fetch(fromRecipes.LOAD_RECIPES, {
run: (action: LoadRecipes, state: RecipesState) => {
return this.recipesService.getRecipes()
.pipe(map((res: Recipe[]) => new LoadRecipesSuccess(res)));
},
onError: (action: LoadRecipes, error) => {
this.toaster.errorSnackBar(error.statusText, 'Cant fetch categories');
return of(new LoadRecipesError(error));
}
});
@Effect() loadProperties$ = this.dataPersistence.fetch(fromProperties.LOAD_PROPERTIES, {
run: (action: LoadProperties, state: PropertiesState) => {
return this.propertiesService.getProperties()
.pipe(map((res: Property[]) => new LoadPropertiesSuccess(res)));
},
onError: (action: LoadProperties, error) => {
this.toaster.errorSnackBar(error.statusText, 'Cant fetch properties');
return of(new LoadPropertiesError(error));
}
});
export interface AppState { recipes: fromRecipes.RecipesState; properties: fromProperties.PropertiesState;
}
imports: [
SharedModule,
BrowserModule.withServerTransition({appId: 'my-app'}),
HttpClientModule,
ToastrModule.forRoot(),
BrowserAnimationsModule,
StoreModule.forRoot(fromApp.appReducer),
EffectsModule.forRoot(fromApp.appEffects),
StoreDevtoolsModule.instrument({ maxAge: 10 }),
NxModule.forRoot()
...]
upd
这是配方减速机
嘿,这里!食谱还原器
witch (action.type) {
case RecipesActions.LOAD_RECIPES:
return {
...state, // the incoming state
loading: true // turn loading indicator on
};
case RecipesActions.LOAD_RECIPES_SUCCESS:
return {
...state, // the incoming state
recipes: action.payload,
loaded: true, // recipes were loaded
loading: false, // turn loading indicator off
};
case RecipesActions.LOAD_RECIPES_ERROR:
return {
...state, // the incoming state
loaded: false, // the recipes were loaded
loading: false, // turn loading indicator off
};
这是properties.reducer
switch (action.type) {
case PropertiesActions.LOAD_PROPERTIES:
return {
...state, // the incoming state
loading: true // turn loading indicator on
};
case PropertiesActions.LOAD_PROPERTIES_SUCCESS:
return {
...state, // the incoming state
properties: action.payload,
loaded: true, // properties were loaded
loading: false, // turn loading indicator off
};
case PropertiesActions.LOAD_PROPERTIES_ERROR:
return {
...state, // the incoming state
loaded: false, // the properties were loaded
loading: false, // turn loading indicator off
};
似乎减速机没有默认的
大小写,否则状态将是未定义的
switch (action.type) {
... other cases ...
default:
return state;
}
我没有看到减缩器,它们正在修改状态,所以我们可能会在这里找到答案。我现在添加减缩器。它很简单,只是返回状态。这发生在操作加载\配方或加载\属性被调度时。我在redux devtoolGreate中看到过!)它起作用了!我只是忘记了这一点!非常帮助我!谢谢!