Skip to content

Instantly share code, notes, and snippets.

@justinvdm
Created September 10, 2014 07:50
Show Gist options
  • Save justinvdm/804e5444845ffae10066 to your computer and use it in GitHub Desktop.
Save justinvdm/804e5444845ffae10066 to your computer and use it in GitHub Desktop.
var Event = vumigo.events.Event;
var BaseApp = App.extend(function(self) {
App.call(self, 'states:start');
self.states.add('states:start', function(name) {
// a bit of a yucky way of doing events, wish we opted for a more
// nodejs like approach (.emit('foo', {bar: 'baz'}))
// .emit returns a promise
return self
.emit(new Event('foo', {bar: 'baz'}))
.thenResolve(new EndState(name, {text: 'ham'}));
});
});
var AppA = App.extend(function(self) {
BaseApp.call(self);
// one way of listening to events
self.init = function() {
self.on('foo', function(e) {
// you can return a promise here
console.log(e); // => {bar: 'baz'}
});
};
});
var AppB = App.extend(function(self) {
BaseApp.call(self);
// different way of listening to events
self.events = {
'foo': function(e) {
// you can return a promise here
console.log(e); // => {bar: 'baz'}
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment