Class: Wraith.ViewModel
Defined in: | src/viewmodel.coffee |
Inherits: | Wraith.BaseView |
Overview
The core Wraith View responsible for rendering a single instance of a view. It will bind to a models update event and re-render each time it changes
Direct Known Subclasses
Instance Method Summary
- - (void) constructor($el, template) Constructor Constructor
- - (HTMLElement) render(model) Renders the view given a Wraith.Model object.
- - (void) updateView(model) Updates the view for a given model.
- - (void) bindModel(model) Bound Bind ourselves (the view) to the model -- this is used in two-way binding.
- - (void) unbindModel(model) Bound Unbind ourselves from the given model.
- - (void) handleInputChange_(e, model) Bound When an input is typed into, we want to update the model (if it has a corresponding name)
- - (void) handleFormSubmit_(e, model) Bound Handle the form submit by creating a new instance of the model if it belongs to a collection.
Inherited Method Summary
Methods inherited from Wraith.BaseView
#constructor, #bindUIEvents, #bindUIEvent, #wrapUIEvent, #handleUIEvent, #unbindUIEvents, #unbindUIEvent, #applyViewUpdate, #updateAttribute
Methods inherited from Wraith.Base
#constructor, #bind, #unbind, #emit, #proxy
Constructor Details
- (void) constructor($el, template)
Constructor
Instance Method Details
- (HTMLElement) render(model)
Renders the view given a Wraith.Model object. By injecting the compiled template into a div and then pull it back out we are able to create a HTMLElement which is the desired returned result.
- (void) updateView(model)
Updates the view for a given model. Calls the render function and then does a replaceChild to swap the current view (@$el) for the new view. This also implicitly rebinds events after the view is rendered and inserted into the DOM.
- (void) bindModel(model) (bound)
Bind ourselves (the view) to the model -- this is used in two-way binding. Handles FORM submit binding if the nodeName of $el is a FORM. Also will trigger an update.
- (void) unbindModel(model) (bound)
Unbind ourselves from the given model.
- (void) handleInputChange_(e, model) (bound)
When an input is typed into, we want to update the model (if it has a corresponding name)
- (void) handleFormSubmit_(e, model) (bound)
Handle the form submit by creating a new instance of the model if it belongs to a collection.