@smallstack/components
Advanced tools
Comparing version 0.1.19 to 0.1.20
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@smallstack/common"),require("underscore")):"function"==typeof define&&define.amd?define(["exports","@smallstack/common","underscore"],t):t(e["@smallstack/common"]={},e["@smallstack/common"],e._)}(this,function(e,t,n){"use strict";!function(e){e[e.IN=0]="IN",e[e.OUT=1]="OUT"}(e.ComponentSocketDirection||(e.ComponentSocketDirection={})),function(e){e[e.NUMBER=0]="NUMBER",e[e.NUMBER_ARRAY=1]="NUMBER_ARRAY",e[e.STRING=2]="STRING",e[e.STRING_ARRAY=3]="STRING_ARRAY",e[e.BOOLEAN=4]="BOOLEAN",e[e.BOOLEAN_ARRAY=5]="BOOLEAN_ARRAY",e[e.OBJECT=6]="OBJECT",e[e.OBJECT_ARRAY=7]="OBJECT_ARRAY"}(e.ComponentSocketType||(e.ComponentSocketType={}));var o=function(){function t(){}return t.create=function(e,n,o,i){var c=new t;return c.name=e,c.direction=o,c.type=n,c.values=i,c},t.createInput=function(n,o,i){return t.create(n,o,e.ComponentSocketDirection.IN,i)},t.createOutput=function(n,o,i){return t.create(n,o,e.ComponentSocketDirection.OUT,i)},t.componentSocketTypeToString=function(t){switch(t){case e.ComponentSocketType.BOOLEAN:return"boolean";case e.ComponentSocketType.BOOLEAN_ARRAY:return"boolean[]";case e.ComponentSocketType.NUMBER:return"number";case e.ComponentSocketType.NUMBER_ARRAY:return"number[]";case e.ComponentSocketType.OBJECT:return"object";case e.ComponentSocketType.OBJECT_ARRAY:return"object[]";case e.ComponentSocketType.STRING:return"string";case e.ComponentSocketType.STRING_ARRAY:return"string[]"}throw new Error("UNKNOWN TYPE: "+t)},t}(),i=function(){function e(){this.components={}}return e.instance=function(){return t.IOC.get("componentsRegistry")},e.register=function(e,n){t.IOC.onRegister("componentsRegistry",function(t){t.register(e,n)})},e.prototype.register=function(e,n){t.Logger.info("ComponentsRegistry","Registered component: "+e),this.components[e]=n},e.prototype.getAllComponentNames=function(){return n.keys(this.components)},e.prototype.getAllComponents=function(){return n.values(this.components)},e.prototype.getComponentByName=function(e){var t=this.components[e];if(t)return t;throw new Error("ComponentsRegistry - Could not find component by name: "+e)},e.prototype.isRegistered=function(e){return void 0!==this.components[e]},e.prototype.getComponentsByType=function(e){return n.reject(this.components,function(t){return t.getType()!==e})},e.prototype.getComponentsByTypes=function(e){return n.filter(this.components,function(t){return-1!==e.indexOf(t.getType())})},e}(),c=function(){function e(){this.socketConnections=[],this.socketConnectionCallbacks={},this.afterSocketRegistrationCallbacks={},this.pageEventCallbacks={}}return e.instance=function(){return t.IOC.get("eventService")},e.prototype.addSocketConnection=function(e){t.Logger.debug("EventService","registering socket connection",e),this.socketConnections.push(e)},e.prototype.clearSocketConnections=function(e){void 0===e?(t.Logger.debug("EventService","clearing all socket connections"),this.socketConnections=[]):(t.Logger.debug("EventService","clearing socket connections for componentId '"+e+"'"),this.socketConnections=n.reject(this.socketConnections,function(t){return t.sourceComponentInstanceId===e||t.targetComponentInstanceId===e}))},e.prototype.getSocketConnectionsBySource=function(e,t){return n.filter(this.socketConnections,function(n){return n.sourceComponentInstanceId===e&&n.sourceSocketName===t})},e.prototype.getSocketConnectionsByTarget=function(e,t){return n.filter(this.socketConnections,function(n){return n.targetComponentInstanceId===e&&n.targetSocketName===t})},e.prototype.dispatchSocketEvent=function(e,n,o){for(var i=0,c=this.getSocketConnectionsBySource(e,n);i<c.length;i++){var r=c[i];this.socketConnectionCallbacks[this.getSocketConnectionIdentifier(r.targetComponentInstanceId,r.targetSocketName)]?this.sendSocketEvent(r.targetComponentInstanceId,r.targetSocketName,o):t.Logger.error("EventService","Could not find socket event callback for targetComponentInstanceId '"+r.targetComponentInstanceId+"' and targetSocketName '"+r.targetSocketName+"'!")}},e.prototype.sendSocketEvent=function(e,n,o,i){void 0===i&&(i=!1);var c=this.getSocketConnectionIdentifier(e,n),r=this.socketConnectionCallbacks[c];r?r(o):i?(this.afterSocketRegistrationCallbacks[c]||(this.afterSocketRegistrationCallbacks[c]=[]),this.afterSocketRegistrationCallbacks[c].push(o)):t.Logger.warning("EventService","No callback registered for socketIdentifier '"+c+"'!")},e.prototype.watchSocketEvent=function(e,t,o){var i="dynamic-target-component-"+n.random(-1e4,1e4),c="dynamicAbsorber";this.registerSocketConnectionHandler(i,c,o),this.addSocketConnection({sourceComponentInstanceId:e,sourceSocketName:t,targetComponentInstanceId:i,targetSocketName:c})},e.prototype.dispatchPageEvent=function(e,t){void 0!==this.pageEventCallbacks[e]&&n.each(this.pageEventCallbacks[e],function(e){e(t)})},e.prototype.registerSocketConnectionHandler=function(e,o,i){t.Logger.debug("EventService","Registering "+e+"->"+o);var c=this.getSocketConnectionIdentifier(e,o);this.socketConnectionCallbacks[c]=i,n.each(this.afterSocketRegistrationCallbacks[c],function(e){i(e)}),this.afterSocketRegistrationCallbacks[c]=[]},e.prototype.removeSocketConnectionHandler=function(e,o){var i=this;t.Logger.debug("EventService","Removing socket handler for "+e+"->"+(void 0!==o?o:"[ALL]")),n.each(this.socketConnectionCallbacks,function(t,n){void 0!==o&&n===i.getSocketConnectionIdentifier(e,o)&&delete i.socketConnectionCallbacks[n],void 0===o&&0===n.indexOf(e+"_")&&delete i.socketConnectionCallbacks[n]})},e.prototype.registerPageEventHandler=function(e,t,n){void 0===n&&(n=!1),(void 0===this.pageEventCallbacks[e]||n)&&(this.pageEventCallbacks[e]=[]),this.pageEventCallbacks[e].push(t)},e.prototype.getSocketConnectionIdentifier=function(e,t){if(void 0===e)throw new Error("componentInstanceId is undefined while creating SocketConnectionIdentifier!");if(void 0===t)throw new Error("socketName is undefined while creating SocketConnectionIdentifier!");return e+"_"+t},e}(),r=function(e,t,n,o){var i,c=arguments.length,r=c<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,o);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(r=(c<3?i(r):c>3?i(t,n,r):i(t,n))||r);return c>3&&r&&Object.defineProperty(t,n,r),r},s=function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},a=function(){function n(){this.data={},this.initialized=!1}return n.getSockets=function(){return[]},n.getConfiguration=function(){return[]},n.getComponentName=function(){throw new Error("Please overload the static method BaseComponent.getComponentName()!")},n.register=function(){i.register(this.getComponentName(),this)},n.prototype.init=function(t){var n=this;if(this.initialized)throw new Error("Cannot initialize BaseComponentController twice!");if(t&&(t.componentId&&(this.componentId=t.componentId),t.data&&(this.data=t.data)),"function"==typeof this.getSockets)for(var o=function(t){t.direction===e.ComponentSocketDirection.IN&&c.instance().registerSocketConnectionHandler(i.componentId,t.name,function(e){n.onSocketEvent(t.name,e)})},i=this,r=0,s=this.getSockets();r<s.length;r++){o(s[r])}this.initialized=!0,"function"==typeof this.afterInitialization&&this.afterInitialization()},n.prototype.getData=function(e){if(this.data&&void 0!==this.data[e])return this.data[e]},n.prototype.sendOutput=function(e,n){t.Logger.info("BaseComponent","Sending data:",{componentInstanceId:this.componentId,socketName:e,socketData:n}),this.eventService.dispatchSocketEvent(this.componentId,e,n)},r([t.Autowired(),s("design:type",Object)],n.prototype,"notificationService",void 0),r([t.Autowired(),s("design:type",c)],n.prototype,"eventService",void 0),r([t.Autowired(),s("design:type",Object)],n.prototype,"dataBridge",void 0),n}();!function(e){e[e.ANGULAR=0]="ANGULAR",e[e.REACT=1]="REACT",e[e.INVISIBLE=2]="INVISIBLE",e[e.CMS=3]="CMS"}(e.ComponentType||(e.ComponentType={})),e.BaseComponent=a,e.EventService=c,e.ComponentSocket=o,e.ComponentsRegistry=i,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@smallstack/common"),require("underscore")):"function"==typeof define&&define.amd?define(["exports","@smallstack/common","underscore"],t):t(e["@smallstack/common"]={},e["@smallstack/common"],e._)}(this,function(e,t,n){"use strict";!function(e){e[e.IN=0]="IN",e[e.OUT=1]="OUT"}(e.ComponentSocketDirection||(e.ComponentSocketDirection={})),function(e){e[e.NUMBER=0]="NUMBER",e[e.NUMBER_ARRAY=1]="NUMBER_ARRAY",e[e.STRING=2]="STRING",e[e.STRING_ARRAY=3]="STRING_ARRAY",e[e.BOOLEAN=4]="BOOLEAN",e[e.BOOLEAN_ARRAY=5]="BOOLEAN_ARRAY",e[e.OBJECT=6]="OBJECT",e[e.OBJECT_ARRAY=7]="OBJECT_ARRAY"}(e.ComponentSocketType||(e.ComponentSocketType={}));var o=function(){function t(){}return t.create=function(e,n,o,i){var c=new t;return c.name=e,c.direction=o,c.type=n,c.values=i,c},t.createInput=function(n,o,i){return t.create(n,o,e.ComponentSocketDirection.IN,i)},t.createOutput=function(n,o,i){return t.create(n,o,e.ComponentSocketDirection.OUT,i)},t.componentSocketTypeToString=function(t){switch(t){case e.ComponentSocketType.BOOLEAN:return"boolean";case e.ComponentSocketType.BOOLEAN_ARRAY:return"boolean[]";case e.ComponentSocketType.NUMBER:return"number";case e.ComponentSocketType.NUMBER_ARRAY:return"number[]";case e.ComponentSocketType.OBJECT:return"object";case e.ComponentSocketType.OBJECT_ARRAY:return"object[]";case e.ComponentSocketType.STRING:return"string";case e.ComponentSocketType.STRING_ARRAY:return"string[]"}throw new Error("UNKNOWN TYPE: "+t)},t}(),i=function(){function e(){this.components={}}return e.instance=function(){return t.IOC.get("componentsRegistry")},e.register=function(e,n){t.IOC.onRegister("componentsRegistry",function(t){t.register(e,n)})},e.prototype.register=function(e,n){t.Logger.info("ComponentsRegistry","Registered component: "+e),this.components[e]=n},e.prototype.getAllComponentNames=function(){return n.keys(this.components)},e.prototype.getAllComponents=function(){return n.values(this.components)},e.prototype.getComponentByName=function(e){var t=this.components[e];if(t)return t;throw new Error("ComponentsRegistry - Could not find component by name: "+e)},e.prototype.isRegistered=function(e){return void 0!==this.components[e]},e.prototype.getComponentsByType=function(e){return n.reject(this.components,function(t){return t.getType()!==e})},e.prototype.getComponentsByTypes=function(e){return n.filter(this.components,function(t){return-1!==e.indexOf(t.getType())})},e}(),c=function(){function e(){this.socketConnections=[],this.socketConnectionCallbacks={},this.afterSocketRegistrationCallbacks={},this.pageEventCallbacks={}}return e.instance=function(){return t.IOC.get("eventService")},e.prototype.addSocketConnection=function(e){t.Logger.debug("EventService","registering socket connection",e),this.socketConnections.push(e)},e.prototype.clearSocketConnections=function(e){void 0===e?(t.Logger.debug("EventService","clearing all socket connections"),this.socketConnections=[]):(t.Logger.debug("EventService","clearing socket connections for componentId '"+e+"'"),this.socketConnections=n.reject(this.socketConnections,function(t){return t.sourceComponentInstanceId===e||t.targetComponentInstanceId===e}))},e.prototype.getSocketConnectionsBySource=function(e,t){return n.filter(this.socketConnections,function(n){return n.sourceComponentInstanceId===e&&n.sourceSocketName===t})},e.prototype.getSocketConnectionsByTarget=function(e,t){return n.filter(this.socketConnections,function(n){return n.targetComponentInstanceId===e&&n.targetSocketName===t})},e.prototype.dispatchSocketEvent=function(e,n,o){for(var i=0,c=this.getSocketConnectionsBySource(e,n);i<c.length;i++){var r=c[i];this.socketConnectionCallbacks[this.getSocketConnectionIdentifier(r.targetComponentInstanceId,r.targetSocketName)]?this.sendSocketEvent(r.targetComponentInstanceId,r.targetSocketName,o):t.Logger.error("EventService","Could not find socket event callback for targetComponentInstanceId '"+r.targetComponentInstanceId+"' and targetSocketName '"+r.targetSocketName+"'!")}},e.prototype.sendSocketEvent=function(e,n,o,i){void 0===i&&(i=!1);var c=this.getSocketConnectionIdentifier(e,n),r=this.socketConnectionCallbacks[c];r?r(o):i?(this.afterSocketRegistrationCallbacks[c]||(this.afterSocketRegistrationCallbacks[c]=[]),this.afterSocketRegistrationCallbacks[c].push(o)):t.Logger.warning("EventService","No callback registered for socketIdentifier '"+c+"'!")},e.prototype.watchSocketEvent=function(e,t,o){var i="dynamic-target-component-"+n.random(-1e4,1e4),c="dynamicAbsorber";this.registerSocketConnectionHandler(i,c,o),this.addSocketConnection({sourceComponentInstanceId:e,sourceSocketName:t,targetComponentInstanceId:i,targetSocketName:c})},e.prototype.dispatchPageEvent=function(e,t){void 0!==this.pageEventCallbacks[e]&&n.each(this.pageEventCallbacks[e],function(e){e(t)})},e.prototype.registerSocketConnectionHandler=function(e,o,i){t.Logger.debug("EventService","Registering "+e+"->"+o);var c=this.getSocketConnectionIdentifier(e,o);this.socketConnectionCallbacks[c]=i,n.each(this.afterSocketRegistrationCallbacks[c],function(e){i(e)}),this.afterSocketRegistrationCallbacks[c]=[]},e.prototype.removeSocketConnectionHandler=function(e,o){var i=this;t.Logger.debug("EventService","Removing socket handler for "+e+"->"+(void 0!==o?o:"[ALL]")),n.each(this.socketConnectionCallbacks,function(t,n){void 0!==o&&n===i.getSocketConnectionIdentifier(e,o)&&delete i.socketConnectionCallbacks[n],void 0===o&&0===n.indexOf(e+"_")&&delete i.socketConnectionCallbacks[n]})},e.prototype.registerPageEventHandler=function(e,t,n){void 0===n&&(n=!1),(void 0===this.pageEventCallbacks[e]||n)&&(this.pageEventCallbacks[e]=[]),this.pageEventCallbacks[e].push(t)},e.prototype.getSocketConnectionIdentifier=function(e,t){if(void 0===e)throw new Error("componentInstanceId is undefined while creating SocketConnectionIdentifier!");if(void 0===t)throw new Error("socketName is undefined while creating SocketConnectionIdentifier!");return e+"_"+t},e}(),r=function(e,t,n,o){var i,c=arguments.length,r=c<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,o);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(r=(c<3?i(r):c>3?i(t,n,r):i(t,n))||r);return c>3&&r&&Object.defineProperty(t,n,r),r},s=function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},a=function(){function n(){this.data={},this.initialized=!1}return n.getSockets=function(){return[]},n.getConfiguration=function(){return[]},n.getComponentName=function(){return"UnnamedComponent"},n.register=function(){i.register(this.getComponentName(),this)},n.prototype.init=function(t){var n=this;if(this.initialized)throw new Error("Cannot initialize BaseComponentController twice!");if(t&&(t.componentId&&(this.componentId=t.componentId),t.data&&(this.data=t.data)),"function"==typeof this.getSockets)for(var o=function(t){t.direction===e.ComponentSocketDirection.IN&&c.instance().registerSocketConnectionHandler(i.componentId,t.name,function(e){n.onSocketEvent(t.name,e)})},i=this,r=0,s=this.getSockets();r<s.length;r++){o(s[r])}this.initialized=!0,"function"==typeof this.afterInitialization&&this.afterInitialization()},n.prototype.getData=function(e){if(this.data&&void 0!==this.data[e])return this.data[e]},n.prototype.sendOutput=function(e,n){t.Logger.info("BaseComponent","Sending data:",{componentInstanceId:this.componentId,socketName:e,socketData:n}),this.eventService.dispatchSocketEvent(this.componentId,e,n)},r([t.Autowired(),s("design:type",Object)],n.prototype,"notificationService",void 0),r([t.Autowired(),s("design:type",c)],n.prototype,"eventService",void 0),r([t.Autowired(),s("design:type",Object)],n.prototype,"dataBridge",void 0),n}();!function(e){e[e.ANGULAR=0]="ANGULAR",e[e.REACT=1]="REACT",e[e.INVISIBLE=2]="INVISIBLE",e[e.CMS=3]="CMS"}(e.ComponentType||(e.ComponentType={})),e.BaseComponent=a,e.EventService=c,e.ComponentSocket=o,e.ComponentsRegistry=i,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "@smallstack/components", | ||
"version": "0.1.19", | ||
"version": "0.1.20", | ||
"description": "Base functionality for smallstack components", | ||
@@ -5,0 +5,0 @@ "main": "dist/bundle/index.umd.js", |
Sorry, the diff of this file is not supported yet
46451