Comparing version 0.6.73 to 0.6.732
@@ -1,1 +0,1 @@ | ||
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){"use strict";var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();var _get=function get(_x,_x2,_x3){var _again=true;_function:while(_again){var object=_x,property=_x2,receiver=_x3;desc=parent=getter=undefined;_again=false;if(object===null)object=Function.prototype;var desc=Object.getOwnPropertyDescriptor(object,property);if(desc===undefined){var parent=Object.getPrototypeOf(object);if(parent===null){return undefined}else{_x=parent;_x2=property;_x3=receiver;_again=true;continue _function}}else if("value"in desc){return desc.value}else{var getter=desc.get;if(getter===undefined){return undefined}return getter.call(receiver)}}};function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass)}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass}var WolfyEventEmitter=require("wolfy87-eventemitter");console.log("jsLights test");var EventEmitter=function(_WolfyEventEmitter){_inherits(EventEmitter,_WolfyEventEmitter);function EventEmitter(){_classCallCheck(this,EventEmitter);_get(Object.getPrototypeOf(EventEmitter.prototype),"constructor",this).call(this);this._hooks={}}_createClass(EventEmitter,[{key:"addHook",value:function addHook(name,cb,options){if(!this._hooks[name]){this._hooks[name]=[]}var priority=options&&options.priority?options.priority:0;this._hooks[name].push({cb:cb,priority:priority});this._hooks[name]=this._hooks[name].sort(function(a,b){return b.priority-a.priority})}},{key:"callHooks",value:function callHooks(name,ref){if(this._hooks[name]){for(var i=0;i<this._hooks[name].length;i++){var hook=this._hooks[name][i];var returnHookVal=hook.cb(ref);if(returnHookVal){return returnHookVal}}}}},{key:"on",value:function on(evt,listener){_get(Object.getPrototypeOf(EventEmitter.prototype),"on",this).call(this,evt,listener);return{evt:evt,listener:listener}}},{key:"trigger",value:function trigger(evt,args){var arr=[];arr.push(args);args=arr;var toReturn=_get(Object.getPrototypeOf(EventEmitter.prototype),"trigger",this).call(this,evt,args);this._registerTrigger(evt);return toReturn}},{key:"unbind",value:function unbind(eventObj){if(!eventObj){return}_get(Object.getPrototypeOf(EventEmitter.prototype),"off",this).call(this,eventObj.evt,eventObj.listener)}},{key:"_registerTrigger",value:function _registerTrigger(evt){if(!this.jsLights){this.jsLights={}}if(!this.jsLights.triggered){this.jsLights.triggered={}}if(this.jsLights.triggered[evt]!==undefined){this.jsLights.triggered[evt]++}else{this.jsLights.triggered[evt]=1}}}]);return EventEmitter}(WolfyEventEmitter);var JsLights=function(_EventEmitter){_inherits(JsLights,_EventEmitter);function JsLights(){var _this=this;_classCallCheck(this,JsLights);_get(Object.getPrototypeOf(JsLights.prototype),"constructor",this).call(this);this.triggered=["EventEmitter","Base"];this._beforeDependency={};this._extendedClasses={};this._alias={};this._registered=new Set;if(document){if(document.body){this.triggered.push("onDocumentReady")}else{document.addEventListener("DOMContentLoaded",function(){_this._registerEvent("onDocumentReady")})}}}_createClass(JsLights,[{key:"assign",value:function assign(path,reference,dependency){var register=this.register(path,reference);register.after(dependency);register.assign();return register}},{key:"after",value:function after(_after,cb){var _this2=this;if(typeof cb!="function"){throw new Error("invalid callback function")}if(!Array.isArray(_after)){_after=[_after]}var passed=0;_after.forEach(function(dependency){if(_this2.triggered.indexOf(dependency)!=-1)passed++});if(passed==_after.length){cb();delete cb.jsLights;return}if(!cb.jsLights)cb.jsLights={};if(!cb.jsLights._listeningFor)cb.jsLights._listeningFor=new Set;_after.forEach(function(dependency){if(!cb.jsLights._startedDepCheck&&dependency.indexOf("->")!=-1){var eventsArr=dependency.split("->");var baseClass=eventsArr[0];var onBaseClass=eventsArr[1];jsLights.after(baseClass,function(){var baseClassObj=jsLights._getPropertyByPath(baseClass);if(!baseClassObj){throw new Error(baseClass+" not found")}else if(!baseClassObj.on){throw new Error(baseClass+" has no .on function")}else{if(baseClassObj.jsLights&&baseClassObj.jsLights.triggered&&baseClassObj.jsLights.triggered[onBaseClass]){jsLights._registerEvent(dependency)}else{baseClassObj.once(onBaseClass,function(){jsLights._registerEvent(dependency)})}}})}if(jsLights.triggered.indexOf(dependency)==-1){if(!cb.jsLights._listeningFor.has(dependency)){cb.jsLights._listeningFor.add(dependency);jsLights.once(dependency,function(){jsLights.after(_after,cb);if(cb.jsLights&&cb.jsLights._listeningFor)cb.jsLights._listeningFor["delete"](dependency)})}}});cb.jsLights._startedDepCheck=true}},{key:"createInstances",value:function createInstances(config){var _this3=this;setTimeout(function(){for(var path in config){var classPath=config[path];var extended=jsLights._extendedClasses[classPath];if(extended){classPath=extended[extended.length-1]}_this3.after(classPath,function(registerPath,classPath){this.register(registerPath,this._getPropertyByPath(classPath)).instantiate()}.bind(_this3,path,classPath))}},1)}},{key:"register",value:function register(path,reference){var jsLights=this;if(typeof path!="string"){reference=path;path=false}return new(function(){function _class(){var _this4=this;_classCallCheck(this,_class);this._after=[];this.path=jsLights._getOriginPath(path);this.reference=reference;this._listeningFor=new Set;jsLights._registered.add(this);this._defaultChainEnd=setTimeout(function(){_this4.execute()},0)}_createClass(_class,[{key:"after",value:function after(path){var _this5=this;if(typeof path=="string"){if(this._after.indexOf(path)==-1)this._after.push(path)}else if(Array.isArray(path)){path.forEach(function(p){if(_this5._after.indexOf(p)==-1)_this5._after.push(p)})}return this}},{key:"assign",value:function assign(){var _this6=this;this.onPassedDependencies=function(){_this6._assign(_this6.reference)};this._checkDependencies()}},{key:"before",value:function before(path){if(!this.path)throw Error("can not set before() without namespacing function");var paths=[];if(typeof path=="string")paths.push(path);else if(Array.isArray(path))paths=paths.concat(path);for(var i=0;i<paths.length;i++){var path=paths[i];if(jsLights.triggered.indexOf(path)!=-1)throw new Error(path+" is already trigger");if(jsLights._beforeDependency[path]){if(jsLights._beforeDependency[path].indexOf(this.path)==-1){jsLights._beforeDependency[path].push(this.path)}}else{jsLights._beforeDependency[path]=[this.path]}}return this}},{key:"dependency",value:function dependency(path){return this.after(path)}},{key:"execute",value:function execute(){var _this7=this;if(!this.onPassedDependencies){this.onPassedDependencies=function(){var reference=_this7.reference();if(_this7.path){_this7._assign(reference)}}}this._checkDependencies()}},{key:"executeAs",value:function executeAs(id){this.id(id);this.execute()}},{key:"extends",value:function _extends(path,reference){var _this8=this;path=jsLights._getOriginPath(path);if(!this.reference&&reference){this.reference=reference}if(!this.path&&path){this.path=path;if(this._id)jsLights._alias[this._id]=this.path}this._classCreator=this.reference;this.after(path);this.onPassedDependencies=function(){var superReference=jsLights._getPropertyByPath(path);var superjsLightsInstance=superReference._jsLightsInstance;_this8.parent=superjsLightsInstance;_this8.reference=_this8._classCreator(superReference);_this8.reference._jsLightsInstance=_this8;if(superjsLightsInstance){superjsLightsInstance._addChild(_this8)}if(_this8.path==path){superjsLightsInstance._recompileChildren(_this8)}_this8.assign()};return this}},{key:"id",value:function id(_id){this._id=_id;this.path=jsLights._getOriginPath(this.path);jsLights._alias[_id]=this.path;if(this._assigned){jsLights._registerEvent(_id)}return this}},{key:"instantiate",value:function instantiate(params){var _this9=this;this.onPassedDependencies=function(){var reference=new _this9.reference(params);if(_this9.path)_this9._assign(reference)};this._checkDependencies()}},{key:"_assign",value:function _assign(reference){if(!this.path)throw new Error("can not assign without namespace");if(!reference===undefined)throw new Error('can not assign "undefined" for '+this.path);if(reference){reference.jsLights={path:this.path}}var components=this.path.split(".");var pointer=window;var i=0;var _iteratorNormalCompletion=true;var _didIteratorError=false;var _iteratorError=undefined;try{for(var _iterator=components[Symbol.iterator](),_step;!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=true){var component=_step.value;i++;if(!pointer[component]){pointer[component]={}}if(i==components.length){pointer[component]=reference}pointer=pointer[component]}}catch(err){_didIteratorError=true;_iteratorError=err}finally{try{if(!_iteratorNormalCompletion&&_iterator["return"]){_iterator["return"]()}}finally{if(_didIteratorError){throw _iteratorError}}}jsLights._registerEvent(this.path);if(this._id){jsLights._registerEvent(this._id)}this._assigned=true}},{key:"_checkDependencies",value:function _checkDependencies(){var _this10=this;clearTimeout(this._defaultChainEnd);if(!this._extendedChecked&&this.path){this._extendedChecked=true;var _iteratorNormalCompletion2=true;var _didIteratorError2=false;var _iteratorError2=undefined;try{for(var _iterator2=jsLights._registered[Symbol.iterator](),_step2;!(_iteratorNormalCompletion2=(_step2=_iterator2.next()).done);_iteratorNormalCompletion2=true){var item=_step2.value;if(item.path==this.path&&item!=this){if(!jsLights._extendedClasses[this.path]){jsLights._extendedClasses[this.path]=[]}if(!this._id){this.id(this.path+"-"+jsLights._extendedClasses[this.path].length)}jsLights._extendedClasses[this.path].push(this._id)}}}catch(err){_didIteratorError2=true;_iteratorError2=err}finally{try{if(!_iteratorNormalCompletion2&&_iterator2["return"]){_iterator2["return"]()}}finally{if(_didIteratorError2){throw _iteratorError2}}}}if(this._before){for(var i=0;i<this._before.length;i++){var depPath=this._before[i];if(jsLights.triggered.indexOf(depPath)!=-1){if(!this._startedDepCheck){throw new Error(depPath+" is already assigned. Can not set before() for "+this.path)}else{continue}}jsLights.once(depPath,function(){_this10._checkDependencies()});return}}var passed=0;this._after.forEach(function(dependency){if(jsLights.triggered.indexOf(dependency)!=-1)passed++});if(passed==this._after.length){if(this.onPassedDependencies){this.onPassedDependencies()}this.onPassedDependencies=false;return}this._after.forEach(function(dependency){if(!_this10._startedDepCheck&&dependency.indexOf("->")!=-1){var eventsArr=dependency.split("->");var baseClass=eventsArr[0];var onBaseClass=eventsArr[1];jsLights.after(baseClass,function(){var baseClassObj=jsLights._getPropertyByPath(baseClass);if(!baseClassObj){throw new Error(baseClass+" not found")}else if(!baseClassObj.on){throw new Error(baseClass+" has no .on function")}else{if(baseClassObj.jsLights&&baseClassObj.jsLights.triggered&&baseClassObj.jsLights.triggered[onBaseClass]){jsLights._registerEvent(dependency)}else{baseClassObj.once(onBaseClass,function(){jsLights._registerEvent(dependency)})}}})}if(jsLights.triggered.indexOf(dependency)==-1){if(!_this10._listeningFor.has(dependency)){_this10._listeningFor.add(dependency);jsLights.once(dependency,function(){_this10._checkDependencies();_this10._listeningFor["delete"](dependency)})}}});this._startedDepCheck=true}},{key:"_recompileChildren",value:function _recompileChildren(parent){if(!this.children)return;this.children.forEach(function(child){if(child!=parent){child.reference=child._classCreator(parent.reference);child.assign();child._recompileChildren(child)}})}},{key:"_addChild",value:function _addChild(child){if(!this.children)this.children=[];this.children.push(child)}}]);return _class}())}},{key:"extend",value:function extend(path,reference){var register=this.register(path,reference);register["extends"](path);return register}},{key:"inspect",value:function inspect(path){var _this11=this;if(!path){throw new Error("Invalid path")}var found=false;var _iteratorNormalCompletion3=true;var _didIteratorError3=false;var _iteratorError3=undefined;try{for(var _iterator3=this._registered[Symbol.iterator](),_step3;!(_iteratorNormalCompletion3=(_step3=_iterator3.next()).done);_iteratorNormalCompletion3=true){var item=_step3.value;if(item.path==path){found=true;if(item.onPassedDependencies==false){console.log("Status: %cTriggered","color: green;")}else{console.log("Status: %cPending","color: red;")}if(item._after.length){console.log("Dependencies:");item._after.forEach(function(dep){if(_this11.triggered.indexOf(dep)==-1){console.log(dep+" %c (pending)","color: red")}else{console.log(dep+" %c (triggered)","color: green")}})}}}}catch(err){_didIteratorError3=true;_iteratorError3=err}finally{try{if(!_iteratorNormalCompletion3&&_iterator3["return"]){_iterator3["return"]()}}finally{if(_didIteratorError3){throw _iteratorError3}}}if(!found){console.log(path+" is not registered")}}},{key:"instantiate",value:function instantiate(path,reference,dependency){var register=this.register(path,reference);register.after(dependency);register.instantiate();return register}},{key:"onPathInstantiated",value:function onPathInstantiated(path,cb){console.warn("jsLights.onPathInstantiated is deprecated. Please use after()");console.trace();if(this.triggered.indexOf(path)!=-1){cb()}else{var self=this;this.once(path,function(){cb()})}}},{key:"_registerEvent",value:function _registerEvent(event){if(this.triggered.indexOf(event)==-1){this.triggered.push(event)}this.trigger(event)}},{key:"_getOriginPath",value:function _getOriginPath(path){while(this._alias[path]){path=this._alias[path]}return path}},{key:"_getPropertyByPath",value:function _getPropertyByPath(path){path=this._alias[path]||path;if(path=="EventEmitter"||path=="Base"){return window.jsLights.eventEmitter}var parts=path.split(".");var property=window;for(var i=0;i<parts.length;i++){property=property[parts[i]];if(property===undefined)return undefined}if(i==0)return undefined;return property}}]);return JsLights}(EventEmitter);var jsl=new JsLights;jsl.eventEmitter=jsl.base=EventEmitter;window.jsLights=jsl},{"wolfy87-eventemitter":2}],2:[function(require,module,exports){(function(){"use strict";function EventEmitter(){}var proto=EventEmitter.prototype;var exports=this;var originalGlobalValue=exports.EventEmitter;function indexOfListener(listeners,listener){var i=listeners.length;while(i--){if(listeners[i].listener===listener){return i}}return-1}function alias(name){return function aliasClosure(){return this[name].apply(this,arguments)}}proto.getListeners=function getListeners(evt){var events=this._getEvents();var response;var key;if(evt instanceof RegExp){response={};for(key in events){if(events.hasOwnProperty(key)&&evt.test(key)){response[key]=events[key]}}}else{response=events[evt]||(events[evt]=[])}return response};proto.flattenListeners=function flattenListeners(listeners){var flatListeners=[];var i;for(i=0;i<listeners.length;i+=1){flatListeners.push(listeners[i].listener)}return flatListeners};proto.getListenersAsObject=function getListenersAsObject(evt){var listeners=this.getListeners(evt);var response;if(listeners instanceof Array){response={};response[evt]=listeners}return response||listeners};proto.addListener=function addListener(evt,listener){var listeners=this.getListenersAsObject(evt);var listenerIsWrapped=typeof listener==="object";var key;for(key in listeners){if(listeners.hasOwnProperty(key)&&indexOfListener(listeners[key],listener)===-1){listeners[key].push(listenerIsWrapped?listener:{listener:listener,once:false})}}return this};proto.on=alias("addListener");proto.addOnceListener=function addOnceListener(evt,listener){return this.addListener(evt,{listener:listener,once:true})};proto.once=alias("addOnceListener");proto.defineEvent=function defineEvent(evt){this.getListeners(evt);return this};proto.defineEvents=function defineEvents(evts){for(var i=0;i<evts.length;i+=1){this.defineEvent(evts[i])}return this};proto.removeListener=function removeListener(evt,listener){var listeners=this.getListenersAsObject(evt);var index;var key;for(key in listeners){if(listeners.hasOwnProperty(key)){index=indexOfListener(listeners[key],listener);if(index!==-1){listeners[key].splice(index,1)}}}return this};proto.off=alias("removeListener");proto.addListeners=function addListeners(evt,listeners){return this.manipulateListeners(false,evt,listeners)};proto.removeListeners=function removeListeners(evt,listeners){return this.manipulateListeners(true,evt,listeners)};proto.manipulateListeners=function manipulateListeners(remove,evt,listeners){var i;var value;var single=remove?this.removeListener:this.addListener;var multiple=remove?this.removeListeners:this.addListeners;if(typeof evt==="object"&&!(evt instanceof RegExp)){for(i in evt){if(evt.hasOwnProperty(i)&&(value=evt[i])){if(typeof value==="function"){single.call(this,i,value)}else{multiple.call(this,i,value)}}}}else{i=listeners.length;while(i--){single.call(this,evt,listeners[i])}}return this};proto.removeEvent=function removeEvent(evt){var type=typeof evt;var events=this._getEvents();var key;if(type==="string"){delete events[evt]}else if(evt instanceof RegExp){for(key in events){if(events.hasOwnProperty(key)&&evt.test(key)){delete events[key]}}}else{delete this._events}return this};proto.removeAllListeners=alias("removeEvent");proto.emitEvent=function emitEvent(evt,args){var listenersMap=this.getListenersAsObject(evt);var listeners;var listener;var i;var key;var response;for(key in listenersMap){if(listenersMap.hasOwnProperty(key)){listeners=listenersMap[key].slice(0);i=listeners.length;while(i--){listener=listeners[i];if(listener.once===true){this.removeListener(evt,listener.listener)}response=listener.listener.apply(this,args||[]);if(response===this._getOnceReturnValue()){this.removeListener(evt,listener.listener)}}}}return this};proto.trigger=alias("emitEvent");proto.emit=function emit(evt){var args=Array.prototype.slice.call(arguments,1);return this.emitEvent(evt,args)};proto.setOnceReturnValue=function setOnceReturnValue(value){this._onceReturnValue=value;return this};proto._getOnceReturnValue=function _getOnceReturnValue(){if(this.hasOwnProperty("_onceReturnValue")){return this._onceReturnValue}else{return true}};proto._getEvents=function _getEvents(){return this._events||(this._events={})};EventEmitter.noConflict=function noConflict(){exports.EventEmitter=originalGlobalValue;return EventEmitter};if(typeof define==="function"&&define.amd){define(function(){return EventEmitter})}else if(typeof module==="object"&&module.exports){module.exports=EventEmitter}else{exports.EventEmitter=EventEmitter}}).call(this)},{}]},{},[1]); | ||
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){"use strict";var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();var _get=function get(_x,_x2,_x3){var _again=true;_function:while(_again){var object=_x,property=_x2,receiver=_x3;desc=parent=getter=undefined;_again=false;if(object===null)object=Function.prototype;var desc=Object.getOwnPropertyDescriptor(object,property);if(desc===undefined){var parent=Object.getPrototypeOf(object);if(parent===null){return undefined}else{_x=parent;_x2=property;_x3=receiver;_again=true;continue _function}}else if("value"in desc){return desc.value}else{var getter=desc.get;if(getter===undefined){return undefined}return getter.call(receiver)}}};function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass)}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass}var WolfyEventEmitter=require("wolfy87-eventemitter");var EventEmitter=function(_WolfyEventEmitter){_inherits(EventEmitter,_WolfyEventEmitter);function EventEmitter(){_classCallCheck(this,EventEmitter);_get(Object.getPrototypeOf(EventEmitter.prototype),"constructor",this).call(this);this._hooks={}}_createClass(EventEmitter,[{key:"addHook",value:function addHook(name,cb,options){if(!this._hooks[name]){this._hooks[name]=[]}var priority=options&&options.priority?options.priority:0;this._hooks[name].push({cb:cb,priority:priority});this._hooks[name]=this._hooks[name].sort(function(a,b){return b.priority-a.priority})}},{key:"callHooks",value:function callHooks(name,ref){if(this._hooks[name]){for(var i=0;i<this._hooks[name].length;i++){var hook=this._hooks[name][i];var returnHookVal=hook.cb(ref);if(returnHookVal){return returnHookVal}}}}},{key:"on",value:function on(evt,listener){_get(Object.getPrototypeOf(EventEmitter.prototype),"on",this).call(this,evt,listener);return{evt:evt,listener:listener}}},{key:"trigger",value:function trigger(evt,args){var arr=[];arr.push(args);args=arr;var toReturn=_get(Object.getPrototypeOf(EventEmitter.prototype),"trigger",this).call(this,evt,args);this._registerTrigger(evt);return toReturn}},{key:"unbind",value:function unbind(eventObj){if(!eventObj){return}_get(Object.getPrototypeOf(EventEmitter.prototype),"off",this).call(this,eventObj.evt,eventObj.listener)}},{key:"_registerTrigger",value:function _registerTrigger(evt){if(!this.jsLights){this.jsLights={}}if(!this.jsLights.triggered){this.jsLights.triggered={}}if(this.jsLights.triggered[evt]!==undefined){this.jsLights.triggered[evt]++}else{this.jsLights.triggered[evt]=1}}}]);return EventEmitter}(WolfyEventEmitter);var JsLights=function(_EventEmitter){_inherits(JsLights,_EventEmitter);function JsLights(){var _this=this;_classCallCheck(this,JsLights);_get(Object.getPrototypeOf(JsLights.prototype),"constructor",this).call(this);this.triggered=["EventEmitter","Base"];this._beforeDependency={};this._extendedClasses={};this._alias={};this._registered=new Set;if(document){if(document.body){this.triggered.push("onDocumentReady")}else{document.addEventListener("DOMContentLoaded",function(){_this._registerEvent("onDocumentReady")})}}}_createClass(JsLights,[{key:"assign",value:function assign(path,reference,dependency){var register=this.register(path,reference);register.after(dependency);register.assign();return register}},{key:"after",value:function after(_after,cb){var _this2=this;if(typeof cb!="function"){throw new Error("invalid callback function")}if(!Array.isArray(_after)){_after=[_after]}var passed=0;_after.forEach(function(dependency){if(_this2.triggered.indexOf(dependency)!=-1)passed++});if(passed==_after.length){cb();delete cb.jsLights;return}if(!cb.jsLights)cb.jsLights={};if(!cb.jsLights._listeningFor)cb.jsLights._listeningFor=new Set;_after.forEach(function(dependency){if(!cb.jsLights._startedDepCheck&&dependency.indexOf("->")!=-1){var eventsArr=dependency.split("->");var baseClass=eventsArr[0];var onBaseClass=eventsArr[1];jsLights.after(baseClass,function(){var baseClassObj=jsLights.getByPath(baseClass);if(!baseClassObj){throw new Error(baseClass+" not found")}else if(!baseClassObj.on){throw new Error(baseClass+" has no .on function")}else{if(baseClassObj.jsLights&&baseClassObj.jsLights.triggered&&baseClassObj.jsLights.triggered[onBaseClass]){jsLights._registerEvent(dependency)}else{baseClassObj.once(onBaseClass,function(){jsLights._registerEvent(dependency)})}}})}if(jsLights.triggered.indexOf(dependency)==-1){if(!cb.jsLights._listeningFor.has(dependency)){cb.jsLights._listeningFor.add(dependency);jsLights.once(dependency,function(){jsLights.after(_after,cb);if(cb.jsLights&&cb.jsLights._listeningFor)cb.jsLights._listeningFor["delete"](dependency)})}}});cb.jsLights._startedDepCheck=true}},{key:"createInstances",value:function createInstances(config){var _this3=this;setTimeout(function(){for(var path in config){var classPath=config[path];var extended=jsLights._extendedClasses[classPath];if(extended){classPath=extended[extended.length-1]}_this3.after(classPath,function(registerPath,classPath){this.register(registerPath,this.getByPath(classPath)).instantiate()}.bind(_this3,path,classPath))}},1)}},{key:"register",value:function register(path,reference){var jsLights=this;if(typeof path!="string"){reference=path;path=false}return new(function(){function _class(){var _this4=this;_classCallCheck(this,_class);this._after=[];this.path=jsLights._getOriginPath(path);this.reference=reference;this._listeningFor=new Set;jsLights._registered.add(this);this._defaultChainEnd=setTimeout(function(){_this4.execute()},0)}_createClass(_class,[{key:"after",value:function after(path){var _this5=this;if(typeof path=="string"){if(this._after.indexOf(path)==-1)this._after.push(path)}else if(Array.isArray(path)){path.forEach(function(p){if(_this5._after.indexOf(p)==-1)_this5._after.push(p)})}return this}},{key:"assign",value:function assign(){var _this6=this;this.onPassedDependencies=function(){_this6._assign(_this6.reference)};this._checkDependencies()}},{key:"before",value:function before(path){if(!this.path)throw Error("can not set before() without namespacing function");var paths=[];if(typeof path=="string")paths.push(path);else if(Array.isArray(path))paths=paths.concat(path);for(var i=0;i<paths.length;i++){var path=paths[i];if(jsLights.triggered.indexOf(path)!=-1)throw new Error(path+" is already trigger");if(jsLights._beforeDependency[path]){if(jsLights._beforeDependency[path].indexOf(this.path)==-1){jsLights._beforeDependency[path].push(this.path)}}else{jsLights._beforeDependency[path]=[this.path]}}return this}},{key:"dependency",value:function dependency(path){return this.after(path)}},{key:"execute",value:function execute(){var _this7=this;if(!this.onPassedDependencies){this.onPassedDependencies=function(){var reference=_this7.reference();if(_this7.path){_this7._assign(reference)}}}this._checkDependencies()}},{key:"executeAs",value:function executeAs(id){this.id(id);this.execute()}},{key:"extends",value:function _extends(path,reference){var _this8=this;path=jsLights._getOriginPath(path);if(!this.reference&&reference){this.reference=reference}if(!this.path&&path){this.path=path;if(this._id)jsLights._alias[this._id]=this.path}this._classCreator=this.reference;this.after(path);this.onPassedDependencies=function(){var superReference=jsLights.getByPath(path);var superjsLightsInstance=superReference._jsLightsInstance;_this8.parent=superjsLightsInstance;_this8.reference=_this8._classCreator(superReference);_this8.reference._jsLightsInstance=_this8;if(superjsLightsInstance){superjsLightsInstance._addChild(_this8)}if(_this8.path==path){superjsLightsInstance._recompileChildren(_this8)}_this8.assign()};return this}},{key:"id",value:function id(_id){this._id=_id;this.path=jsLights._getOriginPath(this.path);jsLights._alias[_id]=this.path;if(this._assigned){jsLights._registerEvent(_id)}return this}},{key:"instantiate",value:function instantiate(params){var _this9=this;this.onPassedDependencies=function(){var reference=new _this9.reference(params);if(_this9.path)_this9._assign(reference)};this._checkDependencies()}},{key:"_assign",value:function _assign(reference){if(!this.path)throw new Error("can not assign without namespace");if(!reference===undefined)throw new Error('can not assign "undefined" for '+this.path);if(reference){reference.jsLights={path:this.path}}var components=this.path.split(".");var pointer=window;var i=0;var _iteratorNormalCompletion=true;var _didIteratorError=false;var _iteratorError=undefined;try{for(var _iterator=components[Symbol.iterator](),_step;!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=true){var component=_step.value;i++;if(!pointer[component]){pointer[component]={}}if(i==components.length){pointer[component]=reference}pointer=pointer[component]}}catch(err){_didIteratorError=true;_iteratorError=err}finally{try{if(!_iteratorNormalCompletion&&_iterator["return"]){_iterator["return"]()}}finally{if(_didIteratorError){throw _iteratorError}}}jsLights._registerEvent(this.path);if(this._id){jsLights._registerEvent(this._id)}this._assigned=true}},{key:"_checkDependencies",value:function _checkDependencies(){var _this10=this;clearTimeout(this._defaultChainEnd);if(!this._extendedChecked&&this.path){this._extendedChecked=true;var _iteratorNormalCompletion2=true;var _didIteratorError2=false;var _iteratorError2=undefined;try{for(var _iterator2=jsLights._registered[Symbol.iterator](),_step2;!(_iteratorNormalCompletion2=(_step2=_iterator2.next()).done);_iteratorNormalCompletion2=true){var item=_step2.value;if(item.path==this.path&&item!=this){if(!jsLights._extendedClasses[this.path]){jsLights._extendedClasses[this.path]=[]}if(!this._id){this.id(this.path+"-"+jsLights._extendedClasses[this.path].length)}jsLights._extendedClasses[this.path].push(this._id)}}}catch(err){_didIteratorError2=true;_iteratorError2=err}finally{try{if(!_iteratorNormalCompletion2&&_iterator2["return"]){_iterator2["return"]()}}finally{if(_didIteratorError2){throw _iteratorError2}}}}if(this._before){for(var i=0;i<this._before.length;i++){var depPath=this._before[i];if(jsLights.triggered.indexOf(depPath)!=-1){if(!this._startedDepCheck){throw new Error(depPath+" is already assigned. Can not set before() for "+this.path)}else{continue}}jsLights.once(depPath,function(){_this10._checkDependencies()});return}}var passed=0;this._after.forEach(function(dependency){if(jsLights.triggered.indexOf(dependency)!=-1)passed++});if(passed==this._after.length){if(this.onPassedDependencies){this.onPassedDependencies()}this.onPassedDependencies=false;return}this._after.forEach(function(dependency){if(!_this10._startedDepCheck&&dependency.indexOf("->")!=-1){var eventsArr=dependency.split("->");var baseClass=eventsArr[0];var onBaseClass=eventsArr[1];jsLights.after(baseClass,function(){var baseClassObj=jsLights.getByPath(baseClass);if(!baseClassObj){throw new Error(baseClass+" not found")}else if(!baseClassObj.on){throw new Error(baseClass+" has no .on function")}else{if(baseClassObj.jsLights&&baseClassObj.jsLights.triggered&&baseClassObj.jsLights.triggered[onBaseClass]){jsLights._registerEvent(dependency)}else{baseClassObj.once(onBaseClass,function(){jsLights._registerEvent(dependency)})}}})}if(jsLights.triggered.indexOf(dependency)==-1){if(!_this10._listeningFor.has(dependency)){_this10._listeningFor.add(dependency);jsLights.once(dependency,function(){_this10._checkDependencies();_this10._listeningFor["delete"](dependency)})}}});this._startedDepCheck=true}},{key:"_recompileChildren",value:function _recompileChildren(parent){if(!this.children)return;this.children.forEach(function(child){if(child!=parent){child.reference=child._classCreator(parent.reference);child.assign();child._recompileChildren(child)}})}},{key:"_addChild",value:function _addChild(child){if(!this.children)this.children=[];this.children.push(child)}}]);return _class}())}},{key:"extend",value:function extend(path,reference){var register=this.register(path,reference);register["extends"](path);return register}},{key:"getByPath",value:function getByPath(path){path=this._alias[path]||path;if(path=="EventEmitter"||path=="Base"){return window.jsLights.eventEmitter}var parts=path.split(".");var property=window;for(var i=0;i<parts.length;i++){property=property[parts[i]];if(property===undefined)return undefined}if(i==0)return undefined;return property}},{key:"inspect",value:function inspect(path){var _this11=this;if(!path){throw new Error("Invalid path")}var found=false;var _iteratorNormalCompletion3=true;var _didIteratorError3=false;var _iteratorError3=undefined;try{for(var _iterator3=this._registered[Symbol.iterator](),_step3;!(_iteratorNormalCompletion3=(_step3=_iterator3.next()).done);_iteratorNormalCompletion3=true){var item=_step3.value;if(item.path==path){found=true;if(item.onPassedDependencies==false){console.log("Status: %cTriggered","color: green;")}else{console.log("Status: %cPending","color: red;")}if(item._after.length){console.log("Dependencies:");item._after.forEach(function(dep){if(_this11.triggered.indexOf(dep)==-1){console.log(dep+" %c (pending)","color: red")}else{console.log(dep+" %c (triggered)","color: green")}})}}}}catch(err){_didIteratorError3=true;_iteratorError3=err}finally{try{if(!_iteratorNormalCompletion3&&_iterator3["return"]){_iterator3["return"]()}}finally{if(_didIteratorError3){throw _iteratorError3}}}if(!found){console.log(path+" is not registered")}}},{key:"instantiate",value:function instantiate(path,reference,dependency){var register=this.register(path,reference);register.after(dependency);register.instantiate();return register}},{key:"onPathInstantiated",value:function onPathInstantiated(path,cb){console.warn("jsLights.onPathInstantiated is deprecated. Please use after()");console.trace();if(this.triggered.indexOf(path)!=-1){cb()}else{var self=this;this.once(path,function(){cb()})}}},{key:"_registerEvent",value:function _registerEvent(event){if(this.triggered.indexOf(event)==-1){this.triggered.push(event)}this.trigger(event)}},{key:"_getOriginPath",value:function _getOriginPath(path){while(this._alias[path]){path=this._alias[path]}return path}}]);return JsLights}(EventEmitter);var jsl=new JsLights;jsl.eventEmitter=jsl.base=EventEmitter;window.jsLights=jsl},{"wolfy87-eventemitter":2}],2:[function(require,module,exports){(function(){"use strict";function EventEmitter(){}var proto=EventEmitter.prototype;var exports=this;var originalGlobalValue=exports.EventEmitter;function indexOfListener(listeners,listener){var i=listeners.length;while(i--){if(listeners[i].listener===listener){return i}}return-1}function alias(name){return function aliasClosure(){return this[name].apply(this,arguments)}}proto.getListeners=function getListeners(evt){var events=this._getEvents();var response;var key;if(evt instanceof RegExp){response={};for(key in events){if(events.hasOwnProperty(key)&&evt.test(key)){response[key]=events[key]}}}else{response=events[evt]||(events[evt]=[])}return response};proto.flattenListeners=function flattenListeners(listeners){var flatListeners=[];var i;for(i=0;i<listeners.length;i+=1){flatListeners.push(listeners[i].listener)}return flatListeners};proto.getListenersAsObject=function getListenersAsObject(evt){var listeners=this.getListeners(evt);var response;if(listeners instanceof Array){response={};response[evt]=listeners}return response||listeners};proto.addListener=function addListener(evt,listener){var listeners=this.getListenersAsObject(evt);var listenerIsWrapped=typeof listener==="object";var key;for(key in listeners){if(listeners.hasOwnProperty(key)&&indexOfListener(listeners[key],listener)===-1){listeners[key].push(listenerIsWrapped?listener:{listener:listener,once:false})}}return this};proto.on=alias("addListener");proto.addOnceListener=function addOnceListener(evt,listener){return this.addListener(evt,{listener:listener,once:true})};proto.once=alias("addOnceListener");proto.defineEvent=function defineEvent(evt){this.getListeners(evt);return this};proto.defineEvents=function defineEvents(evts){for(var i=0;i<evts.length;i+=1){this.defineEvent(evts[i])}return this};proto.removeListener=function removeListener(evt,listener){var listeners=this.getListenersAsObject(evt);var index;var key;for(key in listeners){if(listeners.hasOwnProperty(key)){index=indexOfListener(listeners[key],listener);if(index!==-1){listeners[key].splice(index,1)}}}return this};proto.off=alias("removeListener");proto.addListeners=function addListeners(evt,listeners){return this.manipulateListeners(false,evt,listeners)};proto.removeListeners=function removeListeners(evt,listeners){return this.manipulateListeners(true,evt,listeners)};proto.manipulateListeners=function manipulateListeners(remove,evt,listeners){var i;var value;var single=remove?this.removeListener:this.addListener;var multiple=remove?this.removeListeners:this.addListeners;if(typeof evt==="object"&&!(evt instanceof RegExp)){for(i in evt){if(evt.hasOwnProperty(i)&&(value=evt[i])){if(typeof value==="function"){single.call(this,i,value)}else{multiple.call(this,i,value)}}}}else{i=listeners.length;while(i--){single.call(this,evt,listeners[i])}}return this};proto.removeEvent=function removeEvent(evt){var type=typeof evt;var events=this._getEvents();var key;if(type==="string"){delete events[evt]}else if(evt instanceof RegExp){for(key in events){if(events.hasOwnProperty(key)&&evt.test(key)){delete events[key]}}}else{delete this._events}return this};proto.removeAllListeners=alias("removeEvent");proto.emitEvent=function emitEvent(evt,args){var listenersMap=this.getListenersAsObject(evt);var listeners;var listener;var i;var key;var response;for(key in listenersMap){if(listenersMap.hasOwnProperty(key)){listeners=listenersMap[key].slice(0);i=listeners.length;while(i--){listener=listeners[i];if(listener.once===true){this.removeListener(evt,listener.listener)}response=listener.listener.apply(this,args||[]);if(response===this._getOnceReturnValue()){this.removeListener(evt,listener.listener)}}}}return this};proto.trigger=alias("emitEvent");proto.emit=function emit(evt){var args=Array.prototype.slice.call(arguments,1);return this.emitEvent(evt,args)};proto.setOnceReturnValue=function setOnceReturnValue(value){this._onceReturnValue=value;return this};proto._getOnceReturnValue=function _getOnceReturnValue(){if(this.hasOwnProperty("_onceReturnValue")){return this._onceReturnValue}else{return true}};proto._getEvents=function _getEvents(){return this._events||(this._events={})};EventEmitter.noConflict=function noConflict(){exports.EventEmitter=originalGlobalValue;return EventEmitter};if(typeof define==="function"&&define.amd){define(function(){return EventEmitter})}else if(typeof module==="object"&&module.exports){module.exports=EventEmitter}else{exports.EventEmitter=EventEmitter}}).call(this)},{}]},{},[1]); |
{ | ||
"name": "jslights", | ||
"version": "0.6.73", | ||
"version": "0.6.732", | ||
"description": "JavaScript module manager", | ||
@@ -5,0 +5,0 @@ "main": "dist/jslights.js", |
@@ -246,3 +246,3 @@ var WolfyEventEmitter = require('wolfy87-eventemitter'); | ||
jsLights.after(baseClass, () => { | ||
var baseClassObj = jsLights.getPropertyByPath(baseClass); | ||
var baseClassObj = jsLights.getByPath(baseClass); | ||
if (!baseClassObj) { | ||
@@ -309,3 +309,3 @@ throw new Error(baseClass + ' not found'); | ||
this.after(classPath, function(registerPath, classPath) { | ||
this.register(registerPath, this.getPropertyByPath(classPath)).instantiate(); | ||
this.register(registerPath, this.getByPath(classPath)).instantiate(); | ||
}.bind(this, path, classPath)); | ||
@@ -541,3 +541,3 @@ | ||
var superReference = jsLights.getPropertyByPath(path); | ||
var superReference = jsLights.getByPath(path); | ||
var superjsLightsInstance = superReference._jsLightsInstance; | ||
@@ -711,3 +711,3 @@ this.parent = superjsLightsInstance; | ||
jsLights.after(baseClass, () => { | ||
var baseClassObj = jsLights.getPropertyByPath(baseClass); | ||
var baseClassObj = jsLights.getByPath(baseClass); | ||
if (!baseClassObj) { | ||
@@ -785,3 +785,3 @@ throw new Error(baseClass + ' not found'); | ||
getPropertyByPath(path) { | ||
getByPath(path) { | ||
@@ -808,3 +808,3 @@ path = this._alias[path] || path; | ||
} | ||
/** | ||
@@ -811,0 +811,0 @@ * @memberof jsLights |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
58583