123 |
- /**
- * Created by n.atlas on 17/7/2015.
- */var cache={},callbackFun=function(a){if(cache[a])return cache[a];var b=99999,c={fns:{},checks:{},add:function(a,c,d,e){for(var f in"string"==typeof a&&(a=[a]),a)this.fns[a[f]]||(this.fns[a[f]]={}),d?this.fns[a[f]][d]=c:this.fns[a[f]][b++]=c,"function"==typeof e&&(this.checks[a[f]+d]=e)},remove:function(a,b){b?delete this.fns[a][b]:delete this.fns[a]},match:function(a){let b=[];for(let c in this.fns)for(let d in this.fns[c])a.match(new RegExp(d))&&b.push(this.fns[c][d]);for(let c in b)b[c].apply(null)},execute:function(a){for(var b=[],c=1;c<arguments.length;c++)b.push(arguments[c]);var d=[];for(var e in this.fns[a])d.push(e),this.fns[a][e].apply(null,b);return d},executeOnce:function(a){var b=this.execute(a);return this.remove(a),b},executeAndCheck:function(a){if(this.fns[a]){var b=this.execute(a);for(var c in this.fns[a])"function"==typeof this.checks[a+c]&&this.checks[a+c]()&&this.remove(a,c);return 0==Object.keys(this.fns[a])&&delete this.fns[a],b}},getKeys:function(){return Object.keys(this.fns)},dispose:function(){this.fns={}},length:function(){return Object.keys(this.fns).length}};return cache[a]=c,c};window.CallbackJS=callbackFun;export default callbackFun;
|