mirror of https://github.com/lgc-4/DataTools3.git
connector value caching and concatinator
This commit is contained in:
parent
14f95d0165
commit
dddefbcf1d
|
@ -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);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,6 +13,8 @@ class Connector {
|
||||||
|
|
||||||
listeners = [];
|
listeners = [];
|
||||||
|
|
||||||
|
cache;
|
||||||
|
|
||||||
constructor(direction, type, label = null) {
|
constructor(direction, type, label = null) {
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
@ -64,6 +66,10 @@ class Connector {
|
||||||
connect(connector) {
|
connect(connector) {
|
||||||
this.connection = connector;
|
this.connection = connector;
|
||||||
this.element.classList.add("connected");
|
this.element.classList.add("connected");
|
||||||
|
|
||||||
|
if (this.direction == this.INPUT) {
|
||||||
|
this.cache = this.connection.cache;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnect() {
|
disconnect() {
|
||||||
|
@ -79,6 +85,7 @@ class Connector {
|
||||||
|
|
||||||
send(data) {
|
send(data) {
|
||||||
if (!this.connection) return;
|
if (!this.connection) return;
|
||||||
|
this.cache = data;
|
||||||
this.connection.receive(data);
|
this.connection.receive(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +94,7 @@ class Connector {
|
||||||
console.error("invalid type received", data, typeof data, this.type);
|
console.error("invalid type received", data, typeof data, this.type);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.cache = data;
|
||||||
for (let listener of this.listeners) {
|
for (let listener of this.listeners) {
|
||||||
listener(data);
|
listener(data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
<script src="elements/RandomNumberGenerator.js"></script>
|
<script src="elements/RandomNumberGenerator.js"></script>
|
||||||
<script src="elements/NumberBox.js"></script>
|
<script src="elements/NumberBox.js"></script>
|
||||||
<script src="elements/Duplicator.js"></script>
|
<script src="elements/Duplicator.js"></script>
|
||||||
|
<script src="elements/Concatinator.js"></script>
|
||||||
<script src="elements/URLConverter.js"></script>
|
<script src="elements/URLConverter.js"></script>
|
||||||
<script src="controllers/menu-controller.js"></script>
|
<script src="controllers/menu-controller.js"></script>
|
||||||
<script src="controllers/input-controller.js"></script>
|
<script src="controllers/input-controller.js"></script>
|
||||||
|
@ -72,6 +73,7 @@
|
||||||
<div class="elementsGroup">
|
<div class="elementsGroup">
|
||||||
<span>Others</span>
|
<span>Others</span>
|
||||||
<button onclick="addElement(new Duplicator())">Duplicator</button>
|
<button onclick="addElement(new Duplicator())">Duplicator</button>
|
||||||
|
<button onclick="addElement(new Concatinator())">Concatinator</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue