11import { ImmutableTree } from "./util/ImmutableTree" ;
22import { Path } from "./util/Path" ;
33import { forEach } from "../../utils/obj" ;
4- import { NamedNode } from "./snap/Node" ;
4+ import { Node , NamedNode } from "./snap/Node" ;
55import { PRIORITY_INDEX } from "./snap/indexes/PriorityIndex" ;
66import { assert } from "../../utils/assert" ;
77
@@ -15,32 +15,25 @@ import { assert } from "../../utils/assert";
1515 * @param {!ImmutableTree.<!Node> } writeTree
1616 */
1717export 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 ) { } ;
2619 /**
2720 * @type {!CompoundWrite }
2821 */
29- static Empty = new CompoundWrite (
30- /** @type {!ImmutableTree.<!Node> } */ ( new ImmutableTree ( null ) )
31- ) ;
22+ static Empty = new CompoundWrite ( new ImmutableTree ( null ) ) ;
23+
3224 /**
3325 * @param {!Path } path
3426 * @param {!Node } node
3527 * @return {!CompoundWrite }
3628 */
37- addWrite ( path , node ) {
29+ addWrite ( path : Path , node : Node ) : CompoundWrite {
3830 if ( path . isEmpty ( ) ) {
3931 return new CompoundWrite ( new ImmutableTree ( node ) ) ;
4032 } else {
4133 var rootmost = this . writeTree_ . findRootMostValueAndPath ( path ) ;
4234 if ( rootmost != null ) {
43- var rootMostPath = rootmost . path , value = rootmost . value ;
35+ var rootMostPath = rootmost . path
36+ var value = rootmost . value ;
4437 var relativePath = Path . relativePath ( rootMostPath , path ) ;
4538 value = value . updateChild ( relativePath , node ) ;
4639 return new CompoundWrite ( this . writeTree_ . set ( rootMostPath , value ) ) ;
@@ -57,8 +50,8 @@ export class CompoundWrite {
5750 * @param {!Object.<string, !Node> } updates
5851 * @return {!CompoundWrite }
5952 */
60- addWrites ( path , updates ) {
61- var newWrite = < any > this ;
53+ addWrites ( path : Path , updates : { [ name : string ] : Node } ) : CompoundWrite {
54+ var newWrite = < CompoundWrite > this ;
6255 forEach ( updates , function ( childKey , node ) {
6356 newWrite = newWrite . addWrite ( path . child ( childKey ) , node ) ;
6457 } ) ;
@@ -72,7 +65,7 @@ export class CompoundWrite {
7265 * @param {!Path } path The path at which a write and all deeper writes should be removed
7366 * @return {!CompoundWrite } The new CompoundWrite with the removed path
7467 */
75- removeWrite ( path ) {
68+ removeWrite ( path : Path ) : CompoundWrite {
7669 if ( path . isEmpty ( ) ) {
7770 return CompoundWrite . Empty ;
7871 } else {
@@ -88,7 +81,7 @@ export class CompoundWrite {
8881 * @param {!Path } path The path to check for
8982 * @return {boolean } Whether there is a complete write at that path
9083 */
91- hasCompleteWrite ( path ) {
84+ hasCompleteWrite ( path : Path ) : boolean {
9285 return this . getCompleteNode ( path ) != null ;
9386 } ;
9487
@@ -99,11 +92,10 @@ export class CompoundWrite {
9992 * @param {!Path } path The path to get a complete write
10093 * @return {?Node } The node if complete at that path, or null otherwise.
10194 */
102- getCompleteNode ( path ) {
95+ getCompleteNode ( path : Path ) : Node {
10396 var rootmost = this . writeTree_ . findRootMostValueAndPath ( path ) ;
10497 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 ) ) ;
10799 } else {
108100 return null ;
109101 }
@@ -114,7 +106,7 @@ export class CompoundWrite {
114106 *
115107 * @return {!Array.<NamedNode> } A list of all complete children.
116108 */
117- getCompleteChildren ( ) {
109+ getCompleteChildren ( ) : Array < NamedNode > {
118110 var children = [ ] ;
119111 var node = this . writeTree_ . value ;
120112 if ( node != null ) {
@@ -139,7 +131,7 @@ export class CompoundWrite {
139131 * @param {!Path } path
140132 * @return {!CompoundWrite }
141133 */
142- childCompoundWrite ( path ) {
134+ childCompoundWrite ( path : Path ) {
143135 if ( path . isEmpty ( ) ) {
144136 return this ;
145137 } else {
@@ -166,7 +158,7 @@ export class CompoundWrite {
166158 * @param {!Node } node The node to apply this CompoundWrite to
167159 * @return {!Node } The node with all writes applied
168160 */
169- apply ( node ) {
161+ apply ( node : Node ) {
170162 return CompoundWrite . applySubtreeWrite_ ( Path . Empty , this . writeTree_ , node ) ;
171163 } ;
172164
@@ -177,7 +169,7 @@ export class CompoundWrite {
177169 * @return {!Node }
178170 * @private
179171 */
180- static applySubtreeWrite_ = function ( relativePath , writeTree , node ) {
172+ static applySubtreeWrite_ = function ( relativePath : Path , writeTree : ImmutableTree , node : Node ) {
181173 if ( writeTree . value != null ) {
182174 // Since there a write is always a leaf, we're done here
183175 return node . updateChild ( relativePath , writeTree . value ) ;
@@ -195,8 +187,7 @@ export class CompoundWrite {
195187 } ) ;
196188 // If there was a priority write, we only apply it if the node is not empty
197189 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 ) ;
200191 }
201192 return node ;
202193 }
0 commit comments