Skip to content

Commit 42dc051

Browse files
committed
Merge branch 'master' into wuandy/QueryTargetAndLimitToLast
2 parents 9cab57c + 4ecd58e commit 42dc051

File tree

9 files changed

+67
-28
lines changed

9 files changed

+67
-28
lines changed

.opensource/project.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "Firebase JavaScript SDK",
3+
"type": "library",
4+
"platforms": [
5+
"Web"
6+
],
7+
"content": "README.md",
8+
"pages": {
9+
"packages/rxfire/README.md": "RxFire"
10+
},
11+
"related": [
12+
"firebase/quickstart-js"
13+
],
14+
"tabs": [
15+
{
16+
"title": "Reference",
17+
"href": "https://firebase.google.com/docs/reference/js/"
18+
}
19+
]
20+
}

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88

99
// Exclude installed dependencies from searches too
1010
"**/node_modules": true
11-
}
11+
},
12+
"typescript.tsdk": "node_modules/typescript/lib"
1213
}

packages/firestore/CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# Unreleased
2+
- [changed] Improved iOS 13 support by eliminating an additional crash in our
3+
IndexedDB persistence layer.
4+
5+
# 1.6.2
26
- [changed] Fixed a crash on iOS 13 that occurred when persistence was enabled
37
in a background tab (#2232).
48
- [fixed] Fixed an issue in the interaction with the Firestore Emulator that
59
caused requests with timestamps to fail.
10+
11+
# 1.6.0
612
- [feature] Added a `Firestore.onSnapshotsInSync()` method that notifies you
713
when all your snapshot listeners are in sync with each other.
8-
9-
# 1.6.0
1014
- [fixed] Fixed a regression that caused queries with nested field filters to
1115
crash the client if the field was not present in the local copy of the
1216
document.

packages/firestore/src/local/index_free_query_engine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class IndexFreeQueryEngine implements QueryEngine {
6969
'setLocalDocumentsView() not called'
7070
);
7171

72-
// Queries that match all document don't benefit from using
72+
// Queries that match all documents don't benefit from using
7373
// IndexFreeQueries. It is more efficient to scan all documents in a
7474
// collection, rather than to perform individual lookups.
7575
if (query.matchesAllDocuments()) {

packages/firestore/src/local/indexeddb_persistence.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -451,33 +451,30 @@ export class IndexedDbPersistence implements Persistence {
451451
) {
452452
this.lastGarbageCollectionTime = Date.now();
453453

454-
let activeClients: DbClientMetadata[];
455-
let inactiveClients: DbClientMetadata[] = [];
456-
457-
await this.runTransaction(
454+
const inactiveClients = await this.runTransaction(
458455
'maybeGarbageCollectMultiClientState',
459-
'readwrite-primary',
456+
'readwrite-primary-idempotent',
460457
txn => {
461458
const metadataStore = IndexedDbPersistence.getStore<
462459
DbClientMetadataKey,
463460
DbClientMetadata
464461
>(txn, DbClientMetadata.store);
465462

466463
return metadataStore.loadAll().next(existingClients => {
467-
activeClients = this.filterActiveClients(
464+
const active = this.filterActiveClients(
468465
existingClients,
469466
MAX_CLIENT_AGE_MS
470467
);
471-
inactiveClients = existingClients.filter(
472-
client => activeClients.indexOf(client) === -1
468+
const inactive = existingClients.filter(
469+
client => active.indexOf(client) === -1
473470
);
474471

475472
// Delete metadata for clients that are no longer considered active.
476473
return PersistencePromise.forEach(
477-
inactiveClients,
474+
inactive,
478475
(inactiveClient: DbClientMetadata) =>
479476
metadataStore.delete(inactiveClient.clientId)
480-
);
477+
).next(() => inactive);
481478
});
482479
}
483480
);

packages/firestore/src/local/simple_db.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ export class SimpleDb {
303303
isDomException(e) &&
304304
attemptNumber < TRANSACTION_RETRY_COUNT;
305305
debug(
306+
LOG_TAG,
306307
'Transaction failed with error: %s. Retrying: %s.',
307308
e.message,
308309
retryable

packages/rxfire/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
<p align="center">
2-
<h1 align="center">RxFire</h1>
3-
<p align="center">Firebase and RxJS for all frameworks</p>
4-
</p>
1+
# RxFire
2+
3+
Firebase and RxJS for all frameworks.
54

65
## What is RxFire?
76

packages/rxfire/firestore/collection/index.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import { firestore } from 'firebase/app';
1919
import { fromCollectionRef } from '../fromRef';
2020
import { Observable, MonoTypeOperatorFunction } from 'rxjs';
21-
import { map, filter, scan } from 'rxjs/operators';
21+
import { map, filter, scan, distinctUntilChanged } from 'rxjs/operators';
2222
import { snapToData } from '../document';
2323

2424
const ALL_EVENTS: firestore.DocumentChangeType[] = [
@@ -56,6 +56,16 @@ const filterEmpty = filter(
5656
(changes: firestore.DocumentChange[]) => changes.length > 0
5757
);
5858

59+
/**
60+
* Splice arguments on top of a sliced array, to break top-level ===
61+
* this is useful for change-detection
62+
*/
63+
function sliceAndSplice<T>(original: T[], start: number, deleteCount: number, ...args: T[]): T[] {
64+
const returnArray = original.slice();
65+
returnArray.splice(start, deleteCount, ...args);
66+
return returnArray;
67+
}
68+
5969
/**
6070
* Creates a new sorted array from a new change.
6171
* @param combined
@@ -69,35 +79,37 @@ function processIndividualChange(
6979
case 'added':
7080
if (
7181
combined[change.newIndex] &&
72-
combined[change.newIndex].doc.id === change.doc.id
82+
combined[change.newIndex].doc.ref.isEqual(change.doc.ref)
7383
) {
7484
// Skip duplicate emissions. This is rare.
7585
// TODO: Investigate possible bug in SDK.
7686
} else {
77-
combined.splice(change.newIndex, 0, change);
87+
return sliceAndSplice(combined, change.newIndex, 0, change);
7888
}
7989
break;
8090
case 'modified':
8191
if (
8292
combined[change.oldIndex] == null ||
83-
combined[change.oldIndex].doc.id === change.doc.id
93+
combined[change.oldIndex].doc.ref.isEqual(change.doc.ref)
8494
) {
8595
// When an item changes position we first remove it
8696
// and then add it's new position
8797
if (change.oldIndex !== change.newIndex) {
88-
combined.splice(change.oldIndex, 1);
89-
combined.splice(change.newIndex, 0, change);
98+
const copiedArray = combined.slice();
99+
copiedArray.splice(change.oldIndex, 1);
100+
copiedArray.splice(change.newIndex, 0, change);
101+
return copiedArray;
90102
} else {
91-
combined[change.newIndex] = change;
103+
return sliceAndSplice(combined, change.newIndex, 1, change);
92104
}
93105
}
94106
break;
95107
case 'removed':
96108
if (
97109
combined[change.oldIndex] &&
98-
combined[change.oldIndex].doc.id === change.doc.id
110+
combined[change.oldIndex].doc.ref.isEqual(change.doc.ref)
99111
) {
100-
combined.splice(change.oldIndex, 1);
112+
return sliceAndSplice(combined, change.oldIndex, 1);
101113
}
102114
break;
103115
default: // ignore
@@ -167,7 +179,8 @@ export function sortedChanges(
167179
changes: firestore.DocumentChange[]
168180
) => processDocumentChanges(current, changes, events),
169181
[]
170-
)
182+
),
183+
distinctUntilChanged()
171184
);
172185
}
173186

packages/rxfire/test/firestore.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,15 @@ describe('RxFire Firestore', () => {
165165
take(1)
166166
);
167167

168+
let previousData: Array<{}>;
169+
168170
addedChanges.subscribe(data => {
169171
const expectedNames = [
170172
{ name: 'David', type: 'added' },
171173
{ name: 'Shannon', type: 'added' }
172174
];
173175
expect(data).to.eql(expectedNames);
176+
previousData = data;
174177
davidDoc.update({ name: 'David!' });
175178
});
176179

@@ -180,6 +183,7 @@ describe('RxFire Firestore', () => {
180183
{ name: 'Shannon', type: 'added' }
181184
];
182185
expect(data).to.eql(expectedNames);
186+
expect(data === previousData).to.eql(false);
183187
done();
184188
});
185189
});

0 commit comments

Comments
 (0)