From 0f4f742c80e485128e4bc7c8b0949fb40dcf97b1 Mon Sep 17 00:00:00 2001 From: Greg Wang Date: Wed, 14 Nov 2018 20:25:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=AD=A3=E5=B8=B8=E5=A4=84=E7=90=86?= =?UTF-8?q?=E5=BC=82=E6=AD=A5event=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cocos2d/core/event/event-target.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/cocos2d/core/event/event-target.js b/cocos2d/core/event/event-target.js index 03298b9a9f4..ed4ea66ee3c 100644 --- a/cocos2d/core/event/event-target.js +++ b/cocos2d/core/event/event-target.js @@ -149,7 +149,7 @@ var proto = EventTarget.prototype; proto._addEventFlag = function (type, listeners, useCapture) { var cache = this._hasListenerCache; - + if (!cache) { cache = this._hasListenerCache = cc.js.createMap(); } @@ -157,14 +157,14 @@ proto._addEventFlag = function (type, listeners, useCapture) { if (cache[type] === undefined) { cache[type] = 0; } - + var flag = useCapture ? CAPTURING_FLAG : BUBBLING_FLAG; cache[type] |= flag; }; proto._purgeEventFlag = function (type, listeners, useCapture) { var cache = this._hasListenerCache; - + if (!cache || listeners.has(type)) { return; } @@ -182,7 +182,7 @@ proto._resetFlagForTarget = function (target, listeners, useCapture) { if (!cache) { return; } - + var flag = useCapture ? CAPTURING_FLAG : BUBBLING_FLAG; for (var key in cache) { if (!listeners.has(key)) { @@ -319,7 +319,7 @@ proto.off = function (type, callback, target, useCapture) { this._purgeEventFlag(type, listeners, useCapture); } - + } }; @@ -434,16 +434,24 @@ proto.emit = function (message, detail) { event.eventPhase = 2; event.target = event.currentTarget = this; + var res; var capturingListeners = this._capturingListeners; if (capturingListeners && (flag & CAPTURING_FLAG)) { - capturingListeners.invoke(event); + res = capturingListeners.invoke(event); } var bubblingListeners = this._bubblingListeners; if (bubblingListeners && (flag & BUBBLING_FLAG) && !event._propagationImmediateStopped) { - bubblingListeners.invoke(event); + res = bubblingListeners.invoke(event); + } + if (typeof res.finally === 'function') { + res.finally(function() { + event.detail = null; + cc.Event.EventCustom.put(event); + }); + } else { + event.detail = null; + cc.Event.EventCustom.put(event); } - event.detail = null; - cc.Event.EventCustom.put(event); }; /* From 2c93ee94ecb3af2e3d4ae9ceb10d1d3820e103b0 Mon Sep 17 00:00:00 2001 From: Greg Wang Date: Wed, 14 Nov 2018 20:26:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=A1=AE=E4=BF=9Dres=E4=B8=8D=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cocos2d/core/event/event-target.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/event/event-target.js b/cocos2d/core/event/event-target.js index ed4ea66ee3c..b9ce267e9d1 100644 --- a/cocos2d/core/event/event-target.js +++ b/cocos2d/core/event/event-target.js @@ -443,7 +443,7 @@ proto.emit = function (message, detail) { if (bubblingListeners && (flag & BUBBLING_FLAG) && !event._propagationImmediateStopped) { res = bubblingListeners.invoke(event); } - if (typeof res.finally === 'function') { + if (res && typeof res.finally === 'function') { res.finally(function() { event.detail = null; cc.Event.EventCustom.put(event);