When I was creating my first nodes, I wanted to avoid repeating my code especially in the frontend definition of nodes. So what I did was create a "base" node that defined a JS hash. I then went on to use that hash in three other nodes: one, two and three nodes. In the package.json I ensured that the base node was initialised first and bobs your uncle, it works well enough in Node-RED.
Where it does not work is on the flows page for the package, those three nodes aren't shown:
I assume that complex JS code isn't executed by the flows site but what is the alternative? How can I avoid repetition and yet have all my nodes displayed on the flow page?
The flows documented in the catalogue, get index using Node JS - not in a Browser window.
What you see at https://flows.nodered.org is the result of a Node JS scheduled task - not a browser.
The website is just showing the indexed data.
Therefore, during index - its likely window is undefined.
This is just my guess of the problem - so could be way off the mark
Honestly, I'm not sure what benefit there is, in having a 'blueprint' - but then I don't know your project, so it maybe beneficial in your circumstance - most nodes I know of, don't have this approach for the definition
Indeed, I also noticed that But since the labelStyle and the oneditXXX callbacks are all the same for all three nodes, I didn't want to repeat the code. I was simply avoiding repetition. If there is another way to do it, then I would do that.
For the JS part of the nodes, I did define a lib to avoid code repetition (and also to have a common memory store). Is there an equivalent approach for the HTML parts of the nodes?
I guess that would be my question: is there an approach for avoiding code repetition when defining the HTML parts of a collection of nodes?
Ok I've updated the package and codebase to remove the window object, I wonder whether there needs to be an update on flows.nr.org to update the node list since the other three nodes are still not shown