Skip to content

Instantly share code, notes, and snippets.

@mobz
Forked from petermichaux/gist:2593030
Created May 5, 2012 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mobz/2602772 to your computer and use it in GitHub Desktop.
Save mobz/2602772 to your computer and use it in GitHub Desktop.
Golfing Maria Views
// The following is sugar for writing out in full a view constructor function, its prototype, and the boilerplate
// for inheriting from maria.ElementView. This sugar uses naming conventions to wire together
// the view with its model, controller, and their methods.
//
// A checkit.TodoView will observe a checkit.TodoModel. When the model changes, the update method below is called.
// When a user clicks on the todo element, the handling is delegated to the checkit.TodoController's
// handleRootClick method.
//
maria.ElementView.declareConstructor(checkit, 'TodoView', {
template: '<li><span class="todo-content"></span></li>', // the template can live elsewhere, of course
actions: {
'click li': 'handleRootClick'
},
methods: {
update: function() {
this.find('.todo-content').innerHTML = this.getModel().getContent();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment