-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
caijf
committed
Jun 8, 2017
1 parent
90f5957
commit 7141466
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* ------------------------------------------ | ||
* 消息总线实现文件 | ||
* @version 1.0 | ||
* @author genify(caijf@corp.netease.com) | ||
* ------------------------------------------ | ||
*/ | ||
/** @module util/event/esb */ | ||
NEJ.define([ | ||
'base/klass', | ||
'util/event' | ||
],function( | ||
k, t, | ||
exports, pro | ||
){ | ||
/** | ||
* 消息总线 | ||
* | ||
* 脚本举例 | ||
* ```javascript | ||
* NEJ.define([ | ||
* 'util/event/esb' | ||
* ],function(esb){ | ||
* // 添加事件,新加的事件不会覆盖原同名事件 | ||
* esb._$addEvent( | ||
* 'onxxx', function(event){ | ||
* // TODO | ||
* // 阻止后续逻辑 | ||
* // esb._$stop(event); | ||
* // 判断事件是否被阻止 | ||
* // esb._$isStopped(event); | ||
* } | ||
* ); | ||
* // 设置事件,新加的事件覆盖原同名事件 | ||
* esb._$setEvent( | ||
* 'onxxx', function(event){ | ||
* // TODO | ||
* } | ||
* ); | ||
* // 删除事件,注意这里的 eventHandler 引用必须跟添加时一致 | ||
* esb._$delEvent( | ||
* 'onxxx', eventHandler | ||
* ); | ||
* // 调度事件 | ||
* esb._$dispatchEvent( | ||
* 'onxxx',{ | ||
* a:'aaaa', | ||
* b:'bbbbb' | ||
* } | ||
* ) | ||
* }); | ||
* ``` | ||
* | ||
* @class module:util/event/esb.ESB | ||
* @extends module:util/event/esb._$$EventTarget | ||
* | ||
* @param {Object} config - 可选配置参数 | ||
*/ | ||
var ESB = k._$klass(); | ||
pro = ESB._$extend(t._$$EventTarget); | ||
|
||
/** | ||
* 阻止事件 | ||
* | ||
* @method module:util/event/esb.ESB#_$isStopped | ||
* @param {String} arg0 - 事件对象 | ||
* @return {Void} | ||
*/ | ||
pro._$stop = function(event){ | ||
(event||{}).__stopped__ = !0; | ||
}; | ||
|
||
/** | ||
* 判断事件是否被阻止 | ||
* | ||
* @method module:util/event/esb.ESB#_$isStopped | ||
* @param {String} arg0 - 事件对象 | ||
* @return {Void} | ||
*/ | ||
pro._$isStopped = function(event){ | ||
return !!(event||{}).__stopped__; | ||
}; | ||
|
||
// return esb instance | ||
return ESB._$allocate(); | ||
}); |