I'm completely new to ngrx and I'm currently exploring how to handle state management with it. In my application, each staff member (agent) is associated with a group of customers. I'm struggling to define the initial state for each agent object.
import { createReducer } from "@ngrx/store";
import { Cursor } from "../../../models/cursor";
import { Customer } from "../../../models/customer";
export interface State {
agent_customer: {
[agentId: number]: {
customer: Customer[];
cursors: Cursor;
total: number;
loading: boolean;
errorMessage: string;
items_per_page: number;
pageSizeOptions: number[];
pageIndex: number;
searchKey: string;
};
};
}
It's important that each agent object has an initial state set up.
For example:
export const initialState: State = {
agent_customer: {
1: {
customer: [],
cursors: {
after: "",
before: "",
hasNext: false,
hasPrevious: false,
},
total: 0,
loading: false,
errorMessage: null,
items_per_page: 2,
pageSizeOptions: [2, 3, 5, 10, 15],
pageIndex: 0,
searchKey: "",
},
},
};
Edit: This is a representation of what the store should look like if everything goes smoothly.
agent_customer: {
198282: {
customer: [],
cursors: {
after: "",
before: "",
hasNext: false,
hasPrevious: false,
},
total: 0,
loading: false,
errorMessage: null,
items_per_page: 2,
pageSizeOptions: [2, 3, 5, 10, 15],
pageIndex: 0,
searchKey: "",
},
165436: {
customer: [],
cursors: {
after: "",
before: "",
hasNext: false,
hasPrevious: false,
},
total: 0,
loading: false,
errorMessage: null,
items_per_page: 2,
pageSizeOptions: [2, 3, 5, 10, 15],
pageIndex: 0,
searchKey: "",
},
981342: {
customer: [],
cursors: {
after: "",
before: "",
hasNext: false,
hasPrevious: false,
},
total: 0,
loading: false,
errorMessage: null,
items_per_page: 2,
pageSizeOptions: [2, 3, 5, 10, 15],
pageIndex: 0,
searchKey: "",
},
},
What I aim to achieve is to successfully establish the initial state for each subsequent object added to the store.