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' ;
2
6
3
7
/**
4
8
* 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";
8
12
*
9
13
* @interface
10
14
*/
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 ;
18
21
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
+ }
26
30
27
31
28
32
/**
@@ -32,22 +36,23 @@ CompleteChildSource.prototype.getChildAfterChild = function(index, child, revers
32
36
* @constructor
33
37
* @implements CompleteChildSource
34
38
*/
35
- const NoCompleteChildSource_ = function ( ) {
36
- } ;
39
+ export class NoCompleteChildSource_ implements CompleteChildSource {
37
40
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
+ }
44
55
45
- /**
46
- * @inheritDoc
47
- */
48
- NoCompleteChildSource_ . prototype . getChildAfterChild = function ( ) {
49
- return null ;
50
- } ;
51
56
52
57
/**
53
58
* Singleton instance.
@@ -61,57 +66,45 @@ export const NO_COMPLETE_CHILD_SOURCE = new NoCompleteChildSource_();
61
66
* An implementation of CompleteChildSource that uses a WriteTree in addition to any other server data or
62
67
* old event caches available to calculate complete children.
63
68
*
64
- * @param {!fb.core.WriteTreeRef } writes
65
- * @param {!fb.core.view.ViewCache } viewCache
66
- * @param {?fb.core.snap.Node } optCompleteServerCache
67
69
*
68
- * @constructor
69
70
* @implements CompleteChildSource
70
71
*/
71
- export const WriteTreeCompleteChildSource = function ( writes , viewCache , optCompleteServerCache ) {
72
+ export class WriteTreeCompleteChildSource implements CompleteChildSource {
72
73
/**
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_
75
77
*/
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
+ }
83
82
84
83
/**
85
- * @type {?fb.core.snap.Node }
86
- * @private
84
+ * @inheritDoc
87
85
*/
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 ?
100
92
new CacheNode ( this . optCompleteServerCache_ , true , false ) : this . viewCache_ . getServerCache ( ) ;
101
- return this . writes_ . calcCompleteChild ( childKey , serverNode ) ;
93
+ return this . writes_ . calcCompleteChild ( childKey , serverNode ) ;
94
+ }
102
95
}
103
- } ;
104
96
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_ :
110
102
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
+ }
116
109
}
117
- } ;
110
+ }
0 commit comments