@smallstack/components
Advanced tools
Comparing version 0.1.9 to 0.1.10
@@ -9,3 +9,7 @@ import { DataBridge } from "@smallstack/common"; | ||
static registerComponent(): void; | ||
componentId: string; | ||
protected dataBridge: DataBridge; | ||
private initialized; | ||
setComponentId(componentId: string): void; | ||
sendOutput(socketName: string, socketData: any): void; | ||
} |
export * from "./BaseComponent"; | ||
export * from "./EventService"; | ||
export * from "./InitializationAware"; | ||
export * from "./SocketEventAware"; | ||
export * from "./ComponentType"; | ||
export * from "./ComponentSocket"; |
@@ -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";var o=function(e,t,n,o){var c,r=arguments.length,i=r<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,n,o);else for(var a=e.length-1;a>=0;a--)(c=e[a])&&(i=(r<3?c(i):r>3?c(t,n,i):c(t,n))||i);return r>3&&i&&Object.defineProperty(t,n,i),i},c=function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},r=function(){function e(){}return e.getSockets=function(){return[]},e.getConfiguration=function(){return[]},e.getComponentName=function(){return this.constructor.name},e.registerComponent=function(){t.IOC.get("componentsRegistry").addComponent(this)},o([t.Autowired(),c("design:type",Object)],e.prototype,"dataBridge",void 0),e}(),i=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,o,c){var r=this;n.each(this.getSocketConnectionsBySource(e,o),function(e){r.socketConnectionCallbacks[r.getSocketConnectionIdentifier(e.targetComponentInstanceId,e.targetSocketName)]?r.sendSocketEvent(e.targetComponentInstanceId,e.targetSocketName,c):t.Logger.error("EventService","Could not find socket event callback for targetComponentInstanceId '"+e.targetComponentInstanceId+"' and targetSocketName '"+e.targetSocketName+"'!")})},e.prototype.sendSocketEvent=function(e,n,o,c){void 0===c&&(c=!1);var r=this.getSocketConnectionIdentifier(e,n),i=this.socketConnectionCallbacks[r];i?i(o):c?(this.afterSocketRegistrationCallbacks[r]||(this.afterSocketRegistrationCallbacks[r]=[]),this.afterSocketRegistrationCallbacks[r].push(o)):t.Logger.warning("EventService","No callback registered for socketIdentifier '"+r+"'!")},e.prototype.watchSocketEvent=function(e,t,n){var o=chance.guid();this.registerSocketConnectionHandler(o,"dynamicAbsorber",n),this.addSocketConnection({sourceComponentInstanceId:e,sourceSocketName:t,targetComponentInstanceId:o,targetSocketName:"dynamicAbsorber"})},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,c){t.Logger.debug("EventService","Registering "+e+"->"+o);var r=this.getSocketConnectionIdentifier(e,o);this.socketConnectionCallbacks[r]=c,n.each(this.afterSocketRegistrationCallbacks[r],function(e){c(e)}),this.afterSocketRegistrationCallbacks[r]=[]},e.prototype.removeSocketConnectionHandler=function(e,o){var c=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===c.getSocketConnectionIdentifier(e,o)&&delete c.socketConnectionCallbacks[n],void 0===o&&0===n.indexOf(e+"_")&&delete c.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}();!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={})),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 a=function(){function t(){}return t.create=function(e,n,o,c){var r=new t;return r.name=e,r.direction=o,r.type=n,r.values=c,r},t.createInput=function(n,o,c){return t.create(n,o,e.ComponentSocketDirection.IN,c)},t.createOutput=function(n,o,c){return t.create(n,o,e.ComponentSocketDirection.OUT,c)},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}();e.BaseComponent=r,e.EventService=i,e.ComponentSocket=a,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@smallstack/common"),require("underscore"),require("chance")):"function"==typeof define&&define.amd?define(["exports","@smallstack/common","underscore","chance"],t):t(e["@smallstack/common"]={},e["@smallstack/common"],e._,e.chance)}(this,function(e,t,n,o){"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 c=function(){function t(){}return t.create=function(e,n,o,c){var i=new t;return i.name=e,i.direction=o,i.type=n,i.values=c,i},t.createInput=function(n,o,c){return t.create(n,o,e.ComponentSocketDirection.IN,c)},t.createOutput=function(n,o,c){return t.create(n,o,e.ComponentSocketDirection.OUT,c)},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.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,o,c){var i=this;n.each(this.getSocketConnectionsBySource(e,o),function(e){i.socketConnectionCallbacks[i.getSocketConnectionIdentifier(e.targetComponentInstanceId,e.targetSocketName)]?i.sendSocketEvent(e.targetComponentInstanceId,e.targetSocketName,c):t.Logger.error("EventService","Could not find socket event callback for targetComponentInstanceId '"+e.targetComponentInstanceId+"' and targetSocketName '"+e.targetSocketName+"'!")})},e.prototype.sendSocketEvent=function(e,n,o,c){void 0===c&&(c=!1);var i=this.getSocketConnectionIdentifier(e,n),r=this.socketConnectionCallbacks[i];r?r(o):c?(this.afterSocketRegistrationCallbacks[i]||(this.afterSocketRegistrationCallbacks[i]=[]),this.afterSocketRegistrationCallbacks[i].push(o)):t.Logger.warning("EventService","No callback registered for socketIdentifier '"+i+"'!")},e.prototype.watchSocketEvent=function(e,t,n){var c=(new o.Chance).guid();this.registerSocketConnectionHandler(c,"dynamicAbsorber",n),this.addSocketConnection({sourceComponentInstanceId:e,sourceSocketName:t,targetComponentInstanceId:c,targetSocketName:"dynamicAbsorber"})},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,c){t.Logger.debug("EventService","Registering "+e+"->"+o);var i=this.getSocketConnectionIdentifier(e,o);this.socketConnectionCallbacks[i]=c,n.each(this.afterSocketRegistrationCallbacks[i],function(e){c(e)}),this.afterSocketRegistrationCallbacks[i]=[]},e.prototype.removeSocketConnectionHandler=function(e,o){var c=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===c.getSocketConnectionIdentifier(e,o)&&delete c.socketConnectionCallbacks[n],void 0===o&&0===n.indexOf(e+"_")&&delete c.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 c,i=arguments.length,r=i<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 a=e.length-1;a>=0;a--)(c=e[a])&&(r=(i<3?c(r):i>3?c(t,n,r):c(t,n))||r);return i>3&&r&&Object.defineProperty(t,n,r),r},a=function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},s=function(){function n(){this.initialized=!1}return n.getSockets=function(){return[]},n.getConfiguration=function(){return[]},n.getComponentName=function(){return this.constructor.name},n.registerComponent=function(){t.IOC.get("componentsRegistry").addComponent(this)},n.prototype.setComponentId=function(t){var n=this;if(this.initialized)throw new Error("Cannot initialize BaseComponentController twice!");if(this.componentId=t,"function"==typeof this.afterInitialization&&this.afterInitialization(),"function"==typeof this.getSockets)for(var o=this,c=0,r=this.getSockets();c<r.length;c++)!function(t){t.direction===e.ComponentSocketDirection.IN&&i.instance().registerSocketConnectionHandler(o.componentId,t.name,function(e){n.onSocketEvent(t.name,e)})}(r[c]);this.initialized=!0},n.prototype.sendOutput=function(e,n){t.Logger.info("BaseComponent","Sending data:",{componentInstanceId:this.componentId,socketName:e,socketData:n}),i.instance().dispatchSocketEvent(this.componentId,e,n)},r([t.Autowired(),a("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=s,e.EventService=i,e.ComponentSocket=c,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "@smallstack/components", | ||
"version": "0.1.9", | ||
"version": "0.1.10", | ||
"description": "Base functionality for smallstack components", | ||
@@ -16,3 +16,4 @@ "main": "dist/bundle/index.umd.js", | ||
"copydts": "copyfiles -e \"dist/bundle/**/*\" -u 1 \"dist/**/*.d.ts\" ./dist/bundle/dts", | ||
"ci-publish": "ci-publish" | ||
"ci-publish": "ci-publish", | ||
"watch": "nodemon -e ts --ignore dist/ --ignore node_modules/ --exec \"npm run bundle\"" | ||
}, | ||
@@ -26,4 +27,6 @@ "repository": { | ||
"devDependencies": { | ||
"@types/chance": "^0.7.35", | ||
"ci-publish": "1.3.0", | ||
"copyfiles": "1.2.0", | ||
"nodemon": "^1.12.1", | ||
"rimraf": "^2.6.1", | ||
@@ -37,2 +40,3 @@ "rollup": "0.49.3", | ||
"@smallstack/common": "0.1.7", | ||
"chance": "^1.0.11", | ||
"underscore": "1.8.3", | ||
@@ -39,0 +43,0 @@ "window-or-global": "1.0.1" |
Sorry, the diff of this file is not supported yet
40640
15
188
4
9
+ Addedchance@^1.0.11
+ Addedchance@1.1.12(transitive)