Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jslights

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jslights - npm Package Compare versions

Comparing version 0.6.2 to 0.6.3

jslights.js

2

dist/jslights.js

@@ -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(object,property,receiver){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{return get(parent,property,receiver)}}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 _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return call&&(typeof call==="object"||typeof call==="function")?call:self}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 EventEmitter=require("wolfy87-eventemitter");var ModuleEventEmitter=function(_EventEmitter){_inherits(ModuleEventEmitter,_EventEmitter);function ModuleEventEmitter(params){_classCallCheck(this,ModuleEventEmitter);var _this=_possibleConstructorReturn(this,Object.getPrototypeOf(ModuleEventEmitter).call(this,params));_this._hooks={};return _this}_createClass(ModuleEventEmitter,[{key:"on",value:function on(evt,listener){_get(Object.getPrototypeOf(ModuleEventEmitter.prototype),"on",this).call(this,evt,listener);return{evt:evt,listener:listener}}},{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:"trigger",value:function trigger(evt,args){var arr=[];arr.push(args);args=arr;if(window.jsLights.monitor){this._triggerWithMonitoring(evt,args)}else{_get(Object.getPrototypeOf(ModuleEventEmitter.prototype),"trigger",this).call(this,evt,args)}this._registerTrigger(evt)}},{key:"unbind",value:function unbind(eventObj){if(!eventObj){return}_get(Object.getPrototypeOf(ModuleEventEmitter.prototype),"off",this).call(this,eventObj.evt,eventObj.listener)}},{key:"_triggerWithMonitoring",value:function _triggerWithMonitoring(evt,args){var start=performance.now();_get(Object.getPrototypeOf(ModuleEventEmitter.prototype),"trigger",this).call(this,evt,args);var end=performance.now();var time=end-start;var path=this.constructor.name;if(path=="jsLights"){path=evt}else{if(this.jsLights&&this.jsLights.path){path=this.jsLights.path}path+="->"+evt}if(!window.jsLights._monitStats[path]){window.jsLights._monitStats[path]={executed:0,totalExecTime:0}}var c=window.jsLights._monitStats[path];c.totalExecTime+=time;c.executed++;c.avgExecTime=c.totalExecTime/c.executed;c.totalExecTime=parseFloat(c.totalExecTime.toFixed(2));c.avgExecTime=parseFloat(c.avgExecTime.toFixed(2));if(!this._events)c.listeners=0;else c.listeners=Object.keys(this._events).length}},{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 ModuleEventEmitter}(EventEmitter);var jsLights=function(_ModuleEventEmitter){_inherits(jsLights,_ModuleEventEmitter);function jsLights(){_classCallCheck(this,jsLights);var _this2=_possibleConstructorReturn(this,Object.getPrototypeOf(jsLights).call(this));_this2.triggered=["EventEmitter"];_this2._beforeDependency={};_this2._classExtendedWith={};_this2._alias={};if(document.body){_this2.triggered.push("onDocumentReady")}else{document.addEventListener("DOMContentLoaded",function(){_this2.registerEvent("onDocumentReady")})}return _this2}_createClass(jsLights,[{key:"assign",value:function assign(path,reference,dependency){var register=this.register(path,reference);register.after(dependency);register.assign();return register}},{key:"createInstances",value:function createInstances(config){for(var path in config){this.register(path,function(path){var fn=this._getPropertyByPath(path);return new fn}.bind(this,config[path])).dependency(config[path]).execute()}}},{key:"register",value:function register(path,reference){var jsLights=this;if(typeof path!="string"){reference=path;path=false}return new(function(){function _class(){_classCallCheck(this,_class);this._after=[];this.path=jsLights._getOriginPath(path);this.reference=reference;this._listeningFor=new Set}_createClass(_class,[{key:"after",value:function after(path){if(typeof path=="string")this._after.push(path);else if(Array.isArray(path))this._after=this._after.concat(path);return this}},{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:"instantiate",value:function instantiate(params){var _this3=this;this.onPassedDependencies=function(){var reference=new _this3.reference(params);_this3._assign(reference)};this._checkDependencies();return this}},{key:"execute",value:function execute(){var _this4=this;if(!this.onPassedDependencies){this.onPassedDependencies=function(){var reference=_this4.reference();_this4._assign(reference)}}this._checkDependencies();return this}},{key:"executeAs",value:function executeAs(id){this.id(id);this.execute()}},{key:"id",value:function id(_id2){this._id=_id2;this.path=jsLights._getOriginPath(this.path);jsLights._alias[_id2]=this.path;if(this._assigned){jsLights.registerEvent(_id2)}return this}},{key:"extends",value:function _extends(path,reference){var _this5=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;_this5.parent=superjsLightsInstance;_this5.reference=_this5._classCreator(superReference);_this5.reference._jsLightsInstance=_this5;if(superjsLightsInstance){superjsLightsInstance._addChild(_this5)}if(_this5.path==path){superjsLightsInstance._recompileChildren(_this5)}_this5.assign()};return this}},{key:"assign",value:function assign(){var _this6=this;this.onPassedDependencies=function(){_this6._assign(_this6.reference)};this._checkDependencies();return this}},{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 _this7=this;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(){_this7._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(!_this7._startedDepCheck&&dependency.indexOf("->")!=-1){var eventsArr=dependency.split("->");var baseClass=eventsArr[0];var onBaseClass=eventsArr[1];jsLights.onPathInstantiated(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(!_this7._listeningFor.has(dependency)){_this7._listeningFor.add(dependency);jsLights.once(dependency,function(){_this7._checkDependencies();_this7._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:"id",value:function id(_id){var register=this.register();register.id(_id);return register}},{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){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"){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}(ModuleEventEmitter);var jsl=new jsLights;jsl._monitStats={};jsl.stats=function(){console.table(jsl._monitStats)};jsl.eventEmitter=ModuleEventEmitter;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 EventEmitter=require("wolfy87-eventemitter");var ModuleEventEmitter=function(_EventEmitter){_inherits(ModuleEventEmitter,_EventEmitter);function ModuleEventEmitter(params){_classCallCheck(this,ModuleEventEmitter);_get(Object.getPrototypeOf(ModuleEventEmitter.prototype),"constructor",this).call(this,params);this._hooks={}}_createClass(ModuleEventEmitter,[{key:"on",value:function on(evt,listener){_get(Object.getPrototypeOf(ModuleEventEmitter.prototype),"on",this).call(this,evt,listener);return{evt:evt,listener:listener}}},{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:"trigger",value:function trigger(evt,args){var arr=[];arr.push(args);args=arr;_get(Object.getPrototypeOf(ModuleEventEmitter.prototype),"trigger",this).call(this,evt,args);this._registerTrigger(evt)}},{key:"unbind",value:function unbind(eventObj){if(!eventObj){return}_get(Object.getPrototypeOf(ModuleEventEmitter.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 ModuleEventEmitter}(EventEmitter);var JsLights=function(_ModuleEventEmitter){_inherits(JsLights,_ModuleEventEmitter);function JsLights(){var _this=this;_classCallCheck(this,JsLights);_get(Object.getPrototypeOf(JsLights.prototype),"constructor",this).call(this);this.triggered=["EventEmitter","Base"];this._beforeDependency={};this._classExtendedWith={};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){for(var path in config){this.register(path,function(path){var fn=this._getPropertyByPath(path);return new fn}.bind(this,config[path])).dependency(config[path]).execute()}}},{key:"register",value:function register(path,reference){var jsLights=this;if(typeof path!="string"){reference=path;path=false}return new(function(){function _class(){_classCallCheck(this,_class);this._after=[];this.path=jsLights._getOriginPath(path);this.reference=reference;this._listeningFor=new Set;jsLights._registered.add(this)}_createClass(_class,[{key:"after",value:function after(path){if(typeof path=="string")this._after.push(path);else if(Array.isArray(path))this._after=this._after.concat(path);return this}},{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:"instantiate",value:function instantiate(params){var _this3=this;this.onPassedDependencies=function(){var reference=new _this3.reference(params);_this3._assign(reference)};this._checkDependencies();return this}},{key:"execute",value:function execute(){var _this4=this;if(!this.onPassedDependencies){this.onPassedDependencies=function(){var reference=_this4.reference();_this4._assign(reference)}}this._checkDependencies();return this}},{key:"executeAs",value:function executeAs(id){this.id(id);this.execute()}},{key:"id",value:function id(_id2){this._id=_id2;this.path=jsLights._getOriginPath(this.path);jsLights._alias[_id2]=this.path;if(this._assigned){jsLights.registerEvent(_id2)}return this}},{key:"extends",value:function _extends(path,reference){var _this5=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;_this5.parent=superjsLightsInstance;_this5.reference=_this5._classCreator(superReference);_this5.reference._jsLightsInstance=_this5;if(superjsLightsInstance){superjsLightsInstance._addChild(_this5)}if(_this5.path==path){superjsLightsInstance._recompileChildren(_this5)}_this5.assign()};return this}},{key:"assign",value:function assign(){var _this6=this;this.onPassedDependencies=function(){_this6._assign(_this6.reference)};this._checkDependencies();return this}},{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 _this7=this;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(){_this7._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(!_this7._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(!_this7._listeningFor.has(dependency)){_this7._listeningFor.add(dependency);jsLights.once(dependency,function(){_this7._checkDependencies();_this7._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:"id",value:function id(_id){var register=this.register();register.id(_id);return register}},{key:"inspect",value:function inspect(path){var _this8=this;if(!path){throw new Error("Invalid path")}var found=false;var _iteratorNormalCompletion2=true;var _didIteratorError2=false;var _iteratorError2=undefined;try{for(var _iterator2=this._registered[Symbol.iterator](),_step2;!(_iteratorNormalCompletion2=(_step2=_iterator2.next()).done);_iteratorNormalCompletion2=true){var item=_step2.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(_this8.triggered.indexOf(dep)==-1){console.log(dep+" %c (pending)","color: red")}else{console.log(dep+" %c (triggered)","color: green")}})}}}}catch(err){_didIteratorError2=true;_iteratorError2=err}finally{try{if(!_iteratorNormalCompletion2&&_iterator2["return"]){_iterator2["return"]()}}finally{if(_didIteratorError2){throw _iteratorError2}}}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}(ModuleEventEmitter);var jsl=new JsLights;jsl.eventEmitter=jsl.base=ModuleEventEmitter;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.2",
"version": "0.6.3",
"description": "JavaScript module namespacer and event emitter",
"main": "index.js",
"main": "jslights.js",
"dependencies": {

@@ -11,4 +11,4 @@ "wolfy87-eventemitter": "^4.3.0"

"test": "echo \"Error: no test specified\" && exit 1",
"dist": "babel index.js -o _es5.js && browserify _es5.js -o dist/jslights.js && uglifyjs dist/jslights.js -o dist/jslights.js && rm _es5.js",
"distnomin": "babel index.js -o _es5.js && browserify _es5.js -o dist/jslights.js && rm _es5.js"
"dist": "babel jslights.js -o _es5.js && browserify _es5.js -o dist/jslights.js && uglifyjs dist/jslights.js -o dist/jslights.js && rm _es5.js",
"distnomin": "babel jslights.js -o _es5.js && browserify _es5.js -o dist/jslights.js && rm _es5.js"
},

@@ -19,3 +19,3 @@ "repository": {

},
"author": "Domagoj",
"author": "Domagoj Kriskovic",
"license": "MIT",

@@ -22,0 +22,0 @@ "bugs": {

# jsLights
JavaScript module namespacer and event emitter
JavaScript module manager

@@ -59,2 +59,2 @@ ## Usage

For now, to be able to build minified file, you need to have "babel", "browserify" and "uglifyjs" installed globaly
(this should be changed in the near future)
(this should be changed in the near future)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc