var NotificationCenter = (() => {
var _Instance;
function getInstance() {
if (_Instance === undefined) {
_Instance = new cc.EventTarget();
}
return _Instance;
}
/**
* 注册消息通知
* @param {消息key} NotificationName
* @param {消息回调} callBack
* @param { Object The target (this object) to invoke the callback, if it's not given, only callback without target will be removed} target
*/
function on(NotificationName, callBack, target) {
this._Instance.on(NotificationName, callBack, target);
}
/**
* 关闭消息通知
* @param {消息key} NotificationName
* @param {消息回调} callBack
* @param { Object The target (this object) to invoke the callback, if it's not given, only callback without target will be removed} target
*/
function off(NotificationName, callBack, target) {
this._Instance.off(NotificationName, callBack, target);
}
/**
* 删除关闭 target 目标上的所有注册消息
* @param {注册消息目标} target
*/
function targetOff(target) {
this._Instance.targetOff(target);
}
/**
* 注册消息通知,只调用一次的消息注册,调用玩直接删除
* @param {消息key} NotificationName
* @param {消息回调} callBack
* @param { Object The target (this object) to invoke the callback, if it's not given, only callback without target will be removed} target
*/
function once(NotificationName, callBack, target) {
this._Instance.once(NotificationName, callBack, target);
}
/**
* 分发事件到事件流中
* 冒泡事件,事件会从当前节点,向父节点之上冒泡传递
* @param { Event The Event object that is dispatched into the event flow} event
*/
function dispatchEvent(event) {
this._Instance.dispatchEvent(event);
}
/**
* 发送消息通知
* @param {消息key} NotificationName
* @param {消息传递参数} options
*/
function emit(NotificationName, options) {
this._Instance.emit(NotificationName, options);
}
return {
getInstance: getInstance,
}
})();
module.exports = NotificationCenter;