-
Notifications
You must be signed in to change notification settings - Fork 0
/
signals.min.js
1 lines (1 loc) · 1.63 KB
/
signals.min.js
1
var signals=function(h,d){"use strict";var a=[],k,i,f,c,n,m,e,l="function",g,j,b;g=function(c,a,b){if(typeof c!==a)throw b||"Invalid argument.";};k=function(e){var b=c(e);if(a[b]===d)a[b]=[]};i=function(k,b,i){var f=c(k),d=0,j,e;if(b instanceof Array){j=b.length;for(d;d<j;d++){e=b[d];g(e,l,"Callback must be a function");a[f].push({callback:e,obj:i||h})}}else{g(b,l,"Callback must be a function");a[f].push({callback:b,obj:i||h})}};j=function(a){return function(b){f("broadcast",a,b)}};f=function(k,j,l){var e=c(j),h=a[e+":before"],g=a[e],i=a[e+":after"],f;if(g===d)return;f=k==="broadcast"?n:m;b.init(h,g,i).run(f,l)};b=function(b,c,d){var a=this;a.processed=0;a.beforeActions=b;a.actions=c;a.afterActions=d;a.processTotal=c.length+(b?b.length:0);return a};b.init=function(a,d,c){return new b(a,d,c)};b.fn=b.prototype;b.fn.run=function(c,d){var a=this,b;a.args=d;a.takeAction=c;b=function(){a.track()};a.beforeActions&&e(a.beforeActions,c,d,b);e(a.actions,c,d,b)};b.fn.track=function(){var a=this;a.processed++;if(a.processTotal!==a.processed)return a;a.afterActions&&e(a.afterActions,a.takeAction,a.args,function(){})};e=function(b,f,d,c,a){a=a||0;f(b[a],d,b,a);c();a++;a<b.length&&h.setTimeout(function(){e(b,f,d,c,a)},10)};n=function(a,b){var c=a.obj,d=a.callback;d.call(c,b)};m=function(a,c,b,e){a!==d&&a.callback===c&&b.splice(e,1)};c=function(a){return a||"any"};return{subscribe:function(a,b,c){k(a);i(a,b,c)},broadcast:function(a,b){f("broadcast",a,b)},proxy:function(a){return j(a)},unsubscribe:function(a,b){f("unsubscribe",a,b)},isObservable:function(b){var e=c(b);return a[e]!==d},listenerCount:function(e){var f=c(e),b=a[f];return b!==d?b.length:0}}}(this)