diff options
author | portix <none@none> | 2012-04-18 12:42:49 +0200 |
---|---|---|
committer | portix <none@none> | 2012-04-18 12:42:49 +0200 |
commit | fdc89e8328b2386259ac53f619f497655b87783c (patch) | |
tree | 0b4f099cd4ac51686de14465131a2c9beed6c5c6 /scripts | |
parent | e9bb365b9be5f67d20c899af4e5a084daaad9670 (diff) | |
download | dwb-fdc89e8328b2386259ac53f619f497655b87783c.zip |
Return id from connect
--HG--
branch : scripts
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/signals.js | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/scripts/lib/signals.js b/scripts/lib/signals.js index b01b2361..74b8e31f 100644 --- a/scripts/lib/signals.js +++ b/scripts/lib/signals.js @@ -1,32 +1,44 @@ -Object.defineProperty(signals, "registered", { +Object.defineProperty(signals, "_registered", { value : {} }); +Object.defineProperty(signals, "_maxId", { + value : 0, + writable : true +}); Object.defineProperty(signals, "emit", { value : function(sig, wv, o) { - var sigs = signals.registered[sig]; + var sigs = signals._registered[sig]; for (var i=0; i<sigs.length; i++) { - sigs[i](wv, o); + sigs[i].callback(wv, o); } } }); Object.defineProperty(signals, "connect", { value : function(sig, func) { - var connected = signals.registered[sig] !== undefined && signals.registered[sig] !== null; - if (!connected) - signals.registered[sig] = []; - signals.registered[sig].push(func); - if (!connected) { + signals._maxId++; + io.print(signals._maxId); + if (signals._registered[sig] === undefined || signals._registered[sig] === null) { + signals._registered[sig] = []; signals[sig] = function (wv, o) { signals.emit(sig, wv, o); }; } + signals._registered[sig].push({callback : func, id : signals._maxId }); + return signals._maxId; } }); Object.defineProperty(signals, "disconnect", { - value : function(sig, func) { - var sigs = signals.registered[sig]; - if (sigs) - delete sigs.splice(sigs.indexOf(func), 1); + value : function(id) { + var s, i, a; + for (s in signals._registered) { + a = signals._registered[s]; + for (i = 0; i<a.length; i++) { + if (a[i].id == id) { + delete a.splice(i, 1); + } + } + } } }); +io.print("a :" + a); |