Created
December 24, 2015 05:04
-
-
Save rek/269e395ab550ebdf582e to your computer and use it in GitHub Desktop.
Backbone model state system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var view = new View({ | |
state: state, // <- state | |
)}; | |
state.set({ | |
action: 'myFunction', | |
data: { | |
awesome: true | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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