There is no problem if I get the model from a real diagram by using the way any sample provided. However, I get following log warning now.
LOG: ‘Warning: found GraphObject or Diagram reference when copying model data on property “port” of data object: Node#1114
Model data should not have any references to a Diagram or any part of a diagram, such as: Node#1114’
LOG: ‘Warning: found GraphObject or Diagram reference when copying model data on property “bc” of data object: Node#1114
Model data should not have any references to a Diagram or any part of a diagram, such as: Node#1114’
LOG: ‘Warning: found GraphObject or Diagram reference when copying model data on property “locationObject” of data object: Node#1114
Model data should not have any references to a Diagram or any part of a diagram, such as: Node#1114’
LOG: ‘Warning: found GraphObject or Diagram reference when copying model data on property “self” of data object: Node#1114
Model data should not have any references to a Diagram or any part of a diagram, such as: Node#1114’
Any idea? This won’t break the test but just a little bit annoying.
No, that warning is important for you to recognize that something is very wrong.
In this case it should be clear that you are trying to add a Node to the model, rather than some node data, a JavaScript Object.
Each Node should belong to a Diagram.
Each Node.data object should belong to a Model. (Actually it will be in its Model.nodeDataArray.)
The whole point of models is that in a model-view architecture there should be no references to a view within the model. There are many advantages of maintaining such a separation, including the ability to easily serialize the model.
The parameter of copyNodeData is required to be a Node. The output is the copied data with it and will be add to model later. So are you saying that I cannot create a node by using node constructor but must bind a node to a diagram?
Can you help me modify the usage of my code? I don’t want to create a view since I only want to test the model part. How should I do the correct thing in order to add a nodedata correctly to a model without any view/diagram?
I change my code to following now. But get different error now. I am using Karma + PhantomJS + Jasmine for my test.
TypeError: Attempted to assign to readonly property.
let model = new go.GraphLinksModel();
let node = new go.Node();
let nodeData = model.copyNodeData(node.data); // no warning now nodeData[“test”] = “something”; // error here
The word “represent” derives from the word “present”. If “X is represented by Y”, then Y presents a symbol or rendering of X. In GoJS (or any model-view system) X is some piece of data or computer-memory and Y is what you see on screen or paper. Ceci n’est pas une pipe