From 0525ba6b0b6862c724ce3a7cc2760552574de9e4 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 27 May 2016 16:55:10 -0700 Subject: [PATCH] [API] Check/uncheck todos --- src/MCT.js | 6 ++++++ tutorials/todo/todo.js | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/MCT.js b/src/MCT.js index 3dcd97c229..bdbfb6b89d 100644 --- a/src/MCT.js +++ b/src/MCT.js @@ -56,5 +56,11 @@ define([ main: "MAIN" }; + MCT.prototype.verbs = { + mutate: function (domainObject, mutator) { + return domainObject.useCapability('mutation', mutator); + } + }; + return MCT; }); diff --git a/tutorials/todo/todo.js b/tutorials/todo/todo.js index f6a889b60b..de69086d99 100644 --- a/tutorials/todo/todo.js +++ b/tutorials/todo/todo.js @@ -54,7 +54,7 @@ define([ complete: $els.find('.example-todo-button-complete') }; var filters = { - all: function (task) { + all: function () { return true; }, incomplete: function (task) { @@ -71,12 +71,20 @@ define([ tasks = tasks.filter(filters[state.filter]); $list.empty(); - tasks.forEach(function (task) { + tasks.forEach(function (task, index) { var $taskEls = $(taskTemplate); - $taskEls.find('.example-task-checked') - .prop('checked', task.completed); + var $checkbox = $taskEls.find('.example-task-checked'); + $checkbox.prop('checked', task.completed); $taskEls.find('.example-task-description') .text(task.description); + + $checkbox.on('change', function () { + var checked = !!$checkbox.prop('checked'); + mct.verbs.mutate(domainObject, function (model) { + model.tasks[index].completed = checked; + }); + }); + $list.append($taskEls); });