Skip to content

Instantly share code, notes, and snippets.

@sebslomski
Last active December 18, 2015 22:59
Show Gist options
  • Select an option

  • Save sebslomski/5858045 to your computer and use it in GitHub Desktop.

Select an option

Save sebslomski/5858045 to your computer and use it in GitHub Desktop.
var Model = Backbone.Model.extend({
listener: 'guy',
initialize: function() {
if (this.id) {
this.listenTo(
App.vent,
'model:' + this.listener + ':' + this.id + ':changed',
this.onChange
);
}
},
onChange: function(id, cid, data) {
if (this.cid !== cid && this.id === id) {
this.set(data, {propagate: false);
}
},
set: function(data, options) {
Backbone.Model.prototype.set.apply(this);
if (options.propagate !== false) {
App.vent.trigger(
'model:' + this.listener + ':changed',
this.id,
this.cid,
this.toJSON()
);
}
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment