Uniqueness of __gohashid


I’m developing a project based on GoJS, and planning to save links ‘references’ in a in-memory structure where I would do some CRUD operations, on the data associated with said links.
For this I would need to use some unique id, could I rely on the __gohashid property that is created for each gojs component? is this id unique?

Later, I’ll implement a diagram cloning feature, managing multiple gojs model diagrams with slightly modifications done by the user (more nodes, different associated data, etc).
I’m not sure if I’ll have conflicts while managing gohashid values across different gojs model diagrams. I think about diagrams having different ids themselves, but the nodes and links should be shared across original and cloned diagrams.
Maybe could I use a composite id using diagram.model.___gohashid and link.__gohashid?
Or is it better to roll a custom ID property on diagram, nodes and links myself?

Thanks for your attention.

That “__gohashid” property is used internally by GoJS and is not meant to be used by programmers, especially not in saved models.

Each object in the Model.nodeDataArray will have a property with a unique identifier that is also used as a key. The name of the property is given by Model.nodeKeyProperty. You can control how it generates new key values by providing a custom Model.makeUniqueKeyFunction.

If you are using GraphLinksModel, you can ensure each link object in the GraphLinksModel.linkDataArray also has a unique identifier/key by setting the GraphLinksModel.linkKeyProperty to be the name of the property you would like to use. And as with node keys, you can customize key generation for link data by setting GraphLinksModel.makeUniqueLinkKeyFunction.

You mention wanting to have unique identifiers across different models. The default behavior only ensures that keys are unique within the model. What some people do is have the keys be GUIDs. However GoJS does not provide any GUID-generating functionality.

Hi Walter

not in saved models

Oh my, I was forgetting that. When saving it is clear that property is not saved at all.

customize key generation

Thanks for the info on that. I was aware of the ‘key’ property, but wasn’t sure it was unique. In another product we do use GUIDs. So I guess I can look for a way to create something akin to that.

And across different models, I want the same ‘object’ to have the same identifier. It is done to compare different values in different ‘scenarios’ of the same diagram.
So, in Diagram A, I would have Node1 with a key of “-1”, and in Diagram B, a Node1 with the same key, “-1”.
If the keys are unique within the model, then that is fine in this use case.

Thanks for the quick and useful response!