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

227
Views
NgRx Data service Update removes object prototype instead of updating the changed fields

When my NgRx DefaultDataService updates, it removes the type/prototype of the objects in the store. The objects are no longer of type Todo, but are simple objects with no prototype.

The objects come from the server as json objects conforming to the Todo interface. I pipe them to be entered into the store as Todo objects like this:

@Injectable()
export class TodosDataService extends DefaultDataService<ITodo> {
    baseUrl;

constructor( http: HttpClient, httpUrlGenerator: HttpUrlGenerator) {
    super("Todos", http, httpUrlGenerator);
}

getAll(): Observable<Todo[]> {

    //HERE - the ITodo[] from server is mapped to Todo[], then saved to store
    return super.getAll().pipe(
        map(todosList => todosList.map(todoData => new Todo(todoData)))
    );
}

But piping them on this service's update() override method doesn't work:

update(updatedTodo: Update<Todo>): Observable<Todo> {
    return super.update(updatedTodo).pipe(map(data => new Todo(data)));
}

Note: I've also tried this using my own httpClient.put request manually without DefaultDataService's super call and several other ways.

The problem problem is that when ngrx applies the deltas (changes) to the object in the store, it somehow not a todo object anymore. Here's a screenshot of the console right after running the above statement:

Todo Prototype is gone

This is causing unexpected behavior.

TL;DR: How can we make sure the update does not remove the prototype? If that's not possible, is there a simple way to intercept updates before they hit the store, in order to provide custom implementation?

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

0

This behavior is intended see the following GitHub issue for more info. https://github.com/ngrx/platform/issues/1641

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!