Skip to content

Commit e8a4253

Browse files
committed
WIP: dfgsdghd
2 parents e71ec03 + 6404ff2 commit e8a4253

File tree

8 files changed

+562
-532
lines changed

8 files changed

+562
-532
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ applications using Firebase services. This SDK is distributed via:
99
- [npm package](https://www.npmjs.com/package/firebase)
1010
- [Bower package](https://github.com/firebase/firebase-bower)
1111

12-
To get starting using Firebase, see
12+
To get started using Firebase, see
1313
[Add Firebase to your JavaScript Project](https://firebase.google.com/docs/web/setup).
1414

1515
## SDK Dev Workflow

externs/firebase-app-externs.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ firebase.Promise = function(resolver) {};
233233
* @param {(function(!Error): *)=} onReject Called when the Promise is rejected
234234
* (with an error).
235235
* @return {!firebase.Promise<*>}
236+
* @override
236237
*/
237238
firebase.Promise.prototype.then = function(onResolve, onReject) {};
238239

@@ -241,6 +242,7 @@ firebase.Promise.prototype.then = function(onResolve, onReject) {};
241242
*
242243
* @param {(function(!Error): *)=} onReject Called when the Promise is rejected
243244
* (with an error).
245+
* @override
244246
*/
245247
firebase.Promise.prototype.catch = function(onReject) {};
246248

src/database/core/view/CacheNode.ts

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,74 @@
1-
import { Node } from '../snap/Node';
2-
import { Path } from '../util/Path';
3-
41
/**
52
* A cache node only stores complete children. Additionally it holds a flag whether the node can be considered fully
63
* initialized in the sense that we know at one point in time this represented a valid state of the world, e.g.
74
* initialized with data from the server, or a complete overwrite by the client. The filtered flag also tracks
85
* 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
911
*/
10-
export class CacheNode {
12+
export const CacheNode = function(node, fullyInitialized, filtered) {
1113
/**
12-
* @param {!fb.core.snap.Node} node_
13-
* @param {boolean} fullyInitialized_
14-
* @param {boolean} filtered_
14+
* @type {!fb.core.snap.Node}
15+
* @private
1516
*/
16-
constructor(private node_: Node,
17-
private fullyInitialized_: boolean,
18-
private filtered_: boolean) {
19-
20-
}
17+
this.node_ = node;
2118

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

3025
/**
31-
* Returns whether this node is potentially missing children due to a filter applied to the node
32-
* @return {boolean}
26+
* @type {boolean}
27+
* @private
3328
*/
34-
isFiltered(): boolean {
35-
return this.filtered_;
36-
}
29+
this.filtered_ = filtered;
30+
};
3731

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-
}
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+
};
4639

47-
const childKey = path.getFront();
48-
return this.isCompleteForChild(childKey);
49-
}
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+
};
5047

51-
/**
52-
* @param {!string} key
53-
* @return {boolean}
54-
*/
55-
isCompleteForChild(key: string): boolean {
56-
return (this.isFullyInitialized() && !this.filtered_) || this.node_.hasChild(key);
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();
57+
return this.isCompleteForChild(childKey);
5758
}
59+
};
5860

59-
/**
60-
* @return {!fb.core.snap.Node}
61-
*/
62-
getNode(): Node {
63-
return this.node_;
64-
}
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+
};
6568

66-
}
69+
/**
70+
* @return {!fb.core.snap.Node}
71+
*/
72+
CacheNode.prototype.getNode = function() {
73+
return this.node_;
74+
};
Lines changed: 70 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import { CacheNode } from './CacheNode';
2-
import { NamedNode, Node } from '../snap/Node';
3-
import { Index } from '../snap/indexes/Index';
4-
import { WriteTreeRef } from '../WriteTree';
5-
import { ViewCache } from './ViewCache';
1+
import { CacheNode } from "./CacheNode";
62

73
/**
84
* Since updates to filtered nodes might require nodes to be pulled in from "outside" the node, this interface
@@ -12,21 +8,21 @@ import { ViewCache } from './ViewCache';
128
*
139
* @interface
1410
*/
15-
export interface CompleteChildSource {
16-
/**
17-
* @param {!string} childKey
18-
* @return {?fb.core.snap.Node}
19-
*/
20-
getCompleteChild(childKey: string): Node | null;
11+
export const CompleteChildSource = function() { };
2112

22-
/**
23-
* @param {!fb.core.snap.Index} index
24-
* @param {!fb.core.snap.NamedNode} child
25-
* @param {boolean} reverse
26-
* @return {?fb.core.snap.NamedNode}
27-
*/
28-
getChildAfterChild(index: Index, child: NamedNode, reverse: boolean): NamedNode | null;
29-
}
13+
/**
14+
* @param {!string} childKey
15+
* @return {?fb.core.snap.Node}
16+
*/
17+
CompleteChildSource.prototype.getCompleteChild = function(childKey) { };
18+
19+
/**
20+
* @param {!fb.core.snap.Index} index
21+
* @param {!fb.core.snap.NamedNode} child
22+
* @param {boolean} reverse
23+
* @return {?fb.core.snap.NamedNode}
24+
*/
25+
CompleteChildSource.prototype.getChildAfterChild = function(index, child, reverse) { };
3026

3127

3228
/**
@@ -36,23 +32,22 @@ export interface CompleteChildSource {
3632
* @constructor
3733
* @implements CompleteChildSource
3834
*/
39-
export class NoCompleteChildSource_ implements CompleteChildSource {
35+
const NoCompleteChildSource_ = function() {
36+
};
4037

41-
/**
42-
* @inheritDoc
43-
*/
44-
getCompleteChild() {
45-
return null;
46-
}
47-
48-
/**
49-
* @inheritDoc
50-
*/
51-
getChildAfterChild() {
52-
return null;
53-
}
54-
}
38+
/**
39+
* @inheritDoc
40+
*/
41+
NoCompleteChildSource_.prototype.getCompleteChild = function() {
42+
return null;
43+
};
5544

45+
/**
46+
* @inheritDoc
47+
*/
48+
NoCompleteChildSource_.prototype.getChildAfterChild = function() {
49+
return null;
50+
};
5651

5752
/**
5853
* Singleton instance.
@@ -66,45 +61,57 @@ export const NO_COMPLETE_CHILD_SOURCE = new NoCompleteChildSource_();
6661
* An implementation of CompleteChildSource that uses a WriteTree in addition to any other server data or
6762
* old event caches available to calculate complete children.
6863
*
64+
* @param {!fb.core.WriteTreeRef} writes
65+
* @param {!fb.core.view.ViewCache} viewCache
66+
* @param {?fb.core.snap.Node} optCompleteServerCache
6967
*
68+
* @constructor
7069
* @implements CompleteChildSource
7170
*/
72-
export class WriteTreeCompleteChildSource implements CompleteChildSource {
71+
export const WriteTreeCompleteChildSource = function(writes, viewCache, optCompleteServerCache) {
7372
/**
74-
* @param {!fb.core.WriteTreeRef} writes_
75-
* @param {!fb.core.view.ViewCache} viewCache_
76-
* @param {?fb.core.snap.Node} optCompleteServerCache_
73+
* @type {!fb.core.WriteTreeRef}
74+
* @private
7775
*/
78-
constructor(private writes_: WriteTreeRef,
79-
private viewCache_: ViewCache,
80-
private optCompleteServerCache_: Node | null = null) {
81-
}
76+
this.writes_ = writes;
8277

8378
/**
84-
* @inheritDoc
79+
* @type {!fb.core.view.ViewCache}
80+
* @private
8581
*/
86-
getCompleteChild(childKey) {
87-
const node = this.viewCache_.getEventCache();
88-
if (node.isCompleteForChild(childKey)) {
89-
return node.getNode().getImmediateChild(childKey);
90-
} else {
91-
const serverNode = this.optCompleteServerCache_ != null ?
92-
new CacheNode(this.optCompleteServerCache_, true, false) : this.viewCache_.getServerCache();
93-
return this.writes_.calcCompleteChild(childKey, serverNode);
94-
}
95-
}
82+
this.viewCache_ = viewCache;
9683

9784
/**
98-
* @inheritDoc
85+
* @type {?fb.core.snap.Node}
86+
* @private
9987
*/
100-
getChildAfterChild(index, child, reverse) {
101-
const completeServerData = this.optCompleteServerCache_ != null ? this.optCompleteServerCache_ :
88+
this.optCompleteServerCache_ = optCompleteServerCache;
89+
};
90+
91+
/**
92+
* @inheritDoc
93+
*/
94+
WriteTreeCompleteChildSource.prototype.getCompleteChild = function(childKey) {
95+
var node = this.viewCache_.getEventCache();
96+
if (node.isCompleteForChild(childKey)) {
97+
return node.getNode().getImmediateChild(childKey);
98+
} else {
99+
var serverNode = this.optCompleteServerCache_ != null ?
100+
new CacheNode(this.optCompleteServerCache_, true, false) : this.viewCache_.getServerCache();
101+
return this.writes_.calcCompleteChild(childKey, serverNode);
102+
}
103+
};
104+
105+
/**
106+
* @inheritDoc
107+
*/
108+
WriteTreeCompleteChildSource.prototype.getChildAfterChild = function(index, child, reverse) {
109+
var completeServerData = this.optCompleteServerCache_ != null ? this.optCompleteServerCache_ :
102110
this.viewCache_.getCompleteServerSnap();
103-
const nodes = this.writes_.calcIndexedSlice(completeServerData, child, 1, reverse, index);
104-
if (nodes.length === 0) {
105-
return null;
106-
} else {
107-
return nodes[0];
108-
}
111+
var nodes = this.writes_.calcIndexedSlice(completeServerData, child, 1, reverse, index);
112+
if (nodes.length === 0) {
113+
return null;
114+
} else {
115+
return nodes[0];
109116
}
110-
}
117+
};

0 commit comments

Comments
 (0)