Skip to content

Instantly share code, notes, and snippets.

@A
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save A/1b8a992635bfb305d67f to your computer and use it in GitHub Desktop.

Select an option

Save A/1b8a992635bfb305d67f to your computer and use it in GitHub Desktop.
var Dispatcher = require('dispatcher');
module.exports = class View extends Backbone.View {
constructor(...args) {
this.dispatcher = dispatcher.bind(this); // Why?
super(...args);
}
save() {
return co.call(this, function * () {
yield this.dispatcher('before save');
super.save();
yield this.dispatcher('after save');
});
}
};
var Dispatcher = require('dispatcher');
module.exports = class View extends Backbone.View {
constructor(...args) {
this.hooks = {}; // for debug?
this.dispatcher = new Dispatcher(this.hooks); // optional hooks?
}
save(...args) {
return co.call(this, function * () {
yield this.dispatcher.before('save');
var result = super.save();
yield this.dispatcher.after('save');
retur result;
});
}
};
// Questions:
// - Strong order?
// - Globs
// - Support async?
var Dispatcher = require('dispatcher');
module.exports = class View extends Backbone.View {
constructor(...args) {
this.dispatcher = new Dispatcher();
this.dispatcher.hooks; // useful to debug?
}
save(...args) {
return co.call(this, function * () {
yield this.dispatcher.get('save:before');
var result = super.save();
yield this.dispatcher.get('save:after');
// yield this.dispatcher.get('save:*');
retur result;
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment