Package Exports
- sails-backbone
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sails-backbone) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
-backbone
Generate client-side Backbone.js Models from a Sails.js API. Uses Backbone Relational to generate relations, and implements validation rules using Anchor, the same library used to validate Sails.js/Waterline Models and Attributes.
Install
$ npm install sails-backbone --saveUsage
Sails.js (Server)
Example Model
// Automobile.js
module.exports = {
attributes: {
name: {
type: 'string',
alphanum: true,
primaryKey: true
},
color: {
type: 'string',
enum: [ 'black', 'black' ]
}
}
};
// Truck.js
_.merge(module.exports, require('./Automobile'), {
extend: 'Automobile',
attributes: {
bedlength: {
type: 'integer'
}
}
};
Controller
var SailsBackbone = require('sails-backbone');
var schema = SailsBackbone.generate(sails);
res.json(schema);Browser (Client)
var app = { };
app.models = SailsBackbone.parse(schema);
Backbone.Relational.store.addModelScope(app.models);Translated into Backbone:
app.models..Automobile = Backbone.RelationalModel.extend({
idAttribute: 'name',
urlRoot: 'http://example.com/automobile',
validations: {
name: {
alphanum: true
}
}
});
app.models.Truck = app.models.Automobile.extend({
idAttribute: 'name',
urlRoot: 'http://example.com/truck',
validations: {
name: {
alphanum: true
},
bedlength: {
integer: true
}
}
});License
MIT