diff --git a/elements/Concatinator.js b/elements/Concatinator.js new file mode 100644 index 0000000..d17b1ef --- /dev/null +++ b/elements/Concatinator.js @@ -0,0 +1,22 @@ +class Concatinator extends Box { + constructor() { + super("Concatinator"); + + this.inputs.push(new Connector(Connector.INPUT, "any", "")); + this.inputs.push(new Connector(Connector.INPUT, "any", "")); + + this.outputs.push(new Connector(Connector.OUTPUT, "string", "")); + + for (let input of this.inputs) { + input.addListener((d) => { + let concatinated = ""; + for (let input2 of this.inputs) { + concatinated = concatinated + input2.cache; + } + for (let output of this.outputs) { + output.send(concatinated); + } + }) + } + } +} \ No newline at end of file diff --git a/elements/Connector.js b/elements/Connector.js index bb71256..b9a5ba2 100644 --- a/elements/Connector.js +++ b/elements/Connector.js @@ -13,6 +13,8 @@ class Connector { listeners = []; + cache; + constructor(direction, type, label = null) { this.direction = direction; this.type = type; @@ -64,6 +66,10 @@ class Connector { connect(connector) { this.connection = connector; this.element.classList.add("connected"); + + if (this.direction == this.INPUT) { + this.cache = this.connection.cache; + } } disconnect() { @@ -79,6 +85,7 @@ class Connector { send(data) { if (!this.connection) return; + this.cache = data; this.connection.receive(data); } @@ -87,6 +94,7 @@ class Connector { console.error("invalid type received", data, typeof data, this.type); return; } + this.cache = data; for (let listener of this.listeners) { listener(data); } diff --git a/index.html b/index.html index 978fa9e..37fe91a 100644 --- a/index.html +++ b/index.html @@ -12,6 +12,7 @@ + @@ -72,6 +73,7 @@