@@ -28,22 +28,12 @@ import { each } from './util/util';
28
28
* dealing with priority writes and multiple nested writes. At any given path there is only allowed to be one write
29
29
* modifying that path. Any write to an existing path or shadowing an existing path will modify that existing write
30
30
* to reflect the write added.
31
- *
32
- * @constructor
33
- * @param {!ImmutableTree.<!Node> } writeTree
34
31
*/
35
32
export class CompoundWrite {
36
33
constructor ( private writeTree_ : ImmutableTree < Node > ) { }
37
- /**
38
- * @type {!CompoundWrite }
39
- */
34
+
40
35
static Empty = new CompoundWrite ( new ImmutableTree ( null ) ) ;
41
36
42
- /**
43
- * @param {!Path } path
44
- * @param {!Node } node
45
- * @return {!CompoundWrite }
46
- */
47
37
addWrite ( path : Path , node : Node ) : CompoundWrite {
48
38
if ( path . isEmpty ( ) ) {
49
39
return new CompoundWrite ( new ImmutableTree ( node ) ) ;
@@ -63,11 +53,6 @@ export class CompoundWrite {
63
53
}
64
54
}
65
55
66
- /**
67
- * @param {!Path } path
68
- * @param {!Object.<string, !Node> } updates
69
- * @return {!CompoundWrite }
70
- */
71
56
addWrites ( path : Path , updates : { [ name : string ] : Node } ) : CompoundWrite {
72
57
let newWrite = this as CompoundWrite ;
73
58
each ( updates , function ( childKey : string , node : Node ) {
@@ -80,7 +65,7 @@ export class CompoundWrite {
80
65
* Will remove a write at the given path and deeper paths. This will <em>not</em> modify a write at a higher
81
66
* location, which must be removed by calling this method with that path.
82
67
*
83
- * @param { !Path } path The path at which a write and all deeper writes should be removed
68
+ * @param path The path at which a write and all deeper writes should be removed
84
69
* @return {!CompoundWrite } The new CompoundWrite with the removed path
85
70
*/
86
71
removeWrite ( path : Path ) : CompoundWrite {
@@ -96,8 +81,8 @@ export class CompoundWrite {
96
81
* Returns whether this CompoundWrite will fully overwrite a node at a given location and can therefore be
97
82
* considered "complete".
98
83
*
99
- * @param { !Path } path The path to check for
100
- * @return { boolean } Whether there is a complete write at that path
84
+ * @param path The path to check for
85
+ * @return Whether there is a complete write at that path
101
86
*/
102
87
hasCompleteWrite ( path : Path ) : boolean {
103
88
return this . getCompleteNode ( path ) != null ;
@@ -107,8 +92,8 @@ export class CompoundWrite {
107
92
* Returns a node for a path if and only if the node is a "complete" overwrite at that path. This will not aggregate
108
93
* writes from deeper paths, but will return child nodes from a more shallow path.
109
94
*
110
- * @param { !Path } path The path to get a complete write
111
- * @return { ?Node } The node if complete at that path, or null otherwise.
95
+ * @param path The path to get a complete write
96
+ * @return The node if complete at that path, or null otherwise.
112
97
*/
113
98
getCompleteNode ( path : Path ) : Node | null {
114
99
const rootmost = this . writeTree_ . findRootMostValueAndPath ( path ) ;
@@ -124,9 +109,9 @@ export class CompoundWrite {
124
109
/**
125
110
* Returns all children that are guaranteed to be a complete overwrite.
126
111
*
127
- * @return { !Array.<NamedNode> } A list of all complete children.
112
+ * @return A list of all complete children.
128
113
*/
129
- getCompleteChildren ( ) : Array < NamedNode > {
114
+ getCompleteChildren ( ) : NamedNode [ ] {
130
115
const children : NamedNode [ ] = [ ] ;
131
116
let node = this . writeTree_ . value ;
132
117
if ( node != null ) {
@@ -149,10 +134,6 @@ export class CompoundWrite {
149
134
return children ;
150
135
}
151
136
152
- /**
153
- * @param {!Path } path
154
- * @return {!CompoundWrite }
155
- */
156
137
childCompoundWrite ( path : Path ) : CompoundWrite {
157
138
if ( path . isEmpty ( ) ) {
158
139
return this ;
@@ -168,7 +149,7 @@ export class CompoundWrite {
168
149
169
150
/**
170
151
* Returns true if this CompoundWrite is empty and therefore does not modify any nodes.
171
- * @return { boolean } Whether this CompoundWrite is empty
152
+ * @return Whether this CompoundWrite is empty
172
153
*/
173
154
isEmpty ( ) : boolean {
174
155
return this . writeTree_ . isEmpty ( ) ;
@@ -177,52 +158,41 @@ export class CompoundWrite {
177
158
/**
178
159
* Applies this CompoundWrite to a node. The node is returned with all writes from this CompoundWrite applied to the
179
160
* node
180
- * @param { !Node } node The node to apply this CompoundWrite to
181
- * @return { !Node } The node with all writes applied
161
+ * @param node The node to apply this CompoundWrite to
162
+ * @return The node with all writes applied
182
163
*/
183
164
apply ( node : Node ) : Node {
184
- return CompoundWrite . applySubtreeWrite_ ( Path . Empty , this . writeTree_ , node ) ;
165
+ return applySubtreeWrite ( Path . Empty , this . writeTree_ , node ) ;
185
166
}
167
+ }
186
168
187
- /**
188
- * @param {!Path } relativePath
189
- * @param {!ImmutableTree.<!Node> } writeTree
190
- * @param {!Node } node
191
- * @return {!Node }
192
- * @private
193
- */
194
- private static applySubtreeWrite_ = function (
195
- relativePath : Path ,
196
- writeTree : ImmutableTree < Node > ,
197
- node : Node
198
- ) : Node {
199
- if ( writeTree . value != null ) {
200
- // Since there a write is always a leaf, we're done here
201
- return node . updateChild ( relativePath , writeTree . value ) ;
202
- } else {
203
- let priorityWrite = null ;
204
- writeTree . children . inorderTraversal ( function ( childKey , childTree ) {
205
- if ( childKey === '.priority' ) {
206
- // Apply priorities at the end so we don't update priorities for either empty nodes or forget
207
- // to apply priorities to empty nodes that are later filled
208
- assert (
209
- childTree . value !== null ,
210
- 'Priority writes must always be leaf nodes'
211
- ) ;
212
- priorityWrite = childTree . value ;
213
- } else {
214
- node = CompoundWrite . applySubtreeWrite_ (
215
- relativePath . child ( childKey ) ,
216
- childTree ,
217
- node
218
- ) ;
219
- }
220
- } ) ;
221
- // If there was a priority write, we only apply it if the node is not empty
222
- if ( ! node . getChild ( relativePath ) . isEmpty ( ) && priorityWrite !== null ) {
223
- node = node . updateChild ( relativePath . child ( '.priority' ) , priorityWrite ) ;
169
+ function applySubtreeWrite (
170
+ relativePath : Path ,
171
+ writeTree : ImmutableTree < Node > ,
172
+ node : Node
173
+ ) : Node {
174
+ if ( writeTree . value != null ) {
175
+ // Since there a write is always a leaf, we're done here
176
+ return node . updateChild ( relativePath , writeTree . value ) ;
177
+ } else {
178
+ let priorityWrite = null ;
179
+ writeTree . children . inorderTraversal ( function ( childKey , childTree ) {
180
+ if ( childKey === '.priority' ) {
181
+ // Apply priorities at the end so we don't update priorities for either empty nodes or forget
182
+ // to apply priorities to empty nodes that are later filled
183
+ assert (
184
+ childTree . value !== null ,
185
+ 'Priority writes must always be leaf nodes'
186
+ ) ;
187
+ priorityWrite = childTree . value ;
188
+ } else {
189
+ node = applySubtreeWrite ( relativePath . child ( childKey ) , childTree , node ) ;
224
190
}
225
- return node ;
191
+ } ) ;
192
+ // If there was a priority write, we only apply it if the node is not empty
193
+ if ( ! node . getChild ( relativePath ) . isEmpty ( ) && priorityWrite !== null ) {
194
+ node = node . updateChild ( relativePath . child ( '.priority' ) , priorityWrite ) ;
226
195
}
227
- } ;
196
+ return node ;
197
+ }
228
198
}
0 commit comments