2 * @class Ext.app.EventBus
5 * Class documentation for the MVC classes will be present before 4.0 final, in the mean time please refer to the MVC
8 Ext.define('Ext.app.EventBus', {
13 observable: 'Ext.util.Observable'
16 constructor: function() {
17 this.mixins.observable.constructor.call(this);
22 Ext.override(Ext.Component, {
23 fireEvent: function(ev) {
24 if (Ext.util.Observable.prototype.fireEvent.apply(this, arguments) !== false) {
25 return me.dispatch.call(me, ev, this, arguments);
32 dispatch: function(ev, target, args) {
35 selector, controllers, id, events, event, i, ln;
38 // Loop over all the selectors that are bound to this event
39 for (selector in selectors) {
40 // Check if the target matches the selector
41 if (target.is(selector)) {
42 // Loop over all the controllers that are bound to this selector
43 controllers = selectors[selector];
44 for (id in controllers) {
45 // Loop over all the events that are bound to this selector on this controller
46 events = controllers[id];
47 for (i = 0, ln = events.length; i < ln; i++) {
50 return event.fire.apply(event, Array.prototype.slice.call(args, 1));
58 control: function(selectors, listeners, controller) {
62 if (Ext.isString(selectors)) {
65 selectors[selector] = listeners;
66 this.control(selectors, null, controller);
70 Ext.Object.each(selectors, function(selector, listeners) {
71 Ext.Object.each(listeners, function(ev, listener) {
74 event = Ext.create('Ext.util.Event', controller, ev);
76 // Normalize the listener
77 if (Ext.isObject(listener)) {
79 listener = options.fn;
80 scope = options.scope || controller;
85 event.addListener(listener, scope, options);
87 // Create the bus tree if it is not there yet
88 bus[ev] = bus[ev] || {};
89 bus[ev][selector] = bus[ev][selector] || {};
90 bus[ev][selector][controller.id] = bus[ev][selector][controller.id] || [];
92 // Push our listener in our bus
93 bus[ev][selector][controller.id].push(event);