Skip to content

Commit e880a64

Browse files
committed
WIP: Convert CacheNode to a class
1 parent a45cf1a commit e880a64

File tree

1 file changed

+46
-54
lines changed

1 file changed

+46
-54
lines changed

src/database/core/view/CacheNode.ts

Lines changed: 46 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,66 @@
1+
import { Node } from '../snap/Node';
2+
import { Path } from '../util/Path';
3+
14
/**
25
* A cache node only stores complete children. Additionally it holds a flag whether the node can be considered fully
36
* initialized in the sense that we know at one point in time this represented a valid state of the world, e.g.
47
* initialized with data from the server, or a complete overwrite by the client. The filtered flag also tracks
58
* whether a node potentially had children removed due to a filter.
6-
*
7-
* @param {!fb.core.snap.Node} node
8-
* @param {boolean} fullyInitialized
9-
* @param {boolean} filtered
10-
* @constructor
119
*/
12-
export const CacheNode = function(node, fullyInitialized, filtered) {
10+
export class CacheNode {
1311
/**
14-
* @type {!fb.core.snap.Node}
15-
* @private
12+
* @param {!fb.core.snap.Node} node_
13+
* @param {boolean} fullyInitialized_
14+
* @param {boolean} filtered_
1615
*/
17-
this.node_ = node;
16+
constructor(private node_: Node,
17+
private fullyInitialized_: boolean,
18+
private filtered_: boolean) {
19+
20+
}
1821

1922
/**
20-
* @type {boolean}
21-
* @private
23+
* Returns whether this node was fully initialized with either server data or a complete overwrite by the client
24+
* @return {boolean}
2225
*/
23-
this.fullyInitialized_ = fullyInitialized;
26+
isFullyInitialized(): boolean {
27+
return this.fullyInitialized_;
28+
}
2429

2530
/**
26-
* @type {boolean}
27-
* @private
31+
* Returns whether this node is potentially missing children due to a filter applied to the node
32+
* @return {boolean}
2833
*/
29-
this.filtered_ = filtered;
30-
};
31-
32-
/**
33-
* Returns whether this node was fully initialized with either server data or a complete overwrite by the client
34-
* @return {boolean}
35-
*/
36-
CacheNode.prototype.isFullyInitialized = function() {
37-
return this.fullyInitialized_;
38-
};
34+
isFiltered(): boolean {
35+
return this.filtered_;
36+
}
3937

40-
/**
41-
* Returns whether this node is potentially missing children due to a filter applied to the node
42-
* @return {boolean}
43-
*/
44-
CacheNode.prototype.isFiltered = function() {
45-
return this.filtered_;
46-
};
38+
/**
39+
* @param {!fb.core.util.Path} path
40+
* @return {boolean}
41+
*/
42+
isCompleteForPath(path: Path): boolean {
43+
if (path.isEmpty()) {
44+
return this.isFullyInitialized() && !this.filtered_;
45+
}
4746

48-
/**
49-
* @param {!fb.core.util.Path} path
50-
* @return {boolean}
51-
*/
52-
CacheNode.prototype.isCompleteForPath = function(path) {
53-
if (path.isEmpty()) {
54-
return this.isFullyInitialized() && !this.filtered_;
55-
} else {
56-
var childKey = path.getFront();
47+
const childKey = path.getFront();
5748
return this.isCompleteForChild(childKey);
5849
}
59-
};
6050

61-
/**
62-
* @param {!string} key
63-
* @return {boolean}
64-
*/
65-
CacheNode.prototype.isCompleteForChild = function(key) {
66-
return (this.isFullyInitialized() && !this.filtered_) || this.node_.hasChild(key);
67-
};
51+
/**
52+
* @param {!string} key
53+
* @return {boolean}
54+
*/
55+
isCompleteForChild(key: string): boolean {
56+
return (this.isFullyInitialized() && !this.filtered_) || this.node_.hasChild(key);
57+
}
6858

69-
/**
70-
* @return {!fb.core.snap.Node}
71-
*/
72-
CacheNode.prototype.getNode = function() {
73-
return this.node_;
74-
};
59+
/**
60+
* @return {!fb.core.snap.Node}
61+
*/
62+
getNode(): Node {
63+
return this.node_;
64+
}
65+
66+
}

0 commit comments

Comments
 (0)