From e1f1acc55ae17bf3059dc1e884b8f6a267e34450 Mon Sep 17 00:00:00 2001 From: valentin-lozev Date: Sat, 9 Jun 2018 16:13:29 +0300 Subject: [PATCH] Init v1.0.2 --- dist/justcore.module.js | 2 +- dist/justcore.umd.js | 2 +- dist/justcore.umd.min.js | 2 +- package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/justcore.module.js b/dist/justcore.module.js index d6028de..36e567b 100644 --- a/dist/justcore.module.js +++ b/dist/justcore.module.js @@ -5,7 +5,7 @@ * Source code: http://github.com/valentin-lozev/justcore */ -var VERSION = "1.0.1"; +var VERSION = "1.0.2"; var errorCodes = { m1: function () { return "use(): extensions must be installed before init"; }, diff --git a/dist/justcore.umd.js b/dist/justcore.umd.js index 6aed696..95e5202 100644 --- a/dist/justcore.umd.js +++ b/dist/justcore.umd.js @@ -11,7 +11,7 @@ (factory((global.justcore = {}))); }(this, (function (exports) { 'use strict'; -var VERSION = "1.0.1"; +var VERSION = "1.0.2"; var errorCodes = { m1: function () { return "use(): extensions must be installed before init"; }, diff --git a/dist/justcore.umd.min.js b/dist/justcore.umd.min.js index cdc1f32..2fbbfe5 100644 --- a/dist/justcore.umd.min.js +++ b/dist/justcore.umd.min.js @@ -4,4 +4,4 @@ * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php * Source code: http://github.com/valentin-lozev/justcore */ -!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?factory(exports):"function"==typeof define&&define.amd?define(["exports"],factory):factory(global.justcore={})}(this,function(exports){"use strict";function throwError(code,formatId){var msgCreator=errorCodes[code];throw new Error(msgCreator(formatId))}var errorCodes={m1:function(){return"use(): extensions must be installed before init"},m2:function(){return"use(): extensions must be passed as an array"},m3:function(){return"use(): extension must be an object"},m4:function(){return"use(): extension name must be a non empty string"},m5:function(id){return'use(): "'+id+'" install must be a function'},m6:function(id){return'use(): "'+id+'" has already been used'},m7:function(){return"init(): core has already been initialized"},m8:function(){return"addModule(): id must be a non empty string"},m9:function(id){return'addModule(): "'+id+'" has already been added'},m10:function(id){return'addModule(): "'+id+'" factory must be a function'},m11:function(){return"startModule(): core must be initialized first"},m12:function(id){return'startModule(): "'+id+'" not found'},m13:function(id){return'startModule(): "'+id+"\"'s sandbox property must be a Sandbox instance"},m14:function(id){return'startModule(): "'+id+'" init hook must be defined'},m15:function(id){return'startModule(): "'+id+'" destroy hook must be defined'},m16:function(){return"createHook(): type must be a non empty string"},m17:function(id){return'createHook(): "'+id+'" method must be a function'},m18:function(){return"addPlugin(): hook type must be a non empty string"},m19:function(id){return'addPlugin(): "'+id+'" plugin must be a function'},m20:function(){return"onMessage(): message type must be a non empty string"},m21:function(id){return'onMessage(): "'+id+'" handler should be a function'},m22:function(){return"publishAsync(): message must be an object"},m23:function(id){return'"'+id+'" moduleDidReceiveMessage hook must be defined in order to subscribe'}},guard=new(function(){function ArgumentGuard(){}return ArgumentGuard.prototype.array=function(arg,code,formatId){return Array.isArray(arg)||throwError(code,formatId),this},ArgumentGuard.prototype.object=function(arg,code,formatId){return"object"==typeof arg&&null!==arg||throwError(code,formatId),this},ArgumentGuard.prototype.function=function(arg,code,formatId){return"function"!=typeof arg&&throwError(code,formatId),this},ArgumentGuard.prototype.nonEmptyString=function(arg,code,formatId){return"string"==typeof arg&&arg.length||throwError(code,formatId),this},ArgumentGuard.prototype.true=function(arg,code,formatId){return arg||throwError(code,formatId),this},ArgumentGuard.prototype.false=function(arg,code,formatId){return arg&&throwError(code,formatId),this},ArgumentGuard}()),lastUID=0;"function"!=typeof Array.prototype.reduceRight&&(Array.prototype.reduceRight=function(callback){if(null===this||void 0===this)throw new TypeError("Array.prototype.reduce called on null or undefined");if("function"!=typeof callback)throw new TypeError(callback+" is not a function");var value,t=Object(this),k=(t.length>>>0)-1;if(arguments.length>=2)value=arguments[1];else{for(;k>=0&&!(k in t);)k--;if(k<0)throw new TypeError("Reduce of empty array with no initial value");value=t[k--]}for(;k>=0;k--)k in t&&(value=callback(value,t[k],k,t));return value});var HooksSystem=function(){function HooksSystem(){this._plugins=Object.create(null)}return HooksSystem.prototype.createHook=function(type,method,context){guard.nonEmptyString(type,"m16").function(method,"m17",type);var hooksContext=this,result=function(){for(var args=[],_i=0;_i=0){guard.function(this.moduleDidReceiveMessage,"m23",this.sandbox.moduleId);var moduleDidReceiveMessage=core.createHook("onModuleReceiveMessage",this.moduleDidReceiveMessage,this);this.sandbox.unsubscribers=messages.reduce(function(map,message){return map[message]=core.onMessage(message,moduleDidReceiveMessage),map},Object.create(null))}}.call(this)},onModuleDestroy:function(next){(function(){var unsubscribers=this.sandbox.unsubscribers;unsubscribers&&Object.keys(unsubscribers).forEach(function(message){unsubscribers[message](),unsubscribers[message]=null,delete unsubscribers[message]})}).call(this),next()}}}}])}return Object.defineProperty(Core.prototype,"version",{get:function(){return"1.0.1"},enumerable:!0,configurable:!0}),Object.defineProperty(Core.prototype,"extensions",{get:function(){return Object.keys(this._extensions)},enumerable:!0,configurable:!0}),Object.defineProperty(Core.prototype,"modules",{get:function(){return Object.keys(this._modules)},enumerable:!0,configurable:!0}),Object.defineProperty(Core.prototype,"runningModules",{get:function(){var _this=this;return this.modules.reduce(function(result,id){return result[id]=Object.keys(_this._modules[id].instances),result},Object.create(null))},enumerable:!0,configurable:!0}),Core.prototype.use=function(extensions){var _this=this;guard.false(this._isInitialized,"m1").array(extensions,"m2"),extensions.forEach(function(x){guard.object(x,"m3").nonEmptyString(x.name,"m4").function(x.install,"m5",x.name).false(x.name in _this._extensions,"m6",x.name),_this._extensions[x.name]=x})},Core.prototype.createHook=function(type,method,context){return this._hooksSystem.createHook(type,method,context)},Core.prototype.init=function(onInit){guard.false(this._isInitialized,"m7"),this._onInit=this.createHook("onCoreInit",onInit||function(){},this),this._createHooks(),this._installExtensions(),!function(){var state=document.readyState;return"complete"===state||"interactive"===state||"loaded"===state}()?document.addEventListener("DOMContentLoaded",this._onDomReady):setTimeout(this._onDomReady,0),this._isInitialized=!0},Core.prototype.addModule=function(id,factory){guard.nonEmptyString(id,"m8").false(id in this._modules,"m9").function(factory,"m10",id),this._modules[id]={factory:factory,instances:Object.create(null)}},Core.prototype.startModule=function(id,options){void 0===options&&(options={}),guard.true(this._isInitialized,"m11").true(id in this._modules,"m12",id);var moduleData=this._modules[id],instanceId=options.instanceId||id,instance=moduleData.instances[instanceId];if(instance)"function"==typeof instance.moduleDidReceiveProps&&this.createHook("onModuleReceiveProps",instance.moduleDidReceiveProps,instance)(options.props);else if(instance=this._createModule(id,instanceId,moduleData.factory))try{this.createHook("onModuleInit",instance.init,instance)(options.props),moduleData.instances[instanceId]=instance}catch(err){console.error('startModule(): "'+id+'" init failed'),console.error(err)}},Core.prototype.stopModule=function(id,instanceId){var moduleData=this._modules[id];if(moduleData)if((instanceId=instanceId||id)in moduleData.instances)try{var instance=moduleData.instances[instanceId];this.createHook("onModuleDestroy",instance.destroy,instance)(),delete moduleData.instances[instanceId]}catch(err){console.error('stopModule(): "'+id+'" destroy failed'),console.error(err)}else console.warn('stopModule(): "'+id+'"\'s "'+instanceId+'" instance is not running');else console.warn('stopModule(): "'+id+'" not found')},Core.prototype.onMessage=function(type,handler){return this._messageBus.onMessage(type,handler)},Core.prototype.publishAsync=function(message){this._messageBus.publishAsync(message)},Core.prototype._createHooks=function(){this.addModule=this.createHook("onModuleAdd",this.addModule,this),this.startModule=this.createHook("onModuleStart",this.startModule,this),this.stopModule=this.createHook("onModuleStop",this.stopModule,this),this.onMessage=this.createHook("onMessageSubscribe",this.onMessage,this),this.publishAsync=this.createHook("onMessagePublish",this.publishAsync,this)},Core.prototype._installExtensions=function(){var _this=this;Object.keys(this._extensions).forEach(function(name){return _this._install(_this._extensions[name])})},Core.prototype._install=function(extension){var _this=this,plugins=extension.install(this)||{};Object.keys(plugins).forEach(function(hookType){return _this._hooksSystem.addPlugin(hookType,plugins[hookType])})},Core.prototype._onDomReady=function(){document.removeEventListener("DOMContentLoaded",this._onDomReady),this._onInit()},Core.prototype._createModule=function(id,instanceId,factory){var result=null;try{result=factory(new this.Sandbox(this,id,instanceId)),guard.true(result.sandbox instanceof this.Sandbox,"m13",id).function(result.init,"m14",id).function(result.destroy,"m15",id)}catch(err){result=null,console.error(err)}return result},Core}();exports.Core=Core,Object.defineProperty(exports,"__esModule",{value:!0})}); +!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?factory(exports):"function"==typeof define&&define.amd?define(["exports"],factory):factory(global.justcore={})}(this,function(exports){"use strict";function throwError(code,formatId){var msgCreator=errorCodes[code];throw new Error(msgCreator(formatId))}var errorCodes={m1:function(){return"use(): extensions must be installed before init"},m2:function(){return"use(): extensions must be passed as an array"},m3:function(){return"use(): extension must be an object"},m4:function(){return"use(): extension name must be a non empty string"},m5:function(id){return'use(): "'+id+'" install must be a function'},m6:function(id){return'use(): "'+id+'" has already been used'},m7:function(){return"init(): core has already been initialized"},m8:function(){return"addModule(): id must be a non empty string"},m9:function(id){return'addModule(): "'+id+'" has already been added'},m10:function(id){return'addModule(): "'+id+'" factory must be a function'},m11:function(){return"startModule(): core must be initialized first"},m12:function(id){return'startModule(): "'+id+'" not found'},m13:function(id){return'startModule(): "'+id+"\"'s sandbox property must be a Sandbox instance"},m14:function(id){return'startModule(): "'+id+'" init hook must be defined'},m15:function(id){return'startModule(): "'+id+'" destroy hook must be defined'},m16:function(){return"createHook(): type must be a non empty string"},m17:function(id){return'createHook(): "'+id+'" method must be a function'},m18:function(){return"addPlugin(): hook type must be a non empty string"},m19:function(id){return'addPlugin(): "'+id+'" plugin must be a function'},m20:function(){return"onMessage(): message type must be a non empty string"},m21:function(id){return'onMessage(): "'+id+'" handler should be a function'},m22:function(){return"publishAsync(): message must be an object"},m23:function(id){return'"'+id+'" moduleDidReceiveMessage hook must be defined in order to subscribe'}},guard=new(function(){function ArgumentGuard(){}return ArgumentGuard.prototype.array=function(arg,code,formatId){return Array.isArray(arg)||throwError(code,formatId),this},ArgumentGuard.prototype.object=function(arg,code,formatId){return"object"==typeof arg&&null!==arg||throwError(code,formatId),this},ArgumentGuard.prototype.function=function(arg,code,formatId){return"function"!=typeof arg&&throwError(code,formatId),this},ArgumentGuard.prototype.nonEmptyString=function(arg,code,formatId){return"string"==typeof arg&&arg.length||throwError(code,formatId),this},ArgumentGuard.prototype.true=function(arg,code,formatId){return arg||throwError(code,formatId),this},ArgumentGuard.prototype.false=function(arg,code,formatId){return arg&&throwError(code,formatId),this},ArgumentGuard}()),lastUID=0;"function"!=typeof Array.prototype.reduceRight&&(Array.prototype.reduceRight=function(callback){if(null===this||void 0===this)throw new TypeError("Array.prototype.reduce called on null or undefined");if("function"!=typeof callback)throw new TypeError(callback+" is not a function");var value,t=Object(this),k=(t.length>>>0)-1;if(arguments.length>=2)value=arguments[1];else{for(;k>=0&&!(k in t);)k--;if(k<0)throw new TypeError("Reduce of empty array with no initial value");value=t[k--]}for(;k>=0;k--)k in t&&(value=callback(value,t[k],k,t));return value});var HooksSystem=function(){function HooksSystem(){this._plugins=Object.create(null)}return HooksSystem.prototype.createHook=function(type,method,context){guard.nonEmptyString(type,"m16").function(method,"m17",type);var hooksContext=this,result=function(){for(var args=[],_i=0;_i=0){guard.function(this.moduleDidReceiveMessage,"m23",this.sandbox.moduleId);var moduleDidReceiveMessage=core.createHook("onModuleReceiveMessage",this.moduleDidReceiveMessage,this);this.sandbox.unsubscribers=messages.reduce(function(map,message){return map[message]=core.onMessage(message,moduleDidReceiveMessage),map},Object.create(null))}}.call(this)},onModuleDestroy:function(next){(function(){var unsubscribers=this.sandbox.unsubscribers;unsubscribers&&Object.keys(unsubscribers).forEach(function(message){unsubscribers[message](),unsubscribers[message]=null,delete unsubscribers[message]})}).call(this),next()}}}}])}return Object.defineProperty(Core.prototype,"version",{get:function(){return"1.0.2"},enumerable:!0,configurable:!0}),Object.defineProperty(Core.prototype,"extensions",{get:function(){return Object.keys(this._extensions)},enumerable:!0,configurable:!0}),Object.defineProperty(Core.prototype,"modules",{get:function(){return Object.keys(this._modules)},enumerable:!0,configurable:!0}),Object.defineProperty(Core.prototype,"runningModules",{get:function(){var _this=this;return this.modules.reduce(function(result,id){return result[id]=Object.keys(_this._modules[id].instances),result},Object.create(null))},enumerable:!0,configurable:!0}),Core.prototype.use=function(extensions){var _this=this;guard.false(this._isInitialized,"m1").array(extensions,"m2"),extensions.forEach(function(x){guard.object(x,"m3").nonEmptyString(x.name,"m4").function(x.install,"m5",x.name).false(x.name in _this._extensions,"m6",x.name),_this._extensions[x.name]=x})},Core.prototype.createHook=function(type,method,context){return this._hooksSystem.createHook(type,method,context)},Core.prototype.init=function(onInit){guard.false(this._isInitialized,"m7"),this._onInit=this.createHook("onCoreInit",onInit||function(){},this),this._createHooks(),this._installExtensions(),!function(){var state=document.readyState;return"complete"===state||"interactive"===state||"loaded"===state}()?document.addEventListener("DOMContentLoaded",this._onDomReady):setTimeout(this._onDomReady,0),this._isInitialized=!0},Core.prototype.addModule=function(id,factory){guard.nonEmptyString(id,"m8").false(id in this._modules,"m9").function(factory,"m10",id),this._modules[id]={factory:factory,instances:Object.create(null)}},Core.prototype.startModule=function(id,options){void 0===options&&(options={}),guard.true(this._isInitialized,"m11").true(id in this._modules,"m12",id);var moduleData=this._modules[id],instanceId=options.instanceId||id,instance=moduleData.instances[instanceId];if(instance)"function"==typeof instance.moduleDidReceiveProps&&this.createHook("onModuleReceiveProps",instance.moduleDidReceiveProps,instance)(options.props);else if(instance=this._createModule(id,instanceId,moduleData.factory))try{this.createHook("onModuleInit",instance.init,instance)(options.props),moduleData.instances[instanceId]=instance}catch(err){console.error('startModule(): "'+id+'" init failed'),console.error(err)}},Core.prototype.stopModule=function(id,instanceId){var moduleData=this._modules[id];if(moduleData)if((instanceId=instanceId||id)in moduleData.instances)try{var instance=moduleData.instances[instanceId];this.createHook("onModuleDestroy",instance.destroy,instance)(),delete moduleData.instances[instanceId]}catch(err){console.error('stopModule(): "'+id+'" destroy failed'),console.error(err)}else console.warn('stopModule(): "'+id+'"\'s "'+instanceId+'" instance is not running');else console.warn('stopModule(): "'+id+'" not found')},Core.prototype.onMessage=function(type,handler){return this._messageBus.onMessage(type,handler)},Core.prototype.publishAsync=function(message){this._messageBus.publishAsync(message)},Core.prototype._createHooks=function(){this.addModule=this.createHook("onModuleAdd",this.addModule,this),this.startModule=this.createHook("onModuleStart",this.startModule,this),this.stopModule=this.createHook("onModuleStop",this.stopModule,this),this.onMessage=this.createHook("onMessageSubscribe",this.onMessage,this),this.publishAsync=this.createHook("onMessagePublish",this.publishAsync,this)},Core.prototype._installExtensions=function(){var _this=this;Object.keys(this._extensions).forEach(function(name){return _this._install(_this._extensions[name])})},Core.prototype._install=function(extension){var _this=this,plugins=extension.install(this)||{};Object.keys(plugins).forEach(function(hookType){return _this._hooksSystem.addPlugin(hookType,plugins[hookType])})},Core.prototype._onDomReady=function(){document.removeEventListener("DOMContentLoaded",this._onDomReady),this._onInit()},Core.prototype._createModule=function(id,instanceId,factory){var result=null;try{result=factory(new this.Sandbox(this,id,instanceId)),guard.true(result.sandbox instanceof this.Sandbox,"m13",id).function(result.init,"m14",id).function(result.destroy,"m15",id)}catch(err){result=null,console.error(err)}return result},Core}();exports.Core=Core,Object.defineProperty(exports,"__esModule",{value:!0})}); diff --git a/package.json b/package.json index a3e7007..801e134 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "1.0.1", + "version": "1.0.2", "name": "justcore", "main": "dist/justcore.umd.js", "umd:main": "dist/justcore.umd.js",