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

242
Views
Limitar el tamaño de la entidad Ngrx

Estoy creando una aplicación que obtendrá datos de un websocket y el tamaño de la entidad aumentará con el tiempo. Quiero eliminar los elementos antiguos cuando el tamaño supera el máximo. Actualmente uso selectTotal$ para obtener el tamaño actual de la entidad y, si supera el máximo, llamaré a removeMany(ids) para eliminar los elementos antiguos. Sin embargo, no creo que esta sea una buena manera, porque selectTotal$ se activará nuevamente. ¿Debo hacer esto en el reductor al cambiar artículos a la entidad?

Mi implementación actual:

 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 answers
Answer question

0

Puede escribir un efecto, que escuchará el empuje del websocket pero no guardará los datos directamente. En su lugar, verificará el estado actual, calculará uno nuevo y luego enviará una acción para guardar los datos en la tienda.

Algo como esto:

 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 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!