mirror of
https://github.com/thepaperpilot/Planar-Pioneers.git
synced 2024-11-29 19:35:31 +00:00
1 line
968 B
JavaScript
1 line
968 B
JavaScript
var c=function(r){v(r);var e=l(r);return r.on=e.on,r.off=e.off,r.fire=e.fire,r};function l(n){var r=Object.create(null);return{on:function(e,t,o){if(typeof t!="function")throw new Error("callback is expected to be a function");var f=r[e];return f||(f=r[e]=[]),f.push({callback:t,ctx:o}),n},off:function(e,t){var o=typeof e=="undefined";if(o)return r=Object.create(null),n;if(r[e]){var f=typeof t!="function";if(f)delete r[e];else for(var a=r[e],i=0;i<a.length;++i)a[i].callback===t&&a.splice(i,1)}return n},fire:function(e){var t=r[e];if(!t)return n;var o;arguments.length>1&&(o=Array.prototype.splice.call(arguments,1));for(var f=0;f<t.length;++f){var a=t[f];a.callback.apply(a.ctx,o)}return n}}}function v(n){if(!n)throw new Error("Eventify cannot use falsy object as events subject");for(var r=["on","fire","off"],e=0;e<r.length;++e)if(n.hasOwnProperty(r[e]))throw new Error("Subject cannot be eventified, since it already has property '"+r[e]+"'")}export{c as n};
|