-
Notifications
You must be signed in to change notification settings - Fork 2
dataview
Unlike the base View class it comes from, the Dataview Object has some strong opinions about how it is used by observing some conventions.
###A Model
View Objects in sudo.js do not necessarily have a Model, but a Dataview must. As usual, it can be unique to this particular Class or shared. The Dataview itself assumes the following about its model:
- It contains a template.
- There may be a renderTarget.
- There may be a renderMethod.
- There may be an autoRender.
####template
Dataviews hydrate the 'innerHTML' of this.$el by passing their model's 'data' hash to their template. The template value located in this Dataview's model can either be in string form, or already 'compiled' into a function.
####renderTarget
Any argument suitable for al "el" is acceptable (see setEl). On render, If a renderTarget is found the Dataview injects its $el there via its renderMethod. This will happen only once as the Dataview then deletes the renderTarget from its model. If during its lifecycle the Dataview is removed from the renderTarget (or a new target is desired) simply set a renderTarget into the Dataview's model and it will place itself there on the next call to render.
If no renderTarget is present the Dataview assumes it is already in its intended location.
####renderMethod
Any legal jQuery manipulation method name (string). Defaults to "append" if not found.
####autoRender
The Dataview implements the observable extension and, if autoRender is present (and truthy), observes its own model. Any change (a set(s), unset(s) operation) to this class' model that is not in the autoRenderBlacklist will trigger a call to render.
#####autoRenderBlacklist
Some values, when set to a Dataview's model should not trigger an autoRender (even when autorender is set to true). These "keys" should be placed in the autoRenderBlacklist with a truthy value. Since Dataview implements the listener extension event and events are already included in the autoRenderBlacklist. Place any keys here (again, with a truthy value) that should repress an autoRender from occuring when set(s) and unset(s) type operations are called on this Dataview's model.
###render([change])
A method on the Dataview prototype that, when called, passes the Dataview's model data through its template - rehydrating the innerHTML of this.$el. This method is called automagically from:
- This object's addedToParent method (which is called from any container adding this object via addChild).
- This object's model when set(s) or unset(s) are called if autoRender is set to true.
render may be manually called at any time, returns this.
###addedToParent(parent)
Called from any container adding this object via addChild. Dataview simply returns this.render() from here.
###removeFromParent
An overridden version of the method of the same name on the View prototype. The Dataview implementation calls to the "super" then removes this.$el from the DOM.