Skip to content

Commit 1ab4ad0

Browse files
committed
Remove some redundant comments
1 parent b7e7310 commit 1ab4ad0

File tree

2 files changed

+46
-163
lines changed

2 files changed

+46
-163
lines changed

packages/database/src/core/CompoundWrite.ts

Lines changed: 40 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,12 @@ import { each } from './util/util';
2828
* dealing with priority writes and multiple nested writes. At any given path there is only allowed to be one write
2929
* modifying that path. Any write to an existing path or shadowing an existing path will modify that existing write
3030
* to reflect the write added.
31-
*
32-
* @constructor
33-
* @param {!ImmutableTree.<!Node>} writeTree
3431
*/
3532
export class CompoundWrite {
3633
constructor(private writeTree_: ImmutableTree<Node>) {}
37-
/**
38-
* @type {!CompoundWrite}
39-
*/
34+
4035
static Empty = new CompoundWrite(new ImmutableTree(null));
4136

42-
/**
43-
* @param {!Path} path
44-
* @param {!Node} node
45-
* @return {!CompoundWrite}
46-
*/
4737
addWrite(path: Path, node: Node): CompoundWrite {
4838
if (path.isEmpty()) {
4939
return new CompoundWrite(new ImmutableTree(node));
@@ -63,11 +53,6 @@ export class CompoundWrite {
6353
}
6454
}
6555

66-
/**
67-
* @param {!Path} path
68-
* @param {!Object.<string, !Node>} updates
69-
* @return {!CompoundWrite}
70-
*/
7156
addWrites(path: Path, updates: { [name: string]: Node }): CompoundWrite {
7257
let newWrite = this as CompoundWrite;
7358
each(updates, function(childKey: string, node: Node) {
@@ -80,7 +65,7 @@ export class CompoundWrite {
8065
* Will remove a write at the given path and deeper paths. This will <em>not</em> modify a write at a higher
8166
* location, which must be removed by calling this method with that path.
8267
*
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
8469
* @return {!CompoundWrite} The new CompoundWrite with the removed path
8570
*/
8671
removeWrite(path: Path): CompoundWrite {
@@ -96,8 +81,8 @@ export class CompoundWrite {
9681
* Returns whether this CompoundWrite will fully overwrite a node at a given location and can therefore be
9782
* considered "complete".
9883
*
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
10186
*/
10287
hasCompleteWrite(path: Path): boolean {
10388
return this.getCompleteNode(path) != null;
@@ -107,8 +92,8 @@ export class CompoundWrite {
10792
* Returns a node for a path if and only if the node is a "complete" overwrite at that path. This will not aggregate
10893
* writes from deeper paths, but will return child nodes from a more shallow path.
10994
*
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.
11297
*/
11398
getCompleteNode(path: Path): Node | null {
11499
const rootmost = this.writeTree_.findRootMostValueAndPath(path);
@@ -124,9 +109,9 @@ export class CompoundWrite {
124109
/**
125110
* Returns all children that are guaranteed to be a complete overwrite.
126111
*
127-
* @return {!Array.<NamedNode>} A list of all complete children.
112+
* @return A list of all complete children.
128113
*/
129-
getCompleteChildren(): Array<NamedNode> {
114+
getCompleteChildren(): NamedNode[] {
130115
const children: NamedNode[] = [];
131116
let node = this.writeTree_.value;
132117
if (node != null) {
@@ -149,10 +134,6 @@ export class CompoundWrite {
149134
return children;
150135
}
151136

152-
/**
153-
* @param {!Path} path
154-
* @return {!CompoundWrite}
155-
*/
156137
childCompoundWrite(path: Path): CompoundWrite {
157138
if (path.isEmpty()) {
158139
return this;
@@ -168,7 +149,7 @@ export class CompoundWrite {
168149

169150
/**
170151
* 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
172153
*/
173154
isEmpty(): boolean {
174155
return this.writeTree_.isEmpty();
@@ -177,52 +158,41 @@ export class CompoundWrite {
177158
/**
178159
* Applies this CompoundWrite to a node. The node is returned with all writes from this CompoundWrite applied to the
179160
* 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
182163
*/
183164
apply(node: Node): Node {
184-
return CompoundWrite.applySubtreeWrite_(Path.Empty, this.writeTree_, node);
165+
return applySubtreeWrite(Path.Empty, this.writeTree_, node);
185166
}
167+
}
186168

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);
224190
}
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);
226195
}
227-
};
196+
return node;
197+
}
228198
}

0 commit comments

Comments
 (0)