@kilt/azazel
Version:
simple javascript events handler
1 lines • 2.4 kB
JavaScript
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):n.Azazel=t()}(this,function(){"use strict";var p=function(){if("object"==typeof process&&process&&"function"==typeof process.nextTick)return process.nextTick;if("MutationObserver"in window||"WebKitMutationObserver"in window)return function(n,t){var e=[],i=0;function o(){t.data=i=++i%2}return new n(function(){var n=e.shift();0<e.length&&o(),n instanceof Function&&n()}).observe(t,{characterData:!0}),function(n){e.push(n),o()}}(window.MutationObserver||window.WebKitMutationObserver,document.createTextNode(""));var t=function(n){if("function"!=typeof n)throw new TypeError(n+" is not a Function");return n};return"function"==typeof setImmediate?function(n){setImmediate(t(n))}:"function"==typeof setTimeout||"object"==typeof setTimeout?function(n){setTimeout(t(n),0)}:void 0}(),h=function(n){n.apply(this,arguments)};function l(n,t){if(n)for(var e=n.length-1;0<=e;e--)t===n[e]&&n.splice(e,1)}function d(o,r,f){return function t(n,e,i){if(!1!==f&&!(e instanceof Function))throw new Error("listener should be a Function");if(n instanceof Array)return n.forEach(function(n){t(n,e,i)}),r;if("string"!=typeof n)throw new Error("event_name should be a string");return/ /.test(n)?t(n.split(/ +/),e,i):(o.apply(this,arguments),r)}}function v(o,n){"string"==typeof(n=n||{})&&(n={prefix:n}),n.prefix=n.prefix||"",o=o||(this instanceof v?this:{});var r={},f={},c={},u=!1!==n.async?p:h;function s(n,t,e){r[n]=r[n]||[],e?r[n].unshift(t):r[n].push(t)}var t=d(s,o);function a(n,t,e){f[n]=f[n]||[],e?f[n].unshift(t):f[n].push(t)}var e=d(a,o);var i=d(function(t,e,i,o){i instanceof Function&&(o=i,i=null),u(function(){e=e||[],c[t]={args:e,this_arg:i};var n=r[t]&&r[t].slice();n&&n.forEach(function(n){n.apply(i,e)}),function(t,e,i){var n=f[t]&&f[t].slice();if(delete f[t],n)for(var t in n.forEach(function(n){n.apply(i,e)}),f)n.forEach(function(n){f[t]&&l(f[t],n)})}(t,e,i),o instanceof Function&&o.apply(i,e)})},o,!1);return o[n.prefix+"on"]=t,o[n.prefix+"once"]=e,o[n.prefix+"watch"]=function(n,t,e){if(!(t instanceof Function))throw new Error("listener should be a Function");"once"!==e&&s(n,t,e);var i=c[n];return i?t.apply(i.this_arg,i.args):"once"===e&&a(n,t),o},o[n.prefix+"emit"]=i,o[n.prefix+"off"]=d(function(n,t){r[n]&&l(r[n],t),f[n]&&l(f[n],t)}),o}return v.nextTick=p,v});