backbone.base
v0.0.8
Published
Essential Backbone View lifecycle management and base components
Downloads
15
Readme
Backbone.base
Backbone.base is a collection of helper classes and common logic useful when developing backbone applications. Specifically, this project contains:
- BaseView
- BaseModel
How to use it
Install the library via NPM (you'll need browserify or wrapup in order to compile the final JS for the browser in your build process):
npm install backbone.base
Simply require backbone.base into your files. you'll get an aggregate object containing:
Using Backbone.base.View
The view class exported by backbone.base will give you automatic subview lifecycle management. The view class automatically listen to changes in the model and renders; When instanced, the class can be provided with a 'model' or 'collection' attribute and will render (and listen for changes) accordingly; if both 'model' and 'collection' properties are provided, the view will listen for both of them. The class exports also the following 'hooks' functions:
- serialize() : json
- augmentViewModel(json) : json
The base view class provides also a few useful functions:
- renderSubviews
- setSubview(name, selector, view)
- getSubview(name)
- storeSubview(name, view)
lifecycle functions
The following hooks are automatically called if defined in your view extending Backbone.base.View :
- beforeRender
Internal functions not normally used by the developer (but still available if necessary) are:
- cleanSubview(name)
- cleanSubviews