UNPKG

emmiter

Version:
2 lines (1 loc) 7.09 kB
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.Emmiter=t()}}(function(){var t;return function e(t,n,r){function o(s,u){if(!n[s]){if(!t[s]){var f="function"==typeof require&&require;if(!u&&f)return f(s,!0);if(i)return i(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var a=n[s]={exports:{}};t[s][0].call(a.exports,function(e){var n=t[s][1][e];return o(n?n:e)},a,a.exports,e,t,n,r)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;s<r.length;s++)o(r[s]);return o}({1:[function(t,e,n){"use strict";var r=Object.prototype.hasOwnProperty,o=Object.prototype.toString,i=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===o.call(t)},s=function(t){if(!t||"[object Object]"!==o.call(t))return!1;var e=r.call(t,"constructor"),n=t.constructor&&t.constructor.prototype&&r.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!e&&!n)return!1;var i;for(i in t);return"undefined"==typeof i||r.call(t,i)};e.exports=function u(){var t,e,n,r,o,f,c=arguments[0],a=1,p=arguments.length,l=!1;for("boolean"==typeof c?(l=c,c=arguments[1]||{},a=2):("object"!=typeof c&&"function"!=typeof c||null==c)&&(c={});p>a;++a)if(t=arguments[a],null!=t)for(e in t)n=c[e],r=t[e],c!==r&&(l&&r&&(s(r)||(o=i(r)))?(o?(o=!1,f=n&&i(n)?n:[]):f=n&&s(n)?n:{},c[e]=u(l,f,r)):"undefined"!=typeof r&&(c[e]=r));return c}},{}],2:[function(t,e,n){var r={}.toString;e.exports=Array.isArray||function(t){return"[object Array]"==r.call(t)}},{}],3:[function(t,e,n){var r=function(t){var e={};return t&&"[object Function]"===e.toString.call(t)};"undefined"!=typeof e&&e.exports&&(e.exports=r)},{}],4:[function(t,e,n){"use strict";var r=t("isarray");e.exports=function(t){return null!=t&&"object"==typeof t&&!r(t)}},{isarray:5}],5:[function(t,e,n){e.exports=Array.isArray||function(t){return"[object Array]"==Object.prototype.toString.call(t)}},{}],6:[function(e,n,r){!function(r,o){"use strict";function i(){return 9007199254740991===c?0:++c}var s="object"==typeof window&&window||"object"==typeof global&&global||"object"==typeof self&&self||r,u="function"==typeof setImmediate,f="object"==typeof process&&!!process&&"function"==typeof process.nextTick,c=0,a=function(){var t,e,n,r;if(s.MutationObserver)return function(e){t=document.createElement("div"),new MutationObserver(function(){e(),t=null}).observe(t,{attributes:!0}),t.setAttribute("i","1")};if(!u&&s.postMessage&&!s.importScripts&&s.addEventListener){var o="com.setImmediate"+Math.random();r={};var c=function(t){if(t.source===s&&0===t.data.indexOf(o)){var e=t.data.split(":")[1];r[e](),delete r[e]}};return s.addEventListener("message",c,!1),function(t){var e=i();r[e]=t,s.postMessage(o+":"+e,"*")}}return!u&&s.document&&"onreadystatechange"in document.createElement("script")?function(t){e=document.createElement("script"),e.onreadystatechange=function(){e.onreadystatechange=null,e.parentNode.removeChild(e),e=null,t()},document.body.appendChild(e)}:(n=u&&setImmediate||f&&process.nextTick||setTimeout,function(t){n(t)})}();"undefined"!=typeof n&&n.exports?n.exports=a:"undefined"!=typeof e&&e.amd?t(function(){return a}):s.setAsap=a}(this)},{}],7:[function(t,e,n){e.exports=function(t,e,n){var r=[],o=t.length;if(0===o)return r;var i=0>e?Math.max(0,e+o):e||0;for(void 0!==n&&(o=0>n?n+o:n);o-- >i;)r[o-i]=t[o];return r}},{}],emmiter:[function(t,e,n){"use strict";var r=t("sliced"),o=t("extend"),i=t("isobject"),s=t("isarray"),u=t("isfunction"),f=t("setasap"),c=function(t){return"undefined"==typeof t};Array.prototype.some||(Array.prototype.some=function(t){if(null==this)throw new TypeError("Array.prototype.some called on null or undefined");if("function"!=typeof t)throw new TypeError;for(var e=Object(this),n=e.length>>>0,r=arguments.length>=2?arguments[1]:void 0,o=0;n>o;o++)if(o in e&&t.call(r,e[o],o,e))return!0;return!1});var a=function(t,e){if("string"!=typeof t||!t)throw Error("event should be string!");if(2===arguments.length&&"function"!=typeof e)throw Error("callback should be function!")},p=function l(t){return this instanceof l?this:i(t)?l.patch(t):new l};p.prototype.NS_SEPARATOR=function(t){return function(e){return"undefined"!=typeof e&&(t=e),t}}("."),p.prototype._isListener=function(t){return!c(t.event)&&!c(t.ns)&&!c(t.fn)},p.prototype._parseEventName=function(t){var e,n=null;return i(t)&&"undefined"!=typeof t.name&&"undefined"!=typeof t.ns?n=t:(e=t.split(this.NS_SEPARATOR()),n={name:e[0]||"",ns:e[1]||""}),n},p.prototype._buildEventName=function(t){return t=this._parseEventName(t),t.ns?[t.name,t.ns].join(this.NS_SEPARATOR()):t.name},p.prototype.getListeners=function(t,e,n){for(var r,o=arguments.length,i=r=new Array(o);o--;i[o]=arguments[o]);this.listeners=this.listeners||[],r.length<2?(e=null,n=!1):2==r.length?u(r[1])?(e=r[1],n=!1):(e=null,n=!!n):3==r.length&&(e=u(e)?e:null,n=!!n);var s=[],f=[],c=this.listeners;return(t||e)&&(s=this._parseListeners(t,e),f=c.filter(function(t){var r=s.some(function(n){return!(n.event&&n.event!=t.event||n.ns&&n.ns!=t.ns||u(e)&&e!=t.fn)});return n?!r:r}),c=f),c},p.prototype._parseListeners=function(t,e){e=u(e)?e:null;var n=[],r=this;if(i(t))if(this._isListener(t))n.push(t);else for(var o in t)t.hasOwnProperty(o)&&(e=t[o],n=n.concat(this._parseListeners(o,e)));else s(t)?t.forEach(function(t){n=n.concat(r._parseListeners(t,e))}):"string"==typeof t?(t=t.split(" "),t.length>1?n=n.concat(this._parseListeners(t,e)):(o=this._parseEventName(t[0]),n.push({event:o.name,ns:o.ns,fn:e}))):e&&n.push({event:"",ns:"",fn:e});return n},p.prototype.addListener=p.prototype.bind=p.prototype.on=function(t,e){return e=u(e)?e:null,this.listeners=this.getListeners().concat(this._parseListeners(t,e)),this},p.prototype.once=p.prototype.one=function(t,e){a(t,e);var n=this;return n.on(t,function r(){e(),n.off(t,r)}),this},p.prototype.removeListener=p.prototype.unbind=p.prototype.off=function(t,e){return e=u(e)?e:null,this.listeners=this.getListeners(t,e,!0),this},p.prototype.triggerAsync=p.prototype.emitAsync=function(t){for(var e,n=this,r=arguments.length,o=e=new Array(r);r--;o[r]=arguments[r]);return f(function(){n._emit.apply(n,e)}),this},p.prototype.trigger=p.prototype.emit=function(t){for(var e,n=arguments.length,r=e=new Array(n);n--;r[n]=arguments[n]);return this._emit.apply(this,e),this},p.prototype._emit=function(t,e){for(var n,o=this,i=[],s=arguments.length,u=n=new Array(s);s--;u[s]=arguments[s]);return n=r(n,1),this.getListeners(t).forEach(function(t){i.push(t.fn.apply(o,n))}),this._returnListenersResults?i:this},p.prototype.returnListenersResults=function(t){this._returnListenersResults=!!t},p.extend=p.patch=function(t){return o(t,p.prototype)},p.create=function(){return new p},p.destroy=function(t){Object.keys(p.prototype).forEach(function(e){delete t[e]})},e.exports=p},{extend:1,isarray:2,isfunction:3,isobject:4,setasap:6,sliced:7}]},{},["emmiter"])("emmiter")});