1
1
import { getRoot , protect , types , unprotect } from "mobx-state-tree" ;
2
2
import ProcessAttrsMixin from "./ProcessAttrs" ;
3
3
import { parseValue } from "../utils/data" ;
4
+ import { guidGenerator } from "../utils/unique" ;
5
+ import { FF_DEV_3391 } from "../utils/feature-flags" ;
6
+ import { ff } from "@humansignal/core" ;
4
7
5
8
const DynamicChildrenMixin = types
6
9
. model ( { } )
@@ -12,11 +15,19 @@ const DynamicChildrenMixin = types
12
15
} ) )
13
16
. actions ( ( self ) => {
14
17
const prepareDynamicChildrenData = ( data , store , parent ) => {
18
+ // Right now with the FF on, we are traverseing the Tree in the store::initRoot and the
19
+ // AnnotationStore::afterCreate which will generate duplicated children so we only need to
20
+ // run this once, when the annotation store is not yet initialized
21
+ if ( ff . isActive ( FF_DEV_3391 ) && store . annotationStore . initialized ) return ;
22
+
15
23
if ( data && data . length ) {
16
24
for ( const obj of data ) {
25
+ // No matter if using Interactive View mode or not, we add the ids for consistency
26
+ const id = obj . id ?? guidGenerator ( ) ;
17
27
parent . children . push ( {
18
28
type : self . defaultChildType ,
19
29
...obj ,
30
+ id,
20
31
children : [ ] ,
21
32
} ) ;
22
33
@@ -51,9 +62,13 @@ const DynamicChildrenMixin = types
51
62
// we may need to rewrite this, initRoot and the other related methods
52
63
// (actually a lot of them) to work asynchronously as well
53
64
54
- setTimeout ( ( ) => {
65
+ if ( ff . isActive ( FF_DEV_3391 ) ) {
55
66
self . updateDynamicChildren ( store ) ;
56
- } ) ;
67
+ } else {
68
+ setTimeout ( ( ) => {
69
+ self . updateDynamicChildren ( store ) ;
70
+ } ) ;
71
+ }
57
72
} ,
58
73
59
74
updateDynamicChildren ( store ) {
0 commit comments