Skip to content

Commit 376f643

Browse files
author
tamat
committed
fixes to launch onInputAdded or onOutputAdded when configuring node
1 parent b6fb7de commit 376f643

3 files changed

Lines changed: 111 additions & 138 deletions

File tree

build/litegraph.js

Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,43 +2471,34 @@
24712471
this.title = this.constructor.title;
24722472
}
24732473

2474-
if (this.onConnectionsChange) {
2475-
if (this.inputs) {
2476-
for (var i = 0; i < this.inputs.length; ++i) {
2477-
var input = this.inputs[i];
2478-
var link_info = this.graph
2479-
? this.graph.links[input.link]
2480-
: null;
2481-
this.onConnectionsChange(
2482-
LiteGraph.INPUT,
2483-
i,
2484-
true,
2485-
link_info,
2486-
input
2487-
); //link_info has been created now, so its updated
2488-
}
2489-
}
2474+
if (this.inputs) {
2475+
for (var i = 0; i < this.inputs.length; ++i) {
2476+
var input = this.inputs[i];
2477+
var link_info = this.graph ? this.graph.links[input.link] : null;
2478+
if (this.onConnectionsChange)
2479+
this.onConnectionsChange( LiteGraph.INPUT, i, true, link_info, input ); //link_info has been created now, so its updated
24902480

2491-
if (this.outputs) {
2492-
for (var i = 0; i < this.outputs.length; ++i) {
2493-
var output = this.outputs[i];
2494-
if (!output.links) {
2495-
continue;
2496-
}
2497-
for (var j = 0; j < output.links.length; ++j) {
2498-
var link_info = this.graph
2499-
? this.graph.links[output.links[j]]
2500-
: null;
2501-
this.onConnectionsChange(
2502-
LiteGraph.OUTPUT,
2503-
i,
2504-
true,
2505-
link_info,
2506-
output
2507-
); //link_info has been created now, so its updated
2508-
}
2509-
}
2510-
}
2481+
if( this.onInputAdded )
2482+
this.onInputAdded(input);
2483+
2484+
}
2485+
}
2486+
2487+
if (this.outputs) {
2488+
for (var i = 0; i < this.outputs.length; ++i) {
2489+
var output = this.outputs[i];
2490+
if (!output.links) {
2491+
continue;
2492+
}
2493+
for (var j = 0; j < output.links.length; ++j) {
2494+
var link_info = this.graph ? this.graph.links[output.links[j]] : null;
2495+
if (this.onConnectionsChange)
2496+
this.onConnectionsChange( LiteGraph.OUTPUT, i, true, link_info, output ); //link_info has been created now, so its updated
2497+
}
2498+
2499+
if( this.onOutputAdded )
2500+
this.onOutputAdded(output);
2501+
}
25112502
}
25122503

25132504
if( this.widgets )
@@ -3349,26 +3340,26 @@
33493340
* @param {Object} extra_info this can be used to have special properties of an output (label, special color, position, etc)
33503341
*/
33513342
LGraphNode.prototype.addOutput = function(name, type, extra_info) {
3352-
var o = { name: name, type: type, links: null };
3343+
var output = { name: name, type: type, links: null };
33533344
if (extra_info) {
33543345
for (var i in extra_info) {
3355-
o[i] = extra_info[i];
3346+
output[i] = extra_info[i];
33563347
}
33573348
}
33583349

33593350
if (!this.outputs) {
33603351
this.outputs = [];
33613352
}
3362-
this.outputs.push(o);
3353+
this.outputs.push(output);
33633354
if (this.onOutputAdded) {
3364-
this.onOutputAdded(o);
3355+
this.onOutputAdded(output);
33653356
}
33663357

33673358
if (LiteGraph.auto_load_slot_types) LiteGraph.registerNodeAndSlotType(this,type,true);
33683359

33693360
this.setSize( this.computeSize() );
33703361
this.setDirtyCanvas(true, true);
3371-
return o;
3362+
return output;
33723363
};
33733364

33743365
/**
@@ -3440,28 +3431,28 @@
34403431
*/
34413432
LGraphNode.prototype.addInput = function(name, type, extra_info) {
34423433
type = type || 0;
3443-
var o = { name: name, type: type, link: null };
3434+
var input = { name: name, type: type, link: null };
34443435
if (extra_info) {
34453436
for (var i in extra_info) {
3446-
o[i] = extra_info[i];
3437+
input[i] = extra_info[i];
34473438
}
34483439
}
34493440

34503441
if (!this.inputs) {
34513442
this.inputs = [];
34523443
}
34533444

3454-
this.inputs.push(o);
3445+
this.inputs.push(input);
34553446
this.setSize( this.computeSize() );
34563447

34573448
if (this.onInputAdded) {
3458-
this.onInputAdded(o);
3449+
this.onInputAdded(input);
34593450
}
34603451

34613452
LiteGraph.registerNodeAndSlotType(this,type);
34623453

34633454
this.setDirtyCanvas(true, true);
3464-
return o;
3455+
return input;
34653456
};
34663457

34673458
/**

build/litegraph_mini.js

Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,43 +2471,34 @@
24712471
this.title = this.constructor.title;
24722472
}
24732473

2474-
if (this.onConnectionsChange) {
2475-
if (this.inputs) {
2476-
for (var i = 0; i < this.inputs.length; ++i) {
2477-
var input = this.inputs[i];
2478-
var link_info = this.graph
2479-
? this.graph.links[input.link]
2480-
: null;
2481-
this.onConnectionsChange(
2482-
LiteGraph.INPUT,
2483-
i,
2484-
true,
2485-
link_info,
2486-
input
2487-
); //link_info has been created now, so its updated
2488-
}
2489-
}
2474+
if (this.inputs) {
2475+
for (var i = 0; i < this.inputs.length; ++i) {
2476+
var input = this.inputs[i];
2477+
var link_info = this.graph ? this.graph.links[input.link] : null;
2478+
if (this.onConnectionsChange)
2479+
this.onConnectionsChange( LiteGraph.INPUT, i, true, link_info, input ); //link_info has been created now, so its updated
24902480

2491-
if (this.outputs) {
2492-
for (var i = 0; i < this.outputs.length; ++i) {
2493-
var output = this.outputs[i];
2494-
if (!output.links) {
2495-
continue;
2496-
}
2497-
for (var j = 0; j < output.links.length; ++j) {
2498-
var link_info = this.graph
2499-
? this.graph.links[output.links[j]]
2500-
: null;
2501-
this.onConnectionsChange(
2502-
LiteGraph.OUTPUT,
2503-
i,
2504-
true,
2505-
link_info,
2506-
output
2507-
); //link_info has been created now, so its updated
2508-
}
2509-
}
2510-
}
2481+
if( this.onInputAdded )
2482+
this.onInputAdded(input);
2483+
2484+
}
2485+
}
2486+
2487+
if (this.outputs) {
2488+
for (var i = 0; i < this.outputs.length; ++i) {
2489+
var output = this.outputs[i];
2490+
if (!output.links) {
2491+
continue;
2492+
}
2493+
for (var j = 0; j < output.links.length; ++j) {
2494+
var link_info = this.graph ? this.graph.links[output.links[j]] : null;
2495+
if (this.onConnectionsChange)
2496+
this.onConnectionsChange( LiteGraph.OUTPUT, i, true, link_info, output ); //link_info has been created now, so its updated
2497+
}
2498+
2499+
if( this.onOutputAdded )
2500+
this.onOutputAdded(output);
2501+
}
25112502
}
25122503

25132504
if( this.widgets )
@@ -3349,26 +3340,26 @@
33493340
* @param {Object} extra_info this can be used to have special properties of an output (label, special color, position, etc)
33503341
*/
33513342
LGraphNode.prototype.addOutput = function(name, type, extra_info) {
3352-
var o = { name: name, type: type, links: null };
3343+
var output = { name: name, type: type, links: null };
33533344
if (extra_info) {
33543345
for (var i in extra_info) {
3355-
o[i] = extra_info[i];
3346+
output[i] = extra_info[i];
33563347
}
33573348
}
33583349

33593350
if (!this.outputs) {
33603351
this.outputs = [];
33613352
}
3362-
this.outputs.push(o);
3353+
this.outputs.push(output);
33633354
if (this.onOutputAdded) {
3364-
this.onOutputAdded(o);
3355+
this.onOutputAdded(output);
33653356
}
33663357

33673358
if (LiteGraph.auto_load_slot_types) LiteGraph.registerNodeAndSlotType(this,type,true);
33683359

33693360
this.setSize( this.computeSize() );
33703361
this.setDirtyCanvas(true, true);
3371-
return o;
3362+
return output;
33723363
};
33733364

33743365
/**
@@ -3440,28 +3431,28 @@
34403431
*/
34413432
LGraphNode.prototype.addInput = function(name, type, extra_info) {
34423433
type = type || 0;
3443-
var o = { name: name, type: type, link: null };
3434+
var input = { name: name, type: type, link: null };
34443435
if (extra_info) {
34453436
for (var i in extra_info) {
3446-
o[i] = extra_info[i];
3437+
input[i] = extra_info[i];
34473438
}
34483439
}
34493440

34503441
if (!this.inputs) {
34513442
this.inputs = [];
34523443
}
34533444

3454-
this.inputs.push(o);
3445+
this.inputs.push(input);
34553446
this.setSize( this.computeSize() );
34563447

34573448
if (this.onInputAdded) {
3458-
this.onInputAdded(o);
3449+
this.onInputAdded(input);
34593450
}
34603451

34613452
LiteGraph.registerNodeAndSlotType(this,type);
34623453

34633454
this.setDirtyCanvas(true, true);
3464-
return o;
3455+
return input;
34653456
};
34663457

34673458
/**

0 commit comments

Comments
 (0)