Backbone Presenter
A model-presenter adapter for Backbone models.
For more information on how to customize your presenter, see the model-presenter README.
Example
var Backbone = ;; var PersonPresenter = BackbonePresenter var Person = BackboneModel var person = image: 'image.jpeg' username: 'createbang' firstName: 'Michael' lastName: 'Phillips' ssn: '111-11-1111' memberSince: '2013-01-01'; person // returns full representation of object including custom attributesperson // returns {image: 'image.jpeg', username: 'createbang', fullNameAllCaps: 'MICHAEL PHILLIPS'}person // returns all model data except ssn and adds fullName custom attributeperson // returns just the whitelisted keys
Installation
Extends the Backbone
global with the constructor Presenter
.
via npm
$ npm install backbone-presenter
Usage
Backbone Presenters are defined as an attribute on the applicable model and are bound to the model in the initialize method:
var Person = BackboneModel
serialize
Presenters call a method on the presenter class to convert the model into a raw JavaScript object, if one is defined. Backbone.Presenter defines the serialize method as the result of model.toJSON()
.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Running tests
npm installnpm test