3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.app.EventBus
19 * Class documentation for the MVC classes will be present before 4.0 final, in the mean time please refer to the MVC
22 Ext.define('Ext.app.EventBus', {
27 observable: 'Ext.util.Observable'
30 constructor: function() {
31 this.mixins.observable.constructor.call(this);
36 Ext.override(Ext.Component, {
37 fireEvent: function(ev) {
38 if (Ext.util.Observable.prototype.fireEvent.apply(this, arguments) !== false) {
39 return me.dispatch.call(me, ev, this, arguments);
46 dispatch: function(ev, target, args) {
49 selector, controllers, id, events, event, i, ln;
52 // Loop over all the selectors that are bound to this event
53 for (selector in selectors) {
54 // Check if the target matches the selector
55 if (target.is(selector)) {
56 // Loop over all the controllers that are bound to this selector
57 controllers = selectors[selector];
58 for (id in controllers) {
59 // Loop over all the events that are bound to this selector on this controller
60 events = controllers[id];
61 for (i = 0, ln = events.length; i < ln; i++) {
64 if (event.fire.apply(event, Array.prototype.slice.call(args, 1)) === false) {
74 control: function(selectors, listeners, controller) {
78 if (Ext.isString(selectors)) {
81 selectors[selector] = listeners;
82 this.control(selectors, null, controller);
86 Ext.Object.each(selectors, function(selector, listeners) {
87 Ext.Object.each(listeners, function(ev, listener) {
90 event = Ext.create('Ext.util.Event', controller, ev);
92 // Normalize the listener
93 if (Ext.isObject(listener)) {
95 listener = options.fn;
96 scope = options.scope || controller;
101 event.addListener(listener, scope, options);
103 // Create the bus tree if it is not there yet
104 bus[ev] = bus[ev] || {};
105 bus[ev][selector] = bus[ev][selector] || {};
106 bus[ev][selector][controller.id] = bus[ev][selector][controller.id] || [];
108 // Push our listener in our bus
109 bus[ev][selector][controller.id].push(event);