JSFiddle - React, Tailwind, and code Playground
by nikoshr
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.2.3/backbone-min.js"></script>
JavaScript
var aggregate = _.extend({}, Backbone.Events);
aggregate.register = function(m) {
var self = this;
this.listenTo(m, 'all', function() {
this.trigger.apply(this, arguments);
});
};
aggregate.on('change', function(m) {
// do what you have to do when one of the models change
console.log('Change on ', m.toJSON());
});
aggregate.on('sync', function(m) {
console.log('sync ', m.toJSON());
});
var m1 = new Backbone.Model({id: 1});
m1.url = '/echo/json/';
var m2 = new Backbone.Model({id: 2});
aggregate.register(m1);
aggregate.register(m2);
m1.fetch();
m2.set({data: 2});