Update Node Template after creation

I have a use case where I want to programmatically add some event handlers to all the nodes after the diagram is created. Apart from that, I also want to do things like, changing the node shape etc. as an update. Is it possible to basically update the nodeTemplate once the diagram is created.

diagram.nodeTemplate.click = () => console.log("Node clicked") 

does not seem to work.

I want to do something similar.

Please help me out.


Yes, each template is copied when the Node (or Link) is created and added to the diagram. You are thus not supposed to make changes to a template once it has been instantiated.

For the event handlers, would it not be easier to always have them be defined? Just make them return (i.e. be a no-op) if the circumstance is that they should not have been defined yet.

For changing properties, could you just use a data Binding?

Actually I am building a wrapper and want the users to be able to extend the node templates I provide. I have handled the same by exposing the templates itself which the users can extend.

Do you have any suggestions in this regard?

What kind of “wrapper” do you envision? Will they need to learn the GoJS API? That is unlikely to be acceptable for almost all users. And then they each would need to purchase a development license.

Yes we are in the process of buying the development license for our entire firm i.e. the group license. What I want is to create is a React wrapper similar to the ReactDiagram but with some basic commonly used utilities such as nodeTemplates etc.

We plan to provide some basic node templates which the users may extend such as adding click events to nodes etc.

You can certainly set the click property on individual nodes in your diagram, at any time.

But doing so on the node template will not affect the behavior of any existing node. It will affect any newly created nodes.