Skip to content

Commit

Permalink
sort child features on client side store
Browse files Browse the repository at this point in the history
  • Loading branch information
shashankbrgowda committed Oct 27, 2023
1 parent e0d78b0 commit 143bec6
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/apollo-mst/src/AnnotationFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
SnapshotOrInstance,
cast,
getParentOfType,
getSnapshot,
types,
} from 'mobx-state-tree'

Expand Down Expand Up @@ -143,10 +144,19 @@ export const AnnotationFeature = types
self.strand = strand
},
addChild(childFeature: AnnotationFeatureSnapshot) {
if (!self.children) {
if (self.children && self.children.size > 0) {
const existingChildren = getSnapshot(self.children) ?? {}
self.children.clear()
for (const [, child] of Object.entries({
...existingChildren,
[childFeature._id]: childFeature,
}).sort(([, a], [, b]) => a.start - b.start)) {
self.children.put(child)
}
} else {
self.children = cast({})
self.children?.put(childFeature)
}
self.children?.put(childFeature)
},
deleteChild(childFeatureId: string) {
self.children?.delete(childFeatureId)
Expand Down

0 comments on commit 143bec6

Please sign in to comment.