@@ -38,15 +38,15 @@ import {
38
38
import {
39
39
SyncTree ,
40
40
syncTreeAckUserWrite ,
41
+ syncTreeAddEventRegistration ,
42
+ syncTreeApplyServerMerge ,
41
43
syncTreeApplyServerOverwrite ,
42
44
syncTreeApplyTaggedQueryMerge ,
43
45
syncTreeApplyTaggedQueryOverwrite ,
44
- syncTreeApplyServerMerge ,
45
- syncTreeGetServerValue ,
46
- syncTreeCalcCompleteEventCache ,
47
- syncTreeApplyUserOverwrite ,
48
46
syncTreeApplyUserMerge ,
49
- syncTreeAddEventRegistration ,
47
+ syncTreeApplyUserOverwrite ,
48
+ syncTreeCalcCompleteEventCache ,
49
+ syncTreeGetServerValue ,
50
50
syncTreeRemoveEventRegistration
51
51
} from './SyncTree' ;
52
52
import { SnapshotHolder } from './SnapshotHolder' ;
@@ -92,7 +92,17 @@ import { StatsCollection } from './stats/StatsCollection';
92
92
import { Event } from './view/Event' ;
93
93
import { Node } from './snap/Node' ;
94
94
import { Indexable } from './util/misc' ;
95
- import { Tree } from './util/Tree' ;
95
+ import {
96
+ Tree ,
97
+ treeForEachAncestor ,
98
+ treeForEachChild ,
99
+ treeForEachDescendant ,
100
+ treeGetPath ,
101
+ treeGetValue ,
102
+ treeHasChildren ,
103
+ treeSetValue ,
104
+ treeSubTree
105
+ } from './util/Tree' ;
96
106
import { isValidPriority , validateFirebaseData } from './util/validation' ;
97
107
import { ChildrenNode } from './snap/ChildrenNode' ;
98
108
import { PRIORITY_INDEX } from './snap/indexes/PriorityIndex' ;
@@ -937,11 +947,11 @@ export function repoStartTransaction(
937
947
938
948
// Mark as run and add to our queue.
939
949
transaction . status = TransactionStatus . RUN ;
940
- const queueNode = repo . transactionQueueTree_ . subTree ( path ) ;
941
- const nodeQueue = queueNode . getValue ( ) || [ ] ;
950
+ const queueNode = treeSubTree ( repo . transactionQueueTree_ , path ) ;
951
+ const nodeQueue = treeGetValue ( queueNode ) || [ ] ;
942
952
nodeQueue . push ( transaction ) ;
943
953
944
- queueNode . setValue ( nodeQueue ) ;
954
+ treeSetValue ( queueNode , nodeQueue ) ;
945
955
946
956
// Update visibleData and raise events
947
957
// Note: We intentionally raise events after updating all of our
@@ -1023,7 +1033,7 @@ function repoSendReadyTransactions(
1023
1033
repoPruneCompletedTransactionsBelowNode ( repo , node ) ;
1024
1034
}
1025
1035
1026
- if ( node . getValue ( ) !== null ) {
1036
+ if ( treeGetValue ( node ) ) {
1027
1037
const queue = repoBuildTransactionQueue ( repo , node ) ;
1028
1038
assert ( queue . length > 0 , 'Sending zero length transaction queue' ) ;
1029
1039
@@ -1033,10 +1043,10 @@ function repoSendReadyTransactions(
1033
1043
1034
1044
// If they're all run (and not sent), we can send them. Else, we must wait.
1035
1045
if ( allRun ) {
1036
- repoSendTransactionQueue ( repo , node . path ( ) , queue ) ;
1046
+ repoSendTransactionQueue ( repo , treeGetPath ( node ) , queue ) ;
1037
1047
}
1038
- } else if ( node . hasChildren ( ) ) {
1039
- node . forEachChild ( childNode => {
1048
+ } else if ( treeHasChildren ( node ) ) {
1049
+ treeForEachChild ( node , childNode => {
1040
1050
repoSendReadyTransactions ( repo , childNode ) ;
1041
1051
} ) ;
1042
1052
}
@@ -1117,7 +1127,7 @@ function repoSendTransactionQueue(
1117
1127
// Now remove the completed transactions.
1118
1128
repoPruneCompletedTransactionsBelowNode (
1119
1129
repo ,
1120
- repo . transactionQueueTree_ . subTree ( path )
1130
+ treeSubTree ( repo . transactionQueueTree_ , path )
1121
1131
) ;
1122
1132
// There may be pending transactions that we can now send.
1123
1133
repoSendReadyTransactions ( repo , repo . transactionQueueTree_ ) ;
@@ -1171,7 +1181,7 @@ function repoRerunTransactions(repo: Repo, changedPath: Path): Path {
1171
1181
repo ,
1172
1182
changedPath
1173
1183
) ;
1174
- const path = rootMostTransactionNode . path ( ) ;
1184
+ const path = treeGetPath ( rootMostTransactionNode ) ;
1175
1185
1176
1186
const queue = repoBuildTransactionQueue ( repo , rootMostTransactionNode ) ;
1177
1187
repoRerunTransactionQueue ( repo , queue , path ) ;
@@ -1360,8 +1370,8 @@ function repoGetAncestorTransactionNode(
1360
1370
// find a node with pending transactions.
1361
1371
let transactionNode = repo . transactionQueueTree_ ;
1362
1372
front = pathGetFront ( path ) ;
1363
- while ( front !== null && transactionNode . getValue ( ) === null ) {
1364
- transactionNode = transactionNode . subTree ( front ) ;
1373
+ while ( front !== null && treeGetValue ( transactionNode ) === undefined ) {
1374
+ transactionNode = treeSubTree ( transactionNode , front ) ;
1365
1375
path = pathPopFront ( path ) ;
1366
1376
front = pathGetFront ( path ) ;
1367
1377
}
@@ -1389,9 +1399,7 @@ function repoBuildTransactionQueue(
1389
1399
) ;
1390
1400
1391
1401
// Sort them by the order the transactions were created.
1392
- transactionQueue . sort ( ( a , b ) => {
1393
- return a . order - b . order ;
1394
- } ) ;
1402
+ transactionQueue . sort ( ( a , b ) => a . order - b . order ) ;
1395
1403
1396
1404
return transactionQueue ;
1397
1405
}
@@ -1401,14 +1409,14 @@ function repoAggregateTransactionQueuesForNode(
1401
1409
node : Tree < Transaction [ ] > ,
1402
1410
queue : Transaction [ ]
1403
1411
) : void {
1404
- const nodeQueue = node . getValue ( ) ;
1405
- if ( nodeQueue !== null ) {
1412
+ const nodeQueue = treeGetValue ( node ) ;
1413
+ if ( nodeQueue ) {
1406
1414
for ( let i = 0 ; i < nodeQueue . length ; i ++ ) {
1407
1415
queue . push ( nodeQueue [ i ] ) ;
1408
1416
}
1409
1417
}
1410
1418
1411
- node . forEachChild ( child => {
1419
+ treeForEachChild ( node , child => {
1412
1420
repoAggregateTransactionQueuesForNode ( repo , child , queue ) ;
1413
1421
} ) ;
1414
1422
}
@@ -1420,7 +1428,7 @@ function repoPruneCompletedTransactionsBelowNode(
1420
1428
repo : Repo ,
1421
1429
node : Tree < Transaction [ ] >
1422
1430
) : void {
1423
- const queue = node . getValue ( ) ;
1431
+ const queue = treeGetValue ( node ) ;
1424
1432
if ( queue ) {
1425
1433
let to = 0 ;
1426
1434
for ( let from = 0 ; from < queue . length ; from ++ ) {
@@ -1430,10 +1438,10 @@ function repoPruneCompletedTransactionsBelowNode(
1430
1438
}
1431
1439
}
1432
1440
queue . length = to ;
1433
- node . setValue ( queue . length > 0 ? queue : null ) ;
1441
+ treeSetValue ( node , queue . length > 0 ? queue : undefined ) ;
1434
1442
}
1435
1443
1436
- node . forEachChild ( childNode => {
1444
+ treeForEachChild ( node , childNode => {
1437
1445
repoPruneCompletedTransactionsBelowNode ( repo , childNode ) ;
1438
1446
} ) ;
1439
1447
}
@@ -1446,17 +1454,17 @@ function repoPruneCompletedTransactionsBelowNode(
1446
1454
* @param path Path for which we want to abort related transactions.
1447
1455
*/
1448
1456
function repoAbortTransactions ( repo : Repo , path : Path ) : Path {
1449
- const affectedPath = repoGetAncestorTransactionNode ( repo , path ) . path ( ) ;
1457
+ const affectedPath = treeGetPath ( repoGetAncestorTransactionNode ( repo , path ) ) ;
1450
1458
1451
- const transactionNode = repo . transactionQueueTree_ . subTree ( path ) ;
1459
+ const transactionNode = treeSubTree ( repo . transactionQueueTree_ , path ) ;
1452
1460
1453
- transactionNode . forEachAncestor ( ( node : Tree < Transaction [ ] > ) => {
1461
+ treeForEachAncestor ( transactionNode , ( node : Tree < Transaction [ ] > ) => {
1454
1462
repoAbortTransactionsOnNode ( repo , node ) ;
1455
1463
} ) ;
1456
1464
1457
1465
repoAbortTransactionsOnNode ( repo , transactionNode ) ;
1458
1466
1459
- transactionNode . forEachDescendant ( ( node : Tree < Transaction [ ] > ) => {
1467
+ treeForEachDescendant ( transactionNode , ( node : Tree < Transaction [ ] > ) => {
1460
1468
repoAbortTransactionsOnNode ( repo , node ) ;
1461
1469
} ) ;
1462
1470
@@ -1472,8 +1480,8 @@ function repoAbortTransactionsOnNode(
1472
1480
repo : Repo ,
1473
1481
node : Tree < Transaction [ ] >
1474
1482
) : void {
1475
- const queue = node . getValue ( ) ;
1476
- if ( queue !== null ) {
1483
+ const queue = treeGetValue ( node ) ;
1484
+ if ( queue ) {
1477
1485
// Queue up the callbacks and fire them after cleaning up all of our
1478
1486
// transaction state, since the callback could trigger more transactions
1479
1487
// or sets.
@@ -1519,14 +1527,18 @@ function repoAbortTransactionsOnNode(
1519
1527
}
1520
1528
if ( lastSent === - 1 ) {
1521
1529
// We're not waiting for any sent transactions. We can clear the queue.
1522
- node . setValue ( null ) ;
1530
+ treeSetValue ( node , undefined ) ;
1523
1531
} else {
1524
1532
// Remove the transactions we aborted.
1525
1533
queue . length = lastSent + 1 ;
1526
1534
}
1527
1535
1528
1536
// Now fire the callbacks.
1529
- eventQueueRaiseEventsForChangedPath ( repo . eventQueue_ , node . path ( ) , events ) ;
1537
+ eventQueueRaiseEventsForChangedPath (
1538
+ repo . eventQueue_ ,
1539
+ treeGetPath ( node ) ,
1540
+ events
1541
+ ) ;
1530
1542
for ( let i = 0 ; i < callbacks . length ; i ++ ) {
1531
1543
exceptionGuard ( callbacks [ i ] ) ;
1532
1544
}
0 commit comments