Backbone Nesty
Support nested data types like collections and models within your Backbone.js models
Install
npm install --save backbone-nesty
require('backbone-nesty')
npm install --save backbone-nesty
require('backbone-nesty')
//wzrd.in/bundle/backbone-nesty@2.0.0
ender add backbone-nesty
require('backbone-nesty')
Editions
This package is published with the following editions:
backbone-nesty
aliasesbackbone-nesty/index.js
which uses Editions to automatically select the correct edition for the consumers environmentbackbone-nesty/source/index.coffee
is Source + CoffeeScript + Requirebackbone-nesty/esnext/index.js
is CoffeeScript Compiled + ESNext + Requirebackbone-nesty/es2015/index.js
is CoffeeScript Compiled + ES2015 + Require
Older environments may need Babel's Polyfill or something similar.
Usage
Example
// Importvar Backbone = ;var BackboneNestyModel = BackboneNestyModel;// Eye Modelvar EyeModel = BackboneModel;// Eye Collectionvar EyeCollection = BackboneCollection;// Mouth Modelvar MouthModel = BackboneModel;// Head Modelvar HeadModel = BackboneNestyModel;// Instantiate our head with our nested datavar myHead =// will create a mouth model with this datamouth:open: true// will create an eyes collection with this dataeyes:// will create an eye model with this dataid: 'left'color: 'green'open: true// will create an eye model with this dataid: 'right'color: 'green'open: true;// Checkconsole;console; // true// ^ equiv to myHeader.get('eyes').get('left').get('open')// Nested SettermyHead;// ^ equiv to myHeader.get('eyes').get('right').set('open', false)// Checkconsole;console; // false
BackboneNestyModel API
require('backbone-nesty').BackboneNestyModel
is an extended Backbone.js Model that adds the following functionality:
- properties
collections
defaults to{}
, an object which keys are the attributes and values are the collection data type for the attributemodels
defaults to{}
, an object which keys are the attributes and values are the model data type for the attributeembed
defaults to{}
, an object which keys are the attributes and values are boolean on whether or not we should embed the full data of this attribute when callingtoJSON
on the model or just an id listingstrict
defaults totrue
, a boolean for whether or not we should allow unknown attributes to be set on our model
- methods
toJSON()
will serialize the model and all nested data types as well, if the embed property for an nested data type is false, that value will be replaced with an id listing insteadget(key)
adds support for nested getsset(attrs,opts)
adds support for nested sets and will instantiate the value according to the nested data type if applicable
History
Discover the release history by heading on over to the HISTORY.md
file.
Contribute
Discover how you can contribute by heading on over to the CONTRIBUTING.md
file.
Backers
Maintainers
These amazing people are maintaining this project:
Sponsors
These amazing people have contributed finances to this project:
Become a sponsor!
Contributors
These amazing people have contributed code to this project:
Discover how you can contribute by heading on over to the CONTRIBUTING.md
file.
License
Unless stated otherwise all works are:
- Copyright © Bevry Pty Ltd
and licensed under: