Here’s what I tried. I do not understand what the problem is.
<!DOCTYPE html>
<html>
<head>
<title>Minimal GoJS Sample</title>
<!-- Copyright 1998-2022 by Northwoods Software Corporation. -->
</head>
<body>
<div id="myDiagramDiv" style="border: solid 1px black; width:100%; height:400px"></div>
<button id="myTestButton">Test</button>
<script src="go.js"></script>
<script id="code">
function init() {
const $ = go.GraphObject.make;
myDiagram =
$(go.Diagram, "myDiagramDiv",
{
"undoManager.isEnabled": true,
"Modified": e => console.log("Modified:" , e.diagram.isModified),
});
console.log("init1:", myDiagram.isModified)
myDiagram.nodeTemplate =
$(go.Node, "Auto",
$(go.Shape,
{ fill: "white", portId: "", fromLinkable: true, toLinkable: true, cursor: "pointer" },
new go.Binding("fill", "color")),
$(go.TextBlock,
{ margin: 8, editable: true },
new go.Binding("text").makeTwoWay())
);
console.log("init2:", myDiagram.isModified)
myDiagram.model = new go.GraphLinksModel(
[
{ key: 1, text: "Alpha", color: "lightblue" },
{ key: 2, text: "Beta", color: "orange" },
],
[
{ from: 1, to: 2 },
]);
console.log("init3:", myDiagram.isModified)
}
document.getElementById("myTestButton").addEventListener("click", e => {
myDiagram.div = null;
init();
setTimeout(() => console.log("afterwards:", myDiagram.isModified), 1000);
});
const $ = go.GraphObject.make;
var myDiagram =
$(go.Diagram, "myDiagramDiv",
{
"undoManager.isEnabled": true,
model: new go.GraphLinksModel(
[
{ key: 1, text: "Alpha" },
{ key: 2, text: "Beta" }
], [
{ from: 1, to: 2 }
])
});
</script>
</body>
</html>
I’m assuming that what happens to the original diagram, before calling init()
, doesn’t matter for this discussion. It’s just the state of the second diagram that you are asking about.
I get the results:
init1: false
init2: true
init3: true
Modified: false
afterwards: false