Last active
August 29, 2015 14:14
-
-
Save A/1b8a992635bfb305d67f to your computer and use it in GitHub Desktop.
Trying to achieve es6-dispatcher API https://github.com/rambler-digital-solutions/es6-dispatcher
This file contains hidden or 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 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'); | |
| }); | |
| } | |
| }; |
This file contains hidden or 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 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; | |
| }); | |
| } | |
| }; |
This file contains hidden or 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
| // 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