This package describes light version of the Backbone.Model. You can use this component when you doesn't need the Backbone.Model attributes functionality like model.set() or model.get() methods and change events. But this component have all Backbone.Events functionality.
This component have a properties-assign logic. This means, that when you create the component, you can pass object with properties in first constructor argument. Look at the usage example below.
You can find this code in sample folder.
'use strict';
const Component = require('backbone.component');
const Person = Component.extend({
name: null
});
const Man = Person;
const Woman = Person.extend({
want(target) {
this.trigger('want', target);
}
});
let john = new Man({name: 'John'});
let kate = new Woman({name: 'Kate'});
john.listenTo(kate, 'want', target => {
console.log(`${kate.name}, ${target} is really expensive!`);
});
kate.want('car');
Also you can run this code from console from your project folder.
node ./node_modules/backbone.component/sample/index.js
Run this code from your project root folder.
npm i backbone.component --save-dev