Skip to content

Instantly share code, notes, and snippets.

@petermichaux
Created May 4, 2012 07:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save petermichaux/2593030 to your computer and use it in GitHub Desktop.
Save petermichaux/2593030 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