diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /devtools/client/sourceeditor/tern/signal.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/client/sourceeditor/tern/signal.js')
-rwxr-xr-x | devtools/client/sourceeditor/tern/signal.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/devtools/client/sourceeditor/tern/signal.js b/devtools/client/sourceeditor/tern/signal.js new file mode 100755 index 000000000..5ea64a438 --- /dev/null +++ b/devtools/client/sourceeditor/tern/signal.js @@ -0,0 +1,51 @@ +(function(root, mod) { + if (typeof exports == "object" && typeof module == "object") // CommonJS + return mod(exports); + if (typeof define == "function" && define.amd) // AMD + return define(["exports"], mod); + mod((root.tern || (root.tern = {})).signal = {}); // Plain browser env +})(this, function(exports) { + + function on(type, f) { + var handlers = this._handlers || (this._handlers = Object.create(null)); + (handlers[type] || (handlers[type] = [])).push(f); + } + + function off(type, f) { + var arr = this._handlers && this._handlers[type]; + if (arr) for (var i = 0; i < arr.length; ++i) + if (arr[i] == f) { arr.splice(i, 1); break; } + } + + var noHandlers = [] + function getHandlers(emitter, type) { + var arr = emitter._handlers && emitter._handlers[type]; + return arr && arr.length ? arr.slice() : noHandlers + } + + function signal(type, a1, a2, a3, a4) { + var arr = getHandlers(this, type) + for (var i = 0; i < arr.length; ++i) arr[i].call(this, a1, a2, a3, a4) + } + + function signalReturnFirst(type, a1, a2, a3, a4) { + var arr = getHandlers(this, type) + for (var i = 0; i < arr.length; ++i) { + var result = arr[i].call(this, a1, a2, a3, a4) + if (result) return result + } + } + + function hasHandler(type) { + var arr = this._handlers && this._handlers[type] + return arr && arr.length > 0 && arr + } + + exports.mixin = function(obj) { + obj.on = on; obj.off = off; + obj.signal = signal; + obj.signalReturnFirst = signalReturnFirst; + obj.hasHandler = hasHandler; + return obj; + }; +}); |