cryptalk/public/js/cryptalk_modules/mediator.js

2 lines
441 B
JavaScript
Raw Normal View History

2014-09-23 09:04:12 -04:00
define(function(){function f(d,a,b){var c=e[d],g=c.length,h=g,f=h,k=[],l=b?function(a){a&&k.push(a);!--h&&b(k,g)}:m;if(c)for(;d=c[--f];)d[1](a,l),2>d[1].length&&h--;else b&&b(k,g)}var l=0,e={},m=function(){};return function(){var d=l++;return{emit:function(a,b,c){f(a,b,c);return this},on:function(a,b){(e[a]||(e[a]=[])).push([d,b]);return this},off:function(a){var b=0,c=e[a];if(c)for(;a=c[b++];)a[0]===d&&c.splice(--b,1);return this}}}});