Last active
April 12, 2016 11:47
-
-
Save seanchas116/a0d265ec34d43c62c01841e29ad5ef99 to your computer and use it in GitHub Desktop.
Simple list data-binding utility idea
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
<div class="todo-list"> | |
<div class="todo"> | |
<input type="checkbox" class="done"> | |
<h3 class="title">Title</h3> | |
</div> | |
</div> |
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
const todoBinder = bindToChildren({ | |
element: document.querySelector(".todo-list"), | |
key: (value) => value.id, | |
// called on first insertion | |
onAdd: (elem, value) => { | |
return new TodoController(elem); | |
}, | |
// called on data update | |
onUpdate: (elem, value, controller) => { | |
controller.setTodo(value); | |
}, | |
// called on removal | |
onRemove: (elem, value, controller) => { | |
controller.dispose(); | |
} | |
}); | |
binder.values = [ | |
{title: "Task", done: false, id: 0}, | |
{title: "Another Task", done: true, id: 1}, | |
]; | |
binder.values = [ | |
{title: "Task", done: true, id: 0}, | |
{title: "Another Task", done: true, id: 1}, | |
{title: "New Task", done: false, id: 2}, | |
]; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment