litegraph.js
litegraph.js copied to clipboard
[question] How to clear all previously defined nodes?
Hello! You're library is AWESOME
I used to work for sidefx.com and have been in FBP my whole life, and want to build a large amount of tooling around litegraph
however, I'd like to define, if possible, only nodes I'm building and delete the current nodes available to keep the menu and folder structure clean. Is this possible?
I tried using
const registered = Object.keys(LiteGraph.registered_node_types);
registered.forEach(node=>{
LiteGraph.unregisterNodeType(node);
});
Server Error Error: node type not found: basic/time
Hi there! Better to wait Javi's answer but here's an advice: I would include only the litegraph.js file from the src folder, or customize the inclusions in the example editor index.html
Your code actually works from the console here: https://tamats.com/projects/litegraph/editor/ (but fails to remove some formulas that uses a shared node)
The building and packing probably needs some revision, if you're using the npm or the minified version, that it could be a reason.
Nice to have a sidefx dev here ^_^ Because LiteGraph is so cool and thanks to finally have got some big project using it (ComfyUI), a large amount of users actually touches it daily. It's than even more important to try to help and let it grow how it deserve. If you are going to build many tooling around, that would be awesome, and please share some of you works. Let's contribute and join forces for a better quality of life and nodes.
To address your requirement, the correct approach would be to use clearRegisteredTypes instead of unregisterNodeType.
https://github.com/jagenjo/litegraph.js/blob/0555a2f2a3df5d4657593c6d45eb192359888195/src/litegraph.js#L444-L449
The clearRegisteredTypes method will handle multiple internal objects to thoroughly clear out nodes.