Skip to content

Commit a945668

Browse files
committed
resolve comments
1 parent 40962f9 commit a945668

File tree

3 files changed

+192
-174
lines changed

3 files changed

+192
-174
lines changed

packages/firestore/src/core/sync_engine_impl.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ export async function syncEngineListen(
314314
syncEngineImpl,
315315
query,
316316
shouldListenToRemote,
317-
true
317+
/** shouldInitializeView= */ true
318318
);
319319
debugAssert(!!viewSnapshot, 'viewSnapshot is not initialized');
320320
}
@@ -328,7 +328,12 @@ export async function triggerRemoteStoreListen(
328328
query: Query
329329
): Promise<void> {
330330
const syncEngineImpl = ensureWatchCallbacks(syncEngine);
331-
await allocateTargetAndMaybeListen(syncEngineImpl, query, true, false);
331+
await allocateTargetAndMaybeListen(
332+
syncEngineImpl,
333+
query,
334+
/** shouldListenToRemote= */ true,
335+
/** shouldInitializeView= */ false
336+
);
332337
}
333338

334339
async function allocateTargetAndMaybeListen(

packages/firestore/test/integration/api/bundle.test.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,35 +41,7 @@ import {
4141

4242
export const encoder = new TextEncoder();
4343

44-
/**
45-
* Returns a valid bundle string from replacing project id in `BUNDLE_TEMPLATE` with the given
46-
* db project id (also recalculate length prefixes).
47-
*/
48-
export function bundleString(db: Firestore): string {
49-
const projectId: string = db.app.options.projectId!;
50-
51-
// Extract elements from BUNDLE_TEMPLATE and replace the project ID.
52-
const elements = BUNDLE_TEMPLATE.map(e =>
53-
e.replace('{0}', projectId).replace('(default)', db._databaseId.database)
54-
);
55-
56-
// Recalculating length prefixes for elements that are not BundleMetadata.
57-
let bundleContent = '';
58-
for (const element of elements.slice(1)) {
59-
const length = encoder.encode(element).byteLength;
60-
bundleContent += `${length}${element}`;
61-
}
62-
63-
// Update BundleMetadata with new totalBytes.
64-
const totalBytes = encoder.encode(bundleContent).byteLength;
65-
const metadata = JSON.parse(elements[0]);
66-
metadata.metadata.totalBytes = totalBytes;
67-
const metadataContent = JSON.stringify(metadata);
68-
const metadataLength = encoder.encode(metadataContent).byteLength;
69-
return `${metadataLength}${metadataContent}${bundleContent}`;
70-
}
71-
72-
export function verifySuccessProgress(p: LoadBundleTaskProgress): void {
44+
function verifySuccessProgress(p: LoadBundleTaskProgress): void {
7345
expect(p.taskState).to.equal('Success');
7446
expect(p.bytesLoaded).to.be.equal(p.totalBytes);
7547
expect(p.documentsLoaded).to.equal(p.totalDocuments);
@@ -105,6 +77,34 @@ apiDescribe('Bundles', persistence => {
10577
]);
10678
}
10779

80+
/**
81+
* Returns a valid bundle string from replacing project id in `BUNDLE_TEMPLATE` with the given
82+
* db project id (also recalculate length prefixes).
83+
*/
84+
function bundleString(db: Firestore): string {
85+
const projectId: string = db.app.options.projectId!;
86+
87+
// Extract elements from BUNDLE_TEMPLATE and replace the project ID.
88+
const elements = BUNDLE_TEMPLATE.map(e =>
89+
e.replace('{0}', projectId).replace('(default)', db._databaseId.database)
90+
);
91+
92+
// Recalculating length prefixes for elements that are not BundleMetadata.
93+
let bundleContent = '';
94+
for (const element of elements.slice(1)) {
95+
const length = encoder.encode(element).byteLength;
96+
bundleContent += `${length}${element}`;
97+
}
98+
99+
// Update BundleMetadata with new totalBytes.
100+
const totalBytes = encoder.encode(bundleContent).byteLength;
101+
const metadata = JSON.parse(elements[0]);
102+
metadata.metadata.totalBytes = totalBytes;
103+
const metadataContent = JSON.stringify(metadata);
104+
const metadataLength = encoder.encode(metadataContent).byteLength;
105+
return `${metadataLength}${metadataContent}${bundleContent}`;
106+
}
107+
108108
it('load with documents only with on progress and promise interface', () => {
109109
return withTestDb(persistence, async db => {
110110
const progressEvents: LoadBundleTaskProgress[] = [];

0 commit comments

Comments
 (0)