The reducer within ngrx/store fails to trigger

In my project using combineReducers with "@angular/core": "4.4.3" and "@ngrx/store": "4.0.3", I am facing an issue where the reducers are not being detected after dispatching the actions.

It could be due to my lack of experience with ngrx/store.

You can view the entire project here: https://github.com/raduchiriac/workflow

app.module.ts

import { AppStore } from './app.store'

@NgModule({
  imports: [
    StoreModule.forRoot(AppStore),
    ...
  ],
  providers: [
    ...
  ]
})

app.store.ts

import { createSelector } from 'reselect';
import * as ModalsReducer from "./store/reducers/modals.reducer";

export interface AppState {
  modals: ModalsReducer.State,
}

const metaReducer: ActionReducer<AppState> = combineReducers({
  modals: ModalsReducer.reducer,
});

export function AppStore(state: any, action: any) {
  return metaReducer(state, action);
}

modals.reducer.ts

import * as ModalsActions from '../actions/modals.actions';

export interface State {
  triggerAdd: boolean;
}

const initialState: State = {
  triggerAdd: false,
};

export function reducer(state = initialState, { type, payload }): State {
  switch (type) {
    case ModalsActions.MODALS_TRIGGER_ADD_CLOSE : {
      return Object.assign({...state}, {
        triggerAdd: false
      });
    }
    ...
}

triggers.component.ts

addNew() {
  this.store.dispatch(new ModalsActions.OpenTriggerAddAction());
}
...

EDIT: I found that the only way the store will work is by following this method. But why?

app.module.ts

import { AppStore, reducers } from './app.store'
...
imports: [
  StoreModule.forRoot(reducers, {}),
]

Answer №1

If you're working with ngrx v4, make sure to consult the migration guide for important changes.

One key change in v4 is how reducers are registered.

The syntax

StoreModule.forRoot(reducers, {})
is used because StoreModule.forRoot requires an object of type ActionReducerMap<T, V>. The second argument, {}, represents the initial state.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Expanding the npm packages available on the Azure DevOps Feed

My current project utilizes Angular 2.4 and includes a .npmrc file configured to use an internal registry. The build pipeline I have set up is throwing the following error: No matching version found for yargs@^3.32.0. In most cases you or one of your dep ...

Having trouble with Apple Login functionality in Safari on my Angular application

While implementing apple login in my web app, I encountered an issue with Safari browser. Instead of opening the redirect URI in a new tab, it displays a finger touch enabled login popup. This prevents the passing of the redirect URI and causes problems wi ...

Matching only the specified Records in an array of Typescript generic objects

Check out this demo: https://tsplay.dev/Nnavaw I am working with an array that has the following structure: Array<{ id?: string; text?: string; date?: Date; }> This conflicts with the current implementation: data: Array<Par ...

Typescript headaches: Conflicting property types with restrictions

Currently, I am in the process of familiarizing myself with Typescript through its application in a validation library that I am constructing. types.ts export type Value = string | boolean | number | null | undefined; export type ExceptionResult = { _ ...

Retrieve the text content from a component using ContentChild, rather than accessing another instance of a component

Is there a way to access the text within the tags of a component? <my-custom-component>THIS TEXT</my-custom-component> In a template, using ng-content is an option, or within the component definition as shown in these examples. However, my go ...

Is it possible to utilize instanceof to verify whether a certain variable is of a class constructor type in TypeScript?

I am currently facing an issue with a function that takes a constructor as a parameter and creates an instance based on that constructor. When attempting to check the type of the constructor, I encountered an error. Below are some snippets of code that I ...

SwitchMap in Typescript allows you to switch to a

In my TypeScript code, I have implemented multiple interfaces, components, and a key/interface map. interface FooProps { 'keyInFoo': string } const Foo = (props: FooProps) => {} interface BarProps { 'keyInBar': string } cons ...

Is it possible to begin the vue root instance by using a .vue class component?

Utilizing vue-class-component allows me to incorporate class syntax and TypeScript type checking within my .vue files. I can easily create .vue files and register them as components using this method, with the exception of the root Vue() instance. This ap ...

TS1056 Error: Accessors can only be utilized with ECMAScript 5 or newer versions targeted

I'm currently working on a SharePoint framework project that has the following folder layout: One of the directories is named dataaccess and contains a webpart factory method. The file Sharepointdataprovider.ts includes this code snippet: import { ...

Angular shows nested values without considering dynamic keys

I need assistance with displaying user data retrieved from Firebase database. The JSON response I receive from Firebase starts with a dynamic value like "SivqCsErHQZNvGMe7p6r5nGknFy2". How can I skip this dynamic value and only show key/value pairs below? ...

Changing {number, Observable<string>} to Observable<number, string> is a necessary transformation to be made

Is there a way to convert an array of objects with the following structure: { id: number, data: Observable<string> } into an array of objects with this structure: Observable<{id: number, data: string}> using only RxJS operators? ...

Changing the dropdown value by clicking the previous and next buttons in Angular 2

I need to implement a feature in Angular 2 where the default date displayed in a dropdown is the current year. Additionally, when the "Prev" button is clicked, the selected year value in the dropdown should decrease by one. // Our root app component imp ...

Reducer is not a standalone function in the realm of React Native's Redux framework

I need to implement a reducer in my react native application. The store constant is defined as follows: export const USER_PROFILE = 'USER_PROFILE'; This is the content of action.js file: import {USER_PROFILE} from '../constants/index'; ...

How can I stop DOM removal in Angular 2 RC5?

Encountering difficulties with Angular 2 on touch devices is a common issue. Specifically, when a Component is rendered via NgFor and is dragged on the screen using touch. The problem arises when a re-render of the NgFor happens during a touch drag, causin ...

Using Angular 8, remember to not only create a model but also to properly set it

hello Here is a sample of the model I am working with: export interface SiteSetting { postSetting: PostSetting; } export interface PostSetting { showDataRecordAfterSomeDay: number; } I am trying to populate this model in a component and set it ...

Personalizing Dialog Title in material-ui

While delving into the world of React and Material-UI, I encountered a challenge in updating the font color in the DialogTitle component. After browsing through various resources, I came across a helpful link that suggested overriding the dialog root class ...

Angular example of Typeahead feature is sending a blank parameter to the backend server

I am currently trying to implement a similar functionality to the example provided at this link in my Angular frontend application. The goal is to send a GET request to my backend with the search parameter obtained from an input field. However, even thoug ...

Facing unexpected behavior with rxjs merge in angular5

import { Observable } from 'rxjs/Observable'; import 'rxjs/add/observable/merge'; this.data = this.itemsCollection.valueChanges() this.foo = this.afs.collection<Item>('products') .doc('G2loKLqNQJUQIsDmzSNahlopOyk ...

Converting an anonymous function to a named function in JavaScript

In my Angular application, I have the following template: <dxi-column dataField="ordre" caption="Ordre" [width]="70" dataType="number" [allowEditing]="true"> <dxi-validation-rule type=" ...

Encountering an Angular 12 error 401 upon refreshing the page

Currently, I am working on a login form using angular 12 with Spring Boot that includes basic authentication spring security. When a user successfully logs in, they are directed to the main page which offers CRUD actions as depicted in the images linked be ...