@@ -74,11 +74,13 @@ data class NodeObjectData<NodeId>(
74
74
} else {
75
75
// persist ID only to prevent ObjectHash changes when metamodel elements are renamed
76
76
@OptIn(DelicateModelixApi ::class )
77
- if (index < 0 ) {
78
- copy( properties = properties + (role.getIdOrName() to value) )
77
+ val newProperties = if (index < 0 ) {
78
+ properties + (role.getIdOrName() to value)
79
79
} else {
80
- copy( properties = properties .take(index) + (role.getIdOrName() to value) + properties.drop(index + 1 ) )
80
+ properties.take(index) + (role.getIdOrName() to value) + properties.drop(index + 1 )
81
81
}
82
+ // sorted to get a stable ObjectHash and avoid non-determinism in algorithms working with the model (e.g. sync)
83
+ copy(properties = newProperties.sortedBy { it.first })
82
84
}
83
85
}
84
86
@@ -93,11 +95,13 @@ data class NodeObjectData<NodeId>(
93
95
} else {
94
96
// persist ID only to prevent ObjectHash changes when metamodel elements are renamed
95
97
@OptIn(DelicateModelixApi ::class )
96
- if (index < 0 ) {
97
- copy( references = references + (role.getIdOrName() to value) )
98
+ val newReferences = if (index < 0 ) {
99
+ references + (role.getIdOrName() to value)
98
100
} else {
99
- copy( references = references .take(index) + (role.getIdOrName() to value) + references.drop(index + 1 ) )
101
+ references.take(index) + (role.getIdOrName() to value) + references.drop(index + 1 )
100
102
}
103
+ // sorted to get a stable ObjectHash and avoid non-determinism in algorithms working with the model (e.g. sync)
104
+ copy(references = newReferences.sortedBy { it.first })
101
105
}
102
106
}
103
107
@@ -133,8 +137,8 @@ data class NodeObjectData<NodeId>(
133
137
parent = encodeNullId(value.parentId),
134
138
role = value.roleInParent.getIdOrNameOrNull(),
135
139
children = value.children,
136
- properties = value.properties.sortedBy { it.first }. toMap(),
137
- references = value.references.sortedBy { it.first }. toMap(),
140
+ properties = value.properties.toMap(),
141
+ references = value.references.toMap(),
138
142
)
139
143
}
140
144
0 commit comments