fineui是帆软报表和BI产品线所使用的前端框架。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.0 KiB

8 years ago
/**
* 广播
*
* Created by GUY on 2015/12/23.
* @class
*/
BI.BroadcastController = BI.inherit(BI.Controller, {
init: function () {
8 years ago
this._broadcasts = {};
},
on: function (name, fn) {
8 years ago
var self = this;
8 years ago
if (!this._broadcasts[name]) {
this._broadcasts[name] = [];
}
this._broadcasts[name].push(fn);
8 years ago
return function () {
8 years ago
self.remove(name, fn);
7 years ago
};
8 years ago
},
send: function (name) {
var args = [].slice.call(arguments, 1);
BI.each(this._broadcasts[name], function (i, fn) {
fn.apply(null, args);
});
},
remove: function (name, fn) {
var self = this;
8 years ago
if (fn) {
BI.remove(this._broadcasts[name], function (index, cb) {
return fn === cb;
});
8 years ago
if (this._broadcasts[name].length === 0) {
delete this._broadcasts[name];
}
8 years ago
} else {
delete this._broadcasts[name];
}
return this;
}
});