Горячее, чтобы исправить ngrx автоматически переписать все другие магазины при отправке любого - PullRequest
0 голосов
/ 28 октября 2019

Мне нужна помощь с магазином Angular ngRx. Я трачу пару дней на это, но не могу понять ((

У меня есть 2 магазина в моем приложении и когда я отправляю один из них (store.dispatch (new LoadProperties ())) мое предыдущее значениеиз другого магазина переоценены

это мои эффекты, реквестеры и app.module

recipes.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.ts

@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
  };

1 Ответ

0 голосов
/ 28 октября 2019

Похоже, что у редукторов нет корпуса default, который должен иметь, иначе состояние будет undefined.

switch (action.type) {
   ... other cases ...

   default:
     return state;
}
...