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

Wraith.CollectionView

Instance Method Summary

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

Parameters:

  • $el (HTMLElement) The HTML Element to attach the view to
  • template (String) The template string to use when rendering

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.

Parameters:

Returns:

  • (HTMLElement) — A HTMLElement from the resulting render

- (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.

Parameters:

- (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.

Parameters:

- (void) unbindModel(model) (bound)

Unbind ourselves from the given model.

Parameters:

- (void) handleInputChange_(e, model) (bound)

When an input is typed into, we want to update the model (if it has a corresponding name)

Parameters:

  • e (Event) The keypress event
  • model (Wraith.Model) The model associated with this event

- (void) handleFormSubmit_(e, model) (bound)

Handle the form submit by creating a new instance of the model if it belongs to a collection.

Parameters:

  • e (Event) The form submit event
  • model (Wraith.Model) The model associated with this event