From a user's perspective, there's no issue here if advancedMath also defines the add node, since they always know which one they're using based on which kit object they're referencing.
However, this is not the case for node execution or serialization.
Solving this should not prevent a board from being JSON.stringified, so we can't just change NodeTypeIdentifier to be a reference to the kit's function for that node. Here are a few options:
Change NodeTypeIdentifier from string to { nodeType: string, kitUrl: string }:
+ Nodes are unique across kits even if they have the same nodeType.
+ A saved graph now includes the kit urls.
- Harder to load the same kit from a different url.
- Kits must have URLs.
+- Harder to look up handlers for nodes, as you must first look up the kit by url and then the handler (although this is kind of the point)
--- Breaking change
Change NodeTypeIdentifier from string to { nodeType: string, kitName: string }:
+ Nodes are unique across kits even if they have the same nodeType.
+ The same kit can be loaded from different URLs
+- Harder to look up handlers for nodes, as you must first look up the kit by name and then the handler (although this is kind of the point)
- Kits must have names.
--- Breaking change
Change NodeTypeIdentifier from string to ${string}_${string} where the first part is the kit name and the second is the node type.
+ Nodes are unique across kits even if they have the same nodeType.
+ Still easy to look up handlers for nodes since we can still have a flat object of all the handlers.
- Somewhat mangled NodeType.
- Breaking change, but not as much as the other ones.
In TypeScript,
kits
provide a nice intrinsic implementation of namespacing by being separate objects:From a user's perspective, there's no issue here if
advancedMath
also defines theadd
node, since they always know which one they're using based on which kit object they're referencing.However, this is not the case for node execution or serialization.
Node execution first concatenates all the NodeHandlers from all the loaded kits into a single object. Then, it looks up each node by type to find its node handler. This means if two kits define a node with the same NodeTypeIdentifier, the last one loaded into Breadboard will be the one that actually gets run, and the first one will always be unused. (Other notes: TraversalMachine takes a GraphDescriptor, which is JSON-serializable).
This also means that serialization doesn't account for NodeTypeIdentifier collisions, since serialization is conveniently just to JSON.stringify the board.
Solving this should not prevent a board from being JSON.stringified, so we can't just change
NodeTypeIdentifier
to be a reference to the kit's function for that node. Here are a few options:Change
NodeTypeIdentifier
fromstring
to{ nodeType: string, kitUrl: string }
:Change
NodeTypeIdentifier
fromstring
to{ nodeType: string, kitName: string }
:Change
NodeTypeIdentifier
fromstring
to${string}_${string}
where the first part is the kit name and the second is the node type.