Created
May 1, 2017 09:54
-
-
Save tomastrajan/904f2840640b6049de14b9be78d8f13f to your computer and use it in GitHub Desktop.
Angular Model Pattern - model mutation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable() | |
export class TodosService { | |
/* ... */ | |
// pass all neccessary data as funcion parameters | |
toggleTodo(name: string) { | |
// retrieve model internal state | |
const todos = this.model.get(); | |
// mutate model internal state | |
todos.forEach(t => { | |
if (t.name === name) { | |
t.done = !t.done; | |
} | |
}); | |
// set new model state; and notify all subscribed componenets | |
this.model.set(todos); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment