Skip to content

Commit b60e00b

Browse files
jsayolJosep Sayol
authored and
Josep Sayol
committed
WIP: Convert CompleteChildSource and impl. to classes
1 parent f90ac4d commit b60e00b

File tree

1 file changed

+63
-70
lines changed

1 file changed

+63
-70
lines changed
Lines changed: 63 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { CacheNode } from "./CacheNode";
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';
26

37
/**
48
* Since updates to filtered nodes might require nodes to be pulled in from "outside" the node, this interface
@@ -8,21 +12,21 @@ import { CacheNode } from "./CacheNode";
812
*
913
* @interface
1014
*/
11-
export const CompleteChildSource = function() { };
12-
13-
/**
14-
* @param {!string} childKey
15-
* @return {?fb.core.snap.Node}
16-
*/
17-
CompleteChildSource.prototype.getCompleteChild = function(childKey) { };
15+
export interface CompleteChildSource {
16+
/**
17+
* @param {!string} childKey
18+
* @return {?fb.core.snap.Node}
19+
*/
20+
getCompleteChild(childKey: string): Node | null;
1821

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) { };
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+
}
2630

2731

2832
/**
@@ -32,22 +36,23 @@ CompleteChildSource.prototype.getChildAfterChild = function(index, child, revers
3236
* @constructor
3337
* @implements CompleteChildSource
3438
*/
35-
const NoCompleteChildSource_ = function() {
36-
};
39+
export class NoCompleteChildSource_ implements CompleteChildSource {
3740

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

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

5257
/**
5358
* Singleton instance.
@@ -61,57 +66,45 @@ export const NO_COMPLETE_CHILD_SOURCE = new NoCompleteChildSource_();
6166
* An implementation of CompleteChildSource that uses a WriteTree in addition to any other server data or
6267
* old event caches available to calculate complete children.
6368
*
64-
* @param {!fb.core.WriteTreeRef} writes
65-
* @param {!fb.core.view.ViewCache} viewCache
66-
* @param {?fb.core.snap.Node} optCompleteServerCache
6769
*
68-
* @constructor
6970
* @implements CompleteChildSource
7071
*/
71-
export const WriteTreeCompleteChildSource = function(writes, viewCache, optCompleteServerCache) {
72+
export class WriteTreeCompleteChildSource implements CompleteChildSource {
7273
/**
73-
* @type {!fb.core.WriteTreeRef}
74-
* @private
74+
* @param {!fb.core.WriteTreeRef} writes_
75+
* @param {!fb.core.view.ViewCache} viewCache_
76+
* @param {?fb.core.snap.Node} optCompleteServerCache_
7577
*/
76-
this.writes_ = writes;
77-
78-
/**
79-
* @type {!fb.core.view.ViewCache}
80-
* @private
81-
*/
82-
this.viewCache_ = viewCache;
78+
constructor(private writes_: WriteTreeRef,
79+
private viewCache_: ViewCache,
80+
private optCompleteServerCache_: Node | null = null) {
81+
}
8382

8483
/**
85-
* @type {?fb.core.snap.Node}
86-
* @private
84+
* @inheritDoc
8785
*/
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 ?
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 ?
10092
new CacheNode(this.optCompleteServerCache_, true, false) : this.viewCache_.getServerCache();
101-
return this.writes_.calcCompleteChild(childKey, serverNode);
93+
return this.writes_.calcCompleteChild(childKey, serverNode);
94+
}
10295
}
103-
};
10496

105-
/**
106-
* @inheritDoc
107-
*/
108-
WriteTreeCompleteChildSource.prototype.getChildAfterChild = function(index, child, reverse) {
109-
var completeServerData = this.optCompleteServerCache_ != null ? this.optCompleteServerCache_ :
97+
/**
98+
* @inheritDoc
99+
*/
100+
getChildAfterChild(index, child, reverse) {
101+
const completeServerData = this.optCompleteServerCache_ != null ? this.optCompleteServerCache_ :
110102
this.viewCache_.getCompleteServerSnap();
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];
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+
}
116109
}
117-
};
110+
}

0 commit comments

Comments
 (0)