summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorportix <none@none>2013-02-24 23:57:59 +0100
committerportix <none@none>2013-02-24 23:57:59 +0100
commit73e4adf3a8f69b965e4b5e56b039ad5334ec6956 (patch)
tree449e465829b3b88c3554f66b23c1debfc83ac6ab /scripts
parent03d9f2c8ccc10184f1be5eb2e78b69776fd51c7d (diff)
downloaddwb-73e4adf3a8f69b965e4b5e56b039ad5334ec6956.zip
Remove signals.disconnectByFunction; block disconnection of signals during emission
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lib/signals.js54
1 files changed, 31 insertions, 23 deletions
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<l; i++)
{
- if (sigs[i].connected)
- {
- ret = sigs[i].callback.apply(sigs[i].callback, args) || ret;
- i++;
- }
- else
+ currentSig = sigs[i];
+ ret = currentSig.callback.apply(currentSig.callback, args) || ret;
+ }
+ _blocked = false;
+ if (_pending.length > 0)
+ {
+ for (i=_pending.length-1; i>=0; --i)
{
- sigs.splice(i, 1);
+ pending = _pending[i];
+ _disconnectByProp(pending.prop, pending.obj);
}
- } while (i<l);
-
- if (_registered[sig].length === 0)
- {
- _disconnect(sig);
+ _pending = [];
}
return ret;
}
@@ -76,7 +82,7 @@
_registered[sig] = [];
signals[sig] = function () { return signals.emit(sig, arguments); };
}
- _registered[sig].push({callback : func, id : id, connected : true });
+ _registered[sig].push({ callback : func, id : id });
return id;
};
})()
@@ -92,12 +98,14 @@
},
"disconnect" :
{
- value : _disconnectByProp.bind(null, "id")
+ value : function(obj) {
+ if (typeof obj == "function")
+ _disconnectByProp("callback", obj);
+ else
+ _disconnectByProp("id", obj);
+
+ }
},
- "disconnectByFunction" :
- {
- value : _disconnectByProp.bind(null, "callback")
- },
"disconnectByName" :
{
value : function (name)