@@ -23,15 +23,19 @@ export abstract class AOverlay<T> extends AModel<IOverlay, T> {
23
23
}
24
24
25
25
for ( const anchor of anchors ) {
26
- const dependencies = this . addRelationship ( anchor . getParent ( ) ) ;
27
- dependencies [ 0 ] . addBehavior ( 'overlayId' , DiffAction . ADD , 'MODEL_NAME' , DiffAction . ADD ) ;
28
- dependencies [ 0 ] . addBehavior ( 'overlayId' , DiffAction . ADD , 'MODEL_NAME' , DiffAction . UPDATE ) ;
29
- dependencies [ 1 ] . addBehavior ( 'MODEL_NAME' , DiffAction . DELETE , 'overlayId' , DiffAction . DELETE ) ;
30
-
31
- this . anchors . push ( anchor ) ;
26
+ this . addAnchor ( anchor ) ;
32
27
}
33
28
}
34
29
30
+ addAnchor ( anchor : AAnchor ) : void {
31
+ const dependencies = this . addRelationship ( anchor . getParent ( ) ) ;
32
+ dependencies [ 0 ] . addBehavior ( 'overlayId' , DiffAction . ADD , 'MODEL_NAME' , DiffAction . ADD ) ;
33
+ dependencies [ 0 ] . addBehavior ( 'overlayId' , DiffAction . ADD , 'MODEL_NAME' , DiffAction . UPDATE ) ;
34
+ dependencies [ 1 ] . addBehavior ( 'MODEL_NAME' , DiffAction . DELETE , 'overlayId' , DiffAction . DELETE ) ;
35
+
36
+ this . anchors . push ( anchor ) ;
37
+ }
38
+
35
39
async diff ( previous ?: T ) : Promise < Diff [ ] > {
36
40
const diffs : Diff [ ] = [ ] ;
37
41
@@ -53,6 +57,24 @@ export abstract class AOverlay<T> extends AModel<IOverlay, T> {
53
57
return `${ this . MODEL_NAME } =${ this . overlayId } ` ;
54
58
}
55
59
60
+ removeAnchor ( anchor : AAnchor ) : void {
61
+ const overlayDependencyIndex = this . dependencies . findIndex ( ( d ) => d . from === this && d . to === anchor . getParent ( ) ) ;
62
+ if ( overlayDependencyIndex > - 1 ) {
63
+ this . dependencies . splice ( overlayDependencyIndex , 1 ) ;
64
+ }
65
+ const parentDependencyIndex = anchor
66
+ . getParent ( )
67
+ [ 'dependencies' ] . findIndex ( ( d ) => d . from === anchor . getParent ( ) && d . to === this ) ;
68
+ if ( parentDependencyIndex > - 1 ) {
69
+ anchor . getParent ( ) [ 'dependencies' ] . splice ( parentDependencyIndex , 1 ) ;
70
+ }
71
+
72
+ const anchorIndex = this . anchors . findIndex ( ( a ) => a . anchorId === anchor . anchorId ) ;
73
+ if ( anchorIndex > - 1 ) {
74
+ this . anchors . splice ( anchorIndex , 1 ) ;
75
+ }
76
+ }
77
+
56
78
synth ( ) : IOverlay {
57
79
return {
58
80
anchors : this . anchors . map ( ( a ) => a . synth ( ) ) ,
0 commit comments