Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

249
Vistas
Limiting the size of Ngrx entity

I am building an app that will fetch data from a websocket, and the size of entity will increase overtime. I want to remove the old items when the size exceeds maximum. I currently use selectTotal$ to get the current size of the entity and if it exceeds maximum, then I will call removeMany(ids) to delete the old items. However, I don't think this is a good way, because the selectTotal$ will be triggered again. Should I do this in reducer when upserting items to the entity?

My current implementation:

this.store.selectTotal$
 .pipe(
    filter((t) => t > MAX_COUNT),
    switchMapTo(this.store.ids$)
  )
  .subscribe((ids) => {
      const removals = ids.slice(MAX_COUNT);
      this.store.removeMany(removals);
  });
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can write an effect, that will listen to the websocket push but it won't save the data directly. Instead it will check for the current state, calculate a new one and then it'll dispatch an action to actually save the data to the store.

Something like this:

someEffect$ = createEffect(() => 
  this.acitons$.pipe(
    ofType(processDataPushAction),
    withLatestFrom(this.store.selectAll), // Get all entities currently in store
    map(([<action.payload>, allData]) => {
      let calcResult; // 
      if (allData.length > MAX_COUNT) {
        // splice and assign to calcResult
      } else {
        calcResult = <action.payload>;
      }
      return saveDataAction({ calcResult });
    })
  )
)
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda