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