Skip to content

Instantly share code, notes, and snippets.

@rek
Created December 24, 2015 05:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rek/269e395ab550ebdf582e to your computer and use it in GitHub Desktop.
Save rek/269e395ab550ebdf582e to your computer and use it in GitHub Desktop.
Backbone model state system
var view = new View({
state: state, // <- state
)};
state.set({
action: 'myFunction',
data: {
awesome: true
}
});
/*
* Is this ok, or approaching an anti-pattern?
*/
var View = Marionette.ItemView.extend({
initialize: function() {
var self = this;
// awesome state binding event system:
this.options.state.on('change', function(event) {
// console.log('Change caught', event);
if (_.isFunction(self[event.get('action')])) {
self[event.get('action')](event.get('data'));
}
});
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment