Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
Cómo establecer el estado inicial para la aplicación de la tienda ngrx

Soy nuevo en ngrx y estoy tratando de administrar mi estado con él. En mi aplicación, cada agente (personal) tiene un grupo de clientes que están vinculados a él / ella. Estoy tratando de establecer el estado inicial de cada objeto del agente y no sé cómo.

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

Cada objeto de agente debe tener algún estado inicial.

algo como esto

 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: "", }, }, };

Editar: Este es un ejemplo de lo que debería haber en la tienda si todo va bien.

 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: "", }, },

Lo que quiero es poder establecer el estado inicial de cada objeto posterior que agregue a la tienda.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Debe usar el Módulo de tienda para esto-

import {createAction, props} from '@ngrx/store'

Consulte la guía oficial: https://ngrx.io/guide/store https://ngrx.io/guide/store/reducers

Consulte esta esencia: https://github.com/ngrx/platform/issues/662

about 4 years ago · Juan Pablo Isaza Report

0

Intente pasar el tipo, luego configure el estado inicial de su reductor

 import { Action, createFeatureSelector, createReducer, on } from '@ngrx/store'; import { ACTION } from './actions'; import { Entity} from './entity'; export interface CustomState { agent: Entity[] // Pass the entity type, on this case Entity[] } // type the initial state with your interface(state) const initialState: CustomState = { agent: [ // Pass here each object of type (Entity) { total: 0, loading: false, errorMessage: null, items_per_page: 2, ... } ] } const reducer = createReducer( initialState, on(ACTION, (state, { payload }) => ({ ...state, agent: payload })) ); export function customReducer(state: CustomState, action: Action) { return reducer(state, action) }; export const getCustomState = createFeatureSelector<CustomState>('customName');
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!