FeatureRequest: Dynamically allow changing nodes
See original GitHub issueJust started working with baklavajs, and it is a great project!
It would be nice however to allow to dynamically change the layout of a node during runtime. Based on an IntegerOption or SelectOption have the number of outputs that have been entered / selected For example:
constructor() {
super();
this.type = 'SplitterNode';
this.name = 'Splitter';
this.addInputInterface('Source');
this.addOption('NrOutputs', 'SelectOption', '4', undefined, {
items: ['2', '4', '6', '8', '16'],
});
}
calculate() {
const outputs = this.getOptionValue('NrOutputs');
outputs.forEach(() => {
this.addOutputInterface('outputPort');
});
}
However, this example does not work, nor when just trying to add a single output (without the .forEach) in the calculate() function.
Use case for me: Not for passing “real data” through the nodes, just as a visual representation of systems / software connected to each other. However this functionality could be useful for other use cases as well, where a calculation may output multiple results and these want to be received on multiple outputs, dynamically based on a selection done on the node. This reduces the need to have dozens of nodes that do basically the same thing, but the only difference is the number of outputs.
Is that possible and within your scope of the project? Thank you
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Hello @LukasLoeffler ,
Thank you very much for this suggestion. Based on that, I’ve created a fork of the Sandbox with added functionnality. I extended it so that not only adding outputs is possible, but also removing then (when selecting a smaller number in the selection). Additionally make the numbering more “human friendly” with starting at 1 instead of 0.
I completely understand that this is a bit hacky, however as an intermediate solution this works fine for me. I am rather new to JS, so my implementation may not be that good. Long-term it would be however very useful to have this functionality in the library itself.
Thank you very much!
@dev-dsp Does the code I posted here work for you? You need to click on “JavaScript Splitter Node” to expand it; then you’ll see the JS code.