|
| 1 | +import { Node } from '../snap/Node'; |
| 2 | +import { Path } from '../util/Path'; |
| 3 | + |
1 | 4 | /**
|
2 | 5 | * A cache node only stores complete children. Additionally it holds a flag whether the node can be considered fully
|
3 | 6 | * initialized in the sense that we know at one point in time this represented a valid state of the world, e.g.
|
4 | 7 | * initialized with data from the server, or a complete overwrite by the client. The filtered flag also tracks
|
5 | 8 | * 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 |
11 | 9 | */
|
12 |
| -export const CacheNode = function(node, fullyInitialized, filtered) { |
| 10 | +export class CacheNode { |
13 | 11 | /**
|
14 |
| - * @type {!fb.core.snap.Node} |
15 |
| - * @private |
| 12 | + * @param {!fb.core.snap.Node} node_ |
| 13 | + * @param {boolean} fullyInitialized_ |
| 14 | + * @param {boolean} filtered_ |
16 | 15 | */
|
17 |
| - this.node_ = node; |
| 16 | + constructor(private node_: Node, |
| 17 | + private fullyInitialized_: boolean, |
| 18 | + private filtered_: boolean) { |
| 19 | + |
| 20 | + } |
18 | 21 |
|
19 | 22 | /**
|
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} |
22 | 25 | */
|
23 |
| - this.fullyInitialized_ = fullyInitialized; |
| 26 | + isFullyInitialized(): boolean { |
| 27 | + return this.fullyInitialized_; |
| 28 | + } |
24 | 29 |
|
25 | 30 | /**
|
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} |
28 | 33 | */
|
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 | + } |
39 | 37 |
|
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 | + } |
47 | 46 |
|
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(); |
57 | 48 | return this.isCompleteForChild(childKey);
|
58 | 49 | }
|
59 |
| -}; |
60 | 50 |
|
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 | + } |
68 | 58 |
|
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