[ALOY-1290] Provide a global event dispatcher as alternative for Ti.App.fireEvent
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | None |
Status | Open |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Runtime |
Labels | events |
Reporter | Fokke Zandbergen |
Assignee | Bruce Wayne |
Created | 2015-07-08T18:56:15.000+0000 |
Updated | 2015-07-08T18:56:15.000+0000 |
Description
I once wrote an article on tiDev titled _The case against Ti.App.fireEvent_:
http://www.tidev.io/2014/09/10/the-case-against-ti-app-fireevent-2/
In short: using
Ti.App.fireEvent
is bad because your listening to these events in JavaScript elsewhere so there's no need to cross the bridge, in particular with big payloads.
The alternative in Alloy is to simply use Backbone.Events to create a JS-only dispatcher. This as easy has:
Alloy.Events = _.extend({}, Backbone.Events);
Alloy.Events.on('myEvent', fn);
Alloy.Events.trigger('myEvent');
Since it is this easy.. why not add this to the Alloy library as another global object next to Alloy.CFG
and Alloy.Globals
.
No comments