Refactoring mutations to enforce immutable data in Angular 2

InstructorJohn Lindquist

Share this video with your friends

Send Tweet

When a Todo property updates, you still must create a new Array of Todos and assign a new reference. This lesson walks you through refactoring from the current approach to the immutable approach.

Andre
~ 8 years ago

this.todos = [ ...this.todos.slice(0, i), todo, ...this.todos.slice(i + 1) ];

I don't understand how the todo item being toggled is being removed when it's being added back to the array in the todoToggle function?

Andre
~ 8 years ago

Answered my own question by looking back at previous code. I had forgotten about the 'started pipe' that was created in an earlier lesson, which is filtering the list of todo items that are then outputted by the *ngFor.