1
1
import { ImmutableTree } from "./util/ImmutableTree" ;
2
2
import { Path } from "./util/Path" ;
3
3
import { forEach } from "../../utils/obj" ;
4
- import { NamedNode } from "./snap/Node" ;
4
+ import { Node , NamedNode } from "./snap/Node" ;
5
5
import { PRIORITY_INDEX } from "./snap/indexes/PriorityIndex" ;
6
6
import { assert } from "../../utils/assert" ;
7
7
@@ -15,32 +15,25 @@ import { assert } from "../../utils/assert";
15
15
* @param {!ImmutableTree.<!Node> } writeTree
16
16
*/
17
17
export class CompoundWrite {
18
- writeTree_ ;
19
- constructor ( writeTree ) {
20
- /**
21
- * @type {!ImmutableTree.<!Node> }
22
- * @private
23
- */
24
- this . writeTree_ = writeTree ;
25
- } ;
18
+ constructor ( private writeTree_ : ImmutableTree ) { } ;
26
19
/**
27
20
* @type {!CompoundWrite }
28
21
*/
29
- static Empty = new CompoundWrite (
30
- /** @type {!ImmutableTree.<!Node> } */ ( new ImmutableTree ( null ) )
31
- ) ;
22
+ static Empty = new CompoundWrite ( new ImmutableTree ( null ) ) ;
23
+
32
24
/**
33
25
* @param {!Path } path
34
26
* @param {!Node } node
35
27
* @return {!CompoundWrite }
36
28
*/
37
- addWrite ( path , node ) {
29
+ addWrite ( path : Path , node : Node ) : CompoundWrite {
38
30
if ( path . isEmpty ( ) ) {
39
31
return new CompoundWrite ( new ImmutableTree ( node ) ) ;
40
32
} else {
41
33
var rootmost = this . writeTree_ . findRootMostValueAndPath ( path ) ;
42
34
if ( rootmost != null ) {
43
- var rootMostPath = rootmost . path , value = rootmost . value ;
35
+ var rootMostPath = rootmost . path
36
+ var value = rootmost . value ;
44
37
var relativePath = Path . relativePath ( rootMostPath , path ) ;
45
38
value = value . updateChild ( relativePath , node ) ;
46
39
return new CompoundWrite ( this . writeTree_ . set ( rootMostPath , value ) ) ;
@@ -57,8 +50,8 @@ export class CompoundWrite {
57
50
* @param {!Object.<string, !Node> } updates
58
51
* @return {!CompoundWrite }
59
52
*/
60
- addWrites ( path , updates ) {
61
- var newWrite = < any > this ;
53
+ addWrites ( path : Path , updates : { [ name : string ] : Node } ) : CompoundWrite {
54
+ var newWrite = < CompoundWrite > this ;
62
55
forEach ( updates , function ( childKey , node ) {
63
56
newWrite = newWrite . addWrite ( path . child ( childKey ) , node ) ;
64
57
} ) ;
@@ -72,7 +65,7 @@ export class CompoundWrite {
72
65
* @param {!Path } path The path at which a write and all deeper writes should be removed
73
66
* @return {!CompoundWrite } The new CompoundWrite with the removed path
74
67
*/
75
- removeWrite ( path ) {
68
+ removeWrite ( path : Path ) : CompoundWrite {
76
69
if ( path . isEmpty ( ) ) {
77
70
return CompoundWrite . Empty ;
78
71
} else {
@@ -88,7 +81,7 @@ export class CompoundWrite {
88
81
* @param {!Path } path The path to check for
89
82
* @return {boolean } Whether there is a complete write at that path
90
83
*/
91
- hasCompleteWrite ( path ) {
84
+ hasCompleteWrite ( path : Path ) : boolean {
92
85
return this . getCompleteNode ( path ) != null ;
93
86
} ;
94
87
@@ -99,11 +92,10 @@ export class CompoundWrite {
99
92
* @param {!Path } path The path to get a complete write
100
93
* @return {?Node } The node if complete at that path, or null otherwise.
101
94
*/
102
- getCompleteNode ( path ) {
95
+ getCompleteNode ( path : Path ) : Node {
103
96
var rootmost = this . writeTree_ . findRootMostValueAndPath ( path ) ;
104
97
if ( rootmost != null ) {
105
- return this . writeTree_ . get ( rootmost . path ) . getChild (
106
- Path . relativePath ( rootmost . path , path ) ) ;
98
+ return this . writeTree_ . get ( rootmost . path ) . getChild ( Path . relativePath ( rootmost . path , path ) ) ;
107
99
} else {
108
100
return null ;
109
101
}
@@ -114,7 +106,7 @@ export class CompoundWrite {
114
106
*
115
107
* @return {!Array.<NamedNode> } A list of all complete children.
116
108
*/
117
- getCompleteChildren ( ) {
109
+ getCompleteChildren ( ) : Array < NamedNode > {
118
110
var children = [ ] ;
119
111
var node = this . writeTree_ . value ;
120
112
if ( node != null ) {
@@ -139,7 +131,7 @@ export class CompoundWrite {
139
131
* @param {!Path } path
140
132
* @return {!CompoundWrite }
141
133
*/
142
- childCompoundWrite ( path ) {
134
+ childCompoundWrite ( path : Path ) {
143
135
if ( path . isEmpty ( ) ) {
144
136
return this ;
145
137
} else {
@@ -166,7 +158,7 @@ export class CompoundWrite {
166
158
* @param {!Node } node The node to apply this CompoundWrite to
167
159
* @return {!Node } The node with all writes applied
168
160
*/
169
- apply ( node ) {
161
+ apply ( node : Node ) {
170
162
return CompoundWrite . applySubtreeWrite_ ( Path . Empty , this . writeTree_ , node ) ;
171
163
} ;
172
164
@@ -177,7 +169,7 @@ export class CompoundWrite {
177
169
* @return {!Node }
178
170
* @private
179
171
*/
180
- static applySubtreeWrite_ = function ( relativePath , writeTree , node ) {
172
+ static applySubtreeWrite_ = function ( relativePath : Path , writeTree : ImmutableTree , node : Node ) {
181
173
if ( writeTree . value != null ) {
182
174
// Since there a write is always a leaf, we're done here
183
175
return node . updateChild ( relativePath , writeTree . value ) ;
@@ -195,8 +187,7 @@ export class CompoundWrite {
195
187
} ) ;
196
188
// If there was a priority write, we only apply it if the node is not empty
197
189
if ( ! node . getChild ( relativePath ) . isEmpty ( ) && priorityWrite !== null ) {
198
- node = node . updateChild ( relativePath . child ( '.priority' ) ,
199
- /** @type {!Node } */ ( priorityWrite ) ) ;
190
+ node = node . updateChild ( relativePath . child ( '.priority' ) , priorityWrite ) ;
200
191
}
201
192
return node ;
202
193
}
0 commit comments