From 73e4adf3a8f69b965e4b5e56b039ad5334ec6956 Mon Sep 17 00:00:00 2001 From: portix Date: Sun, 24 Feb 2013 23:57:59 +0100 Subject: Remove signals.disconnectByFunction; block disconnection of signals during emission --- scripts/lib/signals.js | 54 +++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 23 deletions(-) (limited to 'scripts/lib/signals.js') diff --git a/scripts/lib/signals.js b/scripts/lib/signals.js index a89b1f14..25eebede 100644 --- a/scripts/lib/signals.js +++ b/scripts/lib/signals.js @@ -1,6 +1,8 @@ (function () { var _registered = {}; + var _blocked = false; + var _pending = []; function _disconnect(sig) { signals[sig] = null; @@ -9,6 +11,11 @@ var _disconnectByProp = function(prop, obj) { var sig, i, sigs; + if (_blocked) + { + _pending.push({prop : prop, obj : obj}); + return; + } for (sig in _registered) { sigs = _registered[sig]; @@ -22,13 +29,12 @@ } else { - sigs[i].connected = false; + sigs.splice(i, 1); } - return true; + return; } } } - return false; }; Object.defineProperties(signals, { @@ -37,24 +43,24 @@ value : function(sig, args) { var sigs = _registered[sig]; + var currentSig, pending; var ret = false; - var i = 0, l=sigs.length; - do + var i, l; + _blocked = true; + for (i=0, l=sigs.length; i 0) + { + for (i=_pending.length-1; i>=0; --i) { - sigs.splice(i, 1); + pending = _pending[i]; + _disconnectByProp(pending.prop, pending.obj); } - } while (i