Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created April 14, 2012 18:35
Show Gist options
  • Select an option

  • Save Raynos/2386775 to your computer and use it in GitHub Desktop.

Select an option

Save Raynos/2386775 to your computer and use it in GitHub Desktop.
To-do application to-do item view implementation
/*
I herd u liek bloat and useless frameworks.
Just write JavaScript already
Uses [DelegateListener][1] and [fragment][2]
[1]: https://github.com/termi/DelegateListener
[2]: https://github.com/Raynos/fragment
*/
CheckIt.TodoController = {
model: CheckIt.TodoModel,
view: CheckIt.ToDoView,
start: function () {
document.addEventListener(
'click',
new DelegateListener('.done', this.handleClickDone.bind(this))
);
this.view.render()
},
handleClickDone: function (evt) {
this.view.update(this.model)
}
}
CheckIt.TodoView = {
render: function () {
var rootEl = this.rootEl = document.createElement('li');
rootEl.className = 'Todo'
rootEl.appendChild(
fragment('<input type="checkbox" class="done">' +
'<span class="description"></span>')
);
this.textWrapper = rootEl.querySelector('span');
},
update: function (model) {
this.textWrapper.textContent = model.description
this.textWrapper.className = 'description ' + model.status
}
}
CheckIt.Model = {
description: "bar",
status: "foo"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment