Skip to content

Instantly share code, notes, and snippets.

@michael-mafi
Last active February 4, 2017 00:07
Show Gist options
  • Select an option

  • Save michael-mafi/2cf9ee474ded2605d44391be6fd88041 to your computer and use it in GitHub Desktop.

Select an option

Save michael-mafi/2cf9ee474ded2605d44391be6fd88041 to your computer and use it in GitHub Desktop.
todoMVC taking 'store' out of render and putting it into it's own function - gomix preview https://gomix.com/#!/project/dirty-beam
// Step 1 // Remove the call to util.store from the App.render function below
render: function(){
var todos = this.getFilteredTodos();
$('#todo-list').html(this.todoTemplate(todos));
$('#main').toggle(todos.length > 0);
$('#toggle-all').prop('checked', this.getActiveTodos().length === 0);
this.renderFooter();
$('#new-todo').focus();
},
// Step 2 // Create a new function called "App.store" to replace the work that was previously done by the App.render function
store: function(){
util.store('todos-jquery', this.todos);
},
// Step 3 // Then the function is called in all the same methods that used to rely on the
// render function to store the todo, an example of that here at the bottom of the toggleAll function.
// Complete app preview here: https://gomix.com/#!/project/dirty-beam
toggleAll: function(e){
var isChecked = $(e.target).prop('checked');
this.todos.forEach(function(todo){
todo.completed = isChecked;
});
this.store(); // Store it!
this.render(); // Display it!
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment