UNPKG

@soundstep/soma

Version:

Soma is a javascript framework created to build scalable and maintainable applications.

7 lines 18.2 kB
!function(t){var e={};function i(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(n,r,function(e){return t[e]}.bind(null,r));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=2)}([function(t,e,i){var n,r;!function(o){"use strict";var s=/^function\s*[^\(]*\(\s*([^\)]*)\)/m,a=/(?!function)\s*constructor\s*[^\(|function]*\(\s*([^\)]*)\)\s*{/m,c=/,/,p=/^\s*(_?)(\S+?)\1\s*$/,h=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm;o.errors={MAPPING_BAD_PROP:"[Error Injector.MAPPING_BAD_PROP] The first parameter is invalid, a string is expected.",MAPPING_BAD_VALUE:"[Error Injector.MAPPING_BAD_VALUE] The second parameter is invalid, it can't null or undefined, with property: ",MAPPING_BAD_CLASS:"[Error Injector.MAPPING_BAD_CLASS] The second parameter is invalid, a function is expected, with property: ",MAPPING_BAD_SINGLETON:"[Error Injector.MAPPING_BAD_SINGLETON] The third parameter is invalid, a boolean is expected, with property: ",MAPPING_ALREADY_EXISTS:"[Error Injector.MAPPING_ALREADY_EXISTS] This mapping already exists, with property: ",CREATE_INSTANCE_INVALID_PARAM:"[Error Injector.CREATE_INSTANCE_INVALID_PARAM] Invalid parameter, a function is expected.",NO_MAPPING_FOUND:"[Error Injector.NO_MAPPING_FOUND] No mapping found",INJECT_INSTANCE_IN_ITSELF_PROPERTY:"[Error Injector.INJECT_INSTANCE_IN_ITSELF_PROPERTY] A matching property has been found in the target, you can't inject an instance in itself.",INJECT_INSTANCE_IN_ITSELF_CONSTRUCTOR:"[Error Injector.INJECT_INSTANCE_IN_ITSELF_CONSTRUCTOR] A matching constructor parameter has been found in the target, you can't inject an instance in itself.",DEPENDENCIES_MISSING_IN_STRICT_MODE:'[Error Injector.DEPENDENCIES_MISSING_IN_STRICT_MODE] An "inject" property (array) that describes the dependencies is missing in strict mode.',DEPENDENCIES_MISSING_IN_STRICT_MODE_CONSTRUCTOR_INJECTION:'[Error Injector.DEPENDENCIES_MISSING_IN_STRICT_MODE_CONSTRUCTOR_INJECTION] An "inject" property (array) that describes the dependencies of constructor is missing in strict mode.',DEPENDENCIES_INVALID_TARGET:"[Error Injector.DEPENDENCIES_INVALID_TARGET] Invalid target, a function or a class is expected (arrow function cannot be instantiated)."};var u=function(t,e,i,n){this.prop=t,this.value=e,this.cl=i,this.singleton=n||!1},l=function(t){if("string"!=typeof t)throw new Error(o.errors.MAPPING_BAD_PROP)},d=function(t,e){if(function(t,e){for(var i=t.length;i--;)if(t[i]===e)return!0;return!1}(o.getDependencies(e),t))throw new Error(o.errors.INJECT_INSTANCE_IN_ITSELF_CONSTRUCTOR)},f=function(t,e){var i=void 0!==t?' for the injection name: "'+t+'"':"",n=void 0!==e?' when instantiating: "'+e+'"':"";return o.errors.NO_MAPPING_FOUND+i+n+"."};o.Injector=function(){this.mappings={},this.parent=null,this.strictMode=!1,this.strictModeConstructorInjection=!1,this.throwOnMissing=!0},o.getDependencies=function(t){var e,i=[];function n(t,e,n){i.push(n)}t.hasOwnProperty("inject")&&"[object Array]"===Object.prototype.toString.call(t.inject)&&t.inject.length>0&&(e=t.inject);var r,u=t.toString().replace(h,"");if(0===u.indexOf("class"))r=u.replace(/function constructor/g,"").match(a);else{if(0!==u.indexOf("function"))throw new Error(o.errors.DEPENDENCIES_INVALID_TARGET);r=u.match(s)}if(r)for(var l=r[1].split(c),d=0,f=l.length;d<f;d++){var g=l[d].split("=")[0].replace(/\s/g,"");(e&&e[d]?e[d]:g).replace(p,n)}return i},o.Injector.prototype={createChild:function(){var t=new o.Injector;return t.parent=this,t.strictMode=this.strictMode,t.strictModeConstructorInjection=this.strictModeConstructorInjection,t.throwOnMissing=this.throwOnMissing,t},getMappingVo:function(t){return this.mappings?this.mappings[t]?this.mappings[t]:this.parent?this.parent.getMappingVo(t):null:null},mapValue:function(t,e){if(this.mappings[t])throw new Error(o.errors.MAPPING_ALREADY_EXISTS+t);return l(t),function(t,e){if(null==e)throw new Error(o.errors.MAPPING_BAD_VALUE+t)}(t,e),this.mappings[t]=new u(t,e,void 0,void 0),this},mapClass:function(t,e,i){if(this.mappings[t])throw new Error(o.errors.MAPPING_ALREADY_EXISTS+t);return l(t),function(t,e){if("function"!=typeof e)throw new Error(o.errors.MAPPING_BAD_CLASS+t)}(t,e),i&&function(t,e){if("boolean"!=typeof e)throw new Error(o.errors.MAPPING_BAD_SINGLETON+t)}(t,i),this.mappings[t]=new u(t,null,e,i),this},removeMapping:function(t){return this.mappings[t]=null,delete this.mappings[t],this},hasMapping:function(t){return!!this.mappings[t]},hasInheritedMapping:function(t){return!!this.getMappingVo(t)},getMapping:function(t){for(var e in this.mappings)if(this.mappings.hasOwnProperty(e)){var i=this.mappings[e];if(i.value===t||i.cl===t)return i.prop}},getValue:function(t){var e=this.mappings[t];if(!e){if(!this.parent){if(this.throwOnMissing)throw new Error(f(t));return}e=this.parent.getMappingVo.apply(this.parent,arguments)}if(e.cl){var i=Array.prototype.slice.call(arguments);return i[0]=e.cl,e.singleton?(e.value||(e.value=this.createInstance.apply(this,i)),e.value):this.createInstance.apply(this,i)}return e.value},getClass:function(t){var e=this.mappings[t];if(!e){if(!this.parent)return;e=this.parent.getMappingVo.apply(this.parent,arguments)}if(e.cl)return e.cl},instantiate:function(t){if("function"!=typeof t)throw new Error(o.errors.CREATE_INSTANCE_INVALID_PARAM);var e=o.getDependencies(t);if(this.strictMode&&!t.hasOwnProperty("inject"))throw new Error(o.errors.DEPENDENCIES_MISSING_IN_STRICT_MODE);if(this.strictModeConstructorInjection&&e.length>0&&!t.hasOwnProperty("inject"))throw new Error(o.errors.DEPENDENCIES_MISSING_IN_STRICT_MODE_CONSTRUCTOR_INJECTION);for(var i=[null],n=0,r=e.length;n<r;n++)if(arguments.length>n+1&&void 0!==arguments[n+1]&&null!==arguments[n+1])i.push(arguments[n+1]);else{var s=e[n],a=this.getMappingVo(s);if(a){var c=this.getInjectedValue(a,s);i.push(c)}else{if(this.throwOnMissing)throw new Error(f(s,t.name));i.push(void 0)}}return new(Function.prototype.bind.apply(t,i))},inject:function(t,e){for(var i in this.parent&&this.parent.inject(t,!0),this.mappings)if(this.mappings.hasOwnProperty(i)){var n=this.getMappingVo(i);(t.hasOwnProperty(n.prop)||t.constructor&&t.constructor.prototype&&t.constructor.prototype.hasOwnProperty(n.prop))&&(t[i]=this.getInjectedValue(n,i))}return"function"!=typeof t.postConstruct||e||t.postConstruct(),this},getInjectedValue:function(t,e){var i,n=t.value;return t.cl&&(t.singleton?(t.value||(d(e,t.cl),t.value=this.instantiate(t.cl),i=t.value),n=t.value):(d(e,t.cl),i=n=this.instantiate(t.cl))),i&&(!function(t,e){if(e.hasOwnProperty(t))throw new Error(o.errors.INJECT_INSTANCE_IN_ITSELF_PROPERTY)}(e,i),this.inject(i)),n},createInstance:function(){var t=this.instantiate.apply(this,arguments);return this.inject(t),t},getValueFromClass:function(t){for(var e in this.mappings)if(this.mappings.hasOwnProperty(e)){var i=this.mappings[e];if(i.cl===t)return i.singleton?(i.value||(i.value=this.createInstance.apply(this,arguments)),i.value):this.createInstance.apply(this,arguments)}if(this.parent)return this.parent.getValueFromClass.apply(this.parent,arguments);if(this.throwOnMissing)throw new Error(f(void 0,t.name))},dispose:function(){this.mappings={}}},Function.prototype.bind||(Function.prototype.bind=function(t){var e=this;if("function"!=typeof e)throw new Error("Error, you must bind a function.");var i=Array.prototype.slice.call(arguments,1),n=function(){if(this instanceof n){var r=function(){};r.prototype=e.prototype;var o=new r,s=e.apply(o,i.concat(Array.prototype.slice.call(arguments)));return Object(s)===s?s:o}return e.apply(t,i.concat(Array.prototype.slice.call(arguments)))};return n}),void 0===(r="function"==typeof(n=o)?n.call(e,i,e,t):n)||(t.exports=r),void 0!==t.exports&&(t.exports=o),e=o}(this.infuse=this.infuse||{})},function(t,e,i){var n; /** @license * JS Signals <http://millermedeiros.github.com/js-signals/> * Released under the MIT license * Author: Miller Medeiros * Version: 1.0.0 - Build: 268 (2012/11/29 05:48 PM) */!function(r){function o(t,e,i,n,r){this._listener=e,this._isOnce=i,this.context=n,this._signal=t,this._priority=r||0}function s(t,e){if("function"!=typeof t)throw new Error("listener is a required param of {fn}() and should be a Function.".replace("{fn}",e))}function a(){this._bindings=[],this._prevParams=null;var t=this;this.dispatch=function(){a.prototype.dispatch.apply(t,arguments)}}o.prototype={active:!0,params:null,execute:function(t){var e,i;return this.active&&this._listener&&(i=this.params?this.params.concat(t):t,e=this._listener.apply(this.context,i),this._isOnce&&this.detach()),e},detach:function(){return this.isBound()?this._signal.remove(this._listener,this.context):null},isBound:function(){return!!this._signal&&!!this._listener},isOnce:function(){return this._isOnce},getListener:function(){return this._listener},getSignal:function(){return this._signal},_destroy:function(){delete this._signal,delete this._listener,delete this.context},toString:function(){return"[SignalBinding isOnce:"+this._isOnce+", isBound:"+this.isBound()+", active:"+this.active+"]"}},a.prototype={VERSION:"1.0.0",memorize:!1,_shouldPropagate:!0,active:!0,_registerListener:function(t,e,i,n){var r,s=this._indexOfListener(t,i);if(-1!==s){if((r=this._bindings[s]).isOnce()!==e)throw new Error("You cannot add"+(e?"":"Once")+"() then add"+(e?"Once":"")+"() the same listener without removing the relationship first.")}else r=new o(this,t,e,i,n),this._addBinding(r);return this.memorize&&this._prevParams&&r.execute(this._prevParams),r},_addBinding:function(t){var e=this._bindings.length;do{--e}while(this._bindings[e]&&t._priority<=this._bindings[e]._priority);this._bindings.splice(e+1,0,t)},_indexOfListener:function(t,e){for(var i,n=this._bindings.length;n--;)if((i=this._bindings[n])._listener===t&&i.context===e)return n;return-1},has:function(t,e){return-1!==this._indexOfListener(t,e)},add:function(t,e,i){return s(t,"add"),this._registerListener(t,!1,e,i)},addOnce:function(t,e,i){return s(t,"addOnce"),this._registerListener(t,!0,e,i)},remove:function(t,e){s(t,"remove");var i=this._indexOfListener(t,e);return-1!==i&&(this._bindings[i]._destroy(),this._bindings.splice(i,1)),t},removeAll:function(){for(var t=this._bindings.length;t--;)this._bindings[t]._destroy();this._bindings.length=0},getNumListeners:function(){return this._bindings.length},halt:function(){this._shouldPropagate=!1},dispatch:function(t){if(this.active){var e,i=Array.prototype.slice.call(arguments),n=this._bindings.length;if(this.memorize&&(this._prevParams=i),n){e=this._bindings.slice(),this._shouldPropagate=!0;do{n--}while(e[n]&&this._shouldPropagate&&!1!==e[n].execute(i))}}},forget:function(){this._prevParams=null},dispose:function(){this.removeAll(),delete this._bindings,delete this._prevParams},toString:function(){return"[Signal active:"+this.active+" numListeners:"+this.getNumListeners()+"]"}};var c=a;c.Signal=a,void 0===(n=function(){return c}.call(e,i,e,t))||(t.exports=n)}()},function(t,e,i){"use strict";i.r(e);var n=i(0),r=i.n(n),o=i(1),s=i.n(o);const a=function(){this.signals={}};a.prototype.addListener=function(t,e,i,n){return this.signals[t]||(this.signals[t]=new s.a),this.signals[t].add(e,i,n)},a.prototype.addListenerOnce=function(t,e,i,n){return this.signals[t]||(this.signals[t]=new s.a),this.signals[t].addOnce(e,i,n)},a.prototype.removeListener=function(t,e,i){const n=this.signals[t];n&&n.remove(e,i)},a.prototype.getSignal=function(t){return this.signals[t]},a.prototype.dispatch=function(t,e){const i=this.signals[t];i&&(e?i.dispatch.apply(i,e):i.dispatch())},a.prototype.dispose=function(){for(const t in this.signals)this.signals[t].removeAll(),this.signals[t]=void 0,delete this.signals[t];this.signals={}},a.extend=function(t){return utils.inherit(a,t)};const c={};function p(t,e,i,n,r){const o=Array.prototype.slice.call(arguments,5),s=t.createChild();s.mapValue("id",e),s.mapValue("signal",n),s.mapValue("binding",r);const a=s.createInstance(i);"function"==typeof a.execute&&a.execute.apply(a,o),s.dispose()}c.is={object:t=>"object"==typeof t&&null!==t,array:Array.isArray||(t=>"[object Array]"===Object.prototype.toString.call(t)),func:t=>"function"==typeof t},c.applyProperties=(t,e,i,n)=>{if("[object Array]"===Object.prototype.toString.apply(n))for(const r=0,o=n.length;r<o;r++)void 0!==t[n[r]]&&null!==t[n[r]]||(i&&"function"==typeof e[n[r]]?t[n[r]]=e[n[r]].bind(e):t[n[r]]=e[n[r]]);else for(const n in e)i&&"function"==typeof e[n]?t[n]=e[n].bind(e):t[n]=e[n]},c.augment=(t,e,i)=>{if(e.prototype&&t.prototype)if("[object Array]"===Object.prototype.toString.apply(i))for(const n=0,r=i.length;n<r;n++)t.prototype[i[n]]||(t.prototype[i[n]]=e.prototype[i[n]]);else for(const i in e.prototype)t.prototype[i]||(t.prototype[i]=e.prototype[i])},c.inherit=(t,e)=>{let i;i=e&&e.hasOwnProperty("constructor")?e.constructor:function(){return t.apply(this,arguments)};const n=function(){};return n.prototype=t.prototype,i.prototype=new n,e&&c.applyProperties(i.prototype,e),i.prototype.constructor=i,i.parent=t.prototype,i.extend=function(t){return c.inherit(i,t)},i},c.extend=t=>c.inherit((function(){}),t);const h=function(t,e){this.list={},this.emitter=t,this.injector=e};h.prototype.add=function(t,e){if(this.list[t])throw new Error('[Commands] Error: a command with the id: "'+t+'" has already been registered');return this.list[t]=e,function t(e){return{setInjector:function(i){return e&&i&&(e.params[0]=i),t(e)}}}(function(t,e,i){const n=t.emitter.addListener(e,p,t);return n.params=[t.injector,e,i,t.emitter.getSignal(e),n],n}(this,t,e))},h.prototype.get=function(t){return this.list[t]},h.prototype.remove=function(t){this.list[t]&&(this.list[t]=void 0,delete this.list[t],function(t,e){const i=t.emitter.getSignal(e);i&&i.removeAll()}(this,t))},h.prototype.dispose=function(){for(const t in this.list)this.remove(t);this.list={},this.emitter=void 0,this.injector=void 0},h.extend=function(t){return c.inherit(h,t)};const u=function(t,e){this.emitter=t,this.injector=e};u.prototype.create=function(t,e){if(!e||"function"!=typeof e)throw new Error("[Mediators] Error creating a mediator, the first parameter must be a function.");if(null==t)throw new Error("Error creating a mediator, the second parameter cannot be undefined or null.");let i=[];const n=[],r=Object.prototype.toString.call(t);("[object Array]"===r||"[object NodeList]"===r)&&t.length>0?i=[].concat(t):i.push(t);for(const t=0,r=i.length;t<r;t++){const r=this.injector.createChild();r.mapValue("target",i[t]);const o=r.createInstance(e);if(1===i.length)return o;n.push(o)}return n},u.prototype.dispose=function(){this.emitter=void 0,this.injector=void 0};const l=function(t){this.injector=t,this.list={}};l.prototype.create=function(t,e,i,n){let o,s;const a=!1!==i,p=!0===n;if(c.is.function(t))s=t;else if(c.is.object(t)&&c.is.function(t.module))s=t.module;else{if(!c.is.object(t)||!c.is.function(t.Module))throw new Error("[Modules] Error: Could not create module. The module must be a function or an object containing a module property referencing a function.");s=t.Module}if(!function(t){const e=!0;return null==t?e=!1:"string"!=typeof t.id&&(e=!1),e}(s))throw new Error('[Modules] Error: Could not create module. The module function must contain a static "id" property, ex: function Module(){}; Module.id = "module-name"; ');if(s)if(this.has(s.id))o=this.get(s.id);else{const t=this.injector;p&&(t=this.injector.createChild(),t.mapValue("injector",t)),o=function(t,e,i){const n=r.a.getDependencies(e),o=[e];for(const e=0,i=n.length;e<i;e++)t.hasMapping(n[e])||t.hasInheritedMapping(n[e])?o.push(t.getValue(n[e])):o.push(void 0);for(const t=o.length-1;t>=0&&void 0===o[t];t--)o.splice(t,1);return o=o.concat(i),t.createInstance.apply(t,o)}(t,s,e),h=this.list,u=s.id,l=o,!h[u]&&a&&(h[u]=l),"function"==typeof o.init&&o.init()}var h,u,l;return o},l.prototype.has=function(t){return void 0!==this.list[t]},l.prototype.get=function(t){return this.list[t]},l.prototype.remove=function(t){this.list[t]&&("function"==typeof this.list[t].dispose&&this.list[t].dispose(),this.list[t]=void 0,delete this.list[t])},l.prototype.dispose=function(){for(const t in this.list)this.remove(t);this.list={}};var d=function(){this.injector=void 0,this.emitter=void 0,this.commands=void 0,this.mediators=void 0,this.setup(),this.init()};d.prototype.setup=function(){this.injector=new r.a.Injector,this.injector.throwOnMissing=!1,this.injector.mapValue("injector",this.injector),this.injector.mapValue("instance",this),this.injector.mapClass("emitter",a,!0),this.emitter=this.injector.getValue("emitter"),this.injector.mapClass("commands",h,!0),this.commands=this.injector.getValue("commands"),this.injector.mapClass("mediators",u,!0),this.mediators=this.injector.getValue("mediators"),this.injector.mapClass("modules",l,!0),this.modules=this.injector.getValue("modules")},d.prototype.init=function(){},d.prototype.dispose=function(){this.injector&&this.injector.dispose(),this.emitter&&this.emitter.dispose(),this.commands&&this.commands.dispose(),this.mediators&&this.mediators.dispose(),this.modules&&this.modules.dispose(),this.injector=void 0,this.emitter=void 0,this.commands=void 0,this.mediators=void 0,this.modules=void 0},d.extend=function(t){return c.inherit(d,t)};class f{get(){return"Hello"}}function g(t){this.execute=e=>{document.body.innerHTML=`${t.get()} ${e}`}}g.inject=["model"];(new class extends d{init(){this.injector.mapClass("model",f,!0),this.commands.add("test-command",g)}start(){this.emitter.dispatch("test-command",["World!"])}}).start()}]);