Class: Wraith.BaseView

Defined in: src/baseview.coffee
Inherits: Wraith.Base

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. Additionally it will handle setting classes up based on the data-class directive, and other bindings that might be required in the future.

Direct Known Subclasses

Wraith.Controller, Wraith.ViewModel

Instance Method Summary

Inherited Method Summary

Methods inherited from Wraith.Base

#constructor, #bind, #unbind, #emit, #proxy

Constructor Details

- (void) constructor($el)

Constructor

Parameters:

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

Instance Method Details

- (void) bindUIEvents($view) (bound)

Iterates over a view and its children looking for the data-events attribute which should be a comma separated list of events. The scheme is defined by #bindUIEvent

Parameters:

  • $view (HTMLElement) The view element to bind to

- (void) bindUIEvent($view, event) (bound)

Binds to a UI event on a given view. Relies on the data-events attribute to be a space or comma delimited list of events. A valid event is given in the schema event:callback The event must be part of Wraith.UIEVENTS

Parameters:

  • $view (HTMLElement) The view element to bind to
  • event (HTMLElement) The event as defined in the description above

- (void) wrapUIEvent(cb) (bound)

Used as a wrapper for handling UI events and maintaining the proper context.

Parameters:

  • cb (String) The name of the callback function on the controller

- (void) handleUIEvent(e, cb) (bound)

Handles a UI event on the view level. Calls stopPropagation by default to prevent bubbling. Also will emit a uievent for the parent controller to listen to so it can invoke the proper method in the controller.

Parameters:

  • e (Event) The UI Event from the browser
  • cb (String) The name of the callback function on the controller

- (void) unbindUIEvents($view) (bound)

Unbinds a given view and its childrens UI events.

Parameters:

  • $view (HTMLElement) The view to unbind events from

- (void) unbindUIEvent($view, event) (bound)

Unbinds a given view from the given set of events. Follows the same schema as Wraith.BaseView#bindUIEvent does for binding.

Parameters:

  • $view (HTMLElement) The view to unbind events from
  • event (HTMLElement) The event as defined in the description above

- (void) applyViewUpdate($old, $new) (bound)

TODO: make this more efficient!

Crawls the old nodes and new nodes, compares their contents and attributes, and updates the old node accordingly. This prevents the entire view from re-rendering each time data changes.

Parameters:

  • $old (HTMLElement) The old DOM element that we are updating
  • $new (HTMLElement) The new DOM element we are updating based on

- (void) updateAttribute(name, $old, $new)

Updates a given attribute on $old to the current value on $new. Used to update values on a DOM element without having to rewrite the entire DOM structure (children etc).

Parameters:

  • name (String) The attribute name to update
  • $old (HTMLElement) The old DOM element that we are updating
  • $new (HTMLElement) The new DOM element we are updating based on