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