-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
562 additions
and
532 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,74 @@ | ||
import { Node } from '../snap/Node'; | ||
import { Path } from '../util/Path'; | ||
|
||
/** | ||
* A cache node only stores complete children. Additionally it holds a flag whether the node can be considered fully | ||
* initialized in the sense that we know at one point in time this represented a valid state of the world, e.g. | ||
* initialized with data from the server, or a complete overwrite by the client. The filtered flag also tracks | ||
* whether a node potentially had children removed due to a filter. | ||
* | ||
* @param {!fb.core.snap.Node} node | ||
* @param {boolean} fullyInitialized | ||
* @param {boolean} filtered | ||
* @constructor | ||
*/ | ||
export class CacheNode { | ||
export const CacheNode = function(node, fullyInitialized, filtered) { | ||
/** | ||
* @param {!fb.core.snap.Node} node_ | ||
* @param {boolean} fullyInitialized_ | ||
* @param {boolean} filtered_ | ||
* @type {!fb.core.snap.Node} | ||
* @private | ||
*/ | ||
constructor(private node_: Node, | ||
private fullyInitialized_: boolean, | ||
private filtered_: boolean) { | ||
|
||
} | ||
this.node_ = node; | ||
|
||
/** | ||
* Returns whether this node was fully initialized with either server data or a complete overwrite by the client | ||
* @return {boolean} | ||
* @type {boolean} | ||
* @private | ||
*/ | ||
isFullyInitialized(): boolean { | ||
return this.fullyInitialized_; | ||
} | ||
this.fullyInitialized_ = fullyInitialized; | ||
|
||
/** | ||
* Returns whether this node is potentially missing children due to a filter applied to the node | ||
* @return {boolean} | ||
* @type {boolean} | ||
* @private | ||
*/ | ||
isFiltered(): boolean { | ||
return this.filtered_; | ||
} | ||
this.filtered_ = filtered; | ||
}; | ||
|
||
/** | ||
* @param {!fb.core.util.Path} path | ||
* @return {boolean} | ||
*/ | ||
isCompleteForPath(path: Path): boolean { | ||
if (path.isEmpty()) { | ||
return this.isFullyInitialized() && !this.filtered_; | ||
} | ||
/** | ||
* Returns whether this node was fully initialized with either server data or a complete overwrite by the client | ||
* @return {boolean} | ||
*/ | ||
CacheNode.prototype.isFullyInitialized = function() { | ||
return this.fullyInitialized_; | ||
}; | ||
|
||
const childKey = path.getFront(); | ||
return this.isCompleteForChild(childKey); | ||
} | ||
/** | ||
* Returns whether this node is potentially missing children due to a filter applied to the node | ||
* @return {boolean} | ||
*/ | ||
CacheNode.prototype.isFiltered = function() { | ||
return this.filtered_; | ||
}; | ||
|
||
/** | ||
* @param {!string} key | ||
* @return {boolean} | ||
*/ | ||
isCompleteForChild(key: string): boolean { | ||
return (this.isFullyInitialized() && !this.filtered_) || this.node_.hasChild(key); | ||
/** | ||
* @param {!fb.core.util.Path} path | ||
* @return {boolean} | ||
*/ | ||
CacheNode.prototype.isCompleteForPath = function(path) { | ||
if (path.isEmpty()) { | ||
return this.isFullyInitialized() && !this.filtered_; | ||
} else { | ||
var childKey = path.getFront(); | ||
return this.isCompleteForChild(childKey); | ||
} | ||
}; | ||
|
||
/** | ||
* @return {!fb.core.snap.Node} | ||
*/ | ||
getNode(): Node { | ||
return this.node_; | ||
} | ||
/** | ||
* @param {!string} key | ||
* @return {boolean} | ||
*/ | ||
CacheNode.prototype.isCompleteForChild = function(key) { | ||
return (this.isFullyInitialized() && !this.filtered_) || this.node_.hasChild(key); | ||
}; | ||
|
||
} | ||
/** | ||
* @return {!fb.core.snap.Node} | ||
*/ | ||
CacheNode.prototype.getNode = function() { | ||
return this.node_; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.