Skip to content

Commit 3cb206e

Browse files
committed
code cleanup
1 parent 1488228 commit 3cb206e

File tree

3 files changed

+153
-148
lines changed

3 files changed

+153
-148
lines changed

packages/firestore/src/remote/watch_change.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,8 @@ export class WatchChangeAggregator {
690690
this.pendingDocumentUpdatesByTarget =
691691
this.pendingDocumentUpdatesByTarget.insert(
692692
document.key,
693-
this.ensureDocumentUpdateByTarget(document.key).add(targetId));
693+
this.ensureDocumentUpdateByTarget(document.key).add(targetId)
694+
);
694695

695696
this.pendingDocumentTargetMapping =
696697
this.pendingDocumentTargetMapping.insert(

packages/firestore/test/unit/specs/collection_spec.test.ts

Lines changed: 147 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -15,179 +15,180 @@
1515
* limitations under the License.
1616
*/
1717

18-
import {newQueryForPath} from "../../../src/core/query";
19-
import {deletedDoc, doc, filter, query} from '../../util/helpers';
18+
import { newQueryForPath } from '../../../src/core/query';
19+
import { deletedDoc, doc, filter, query } from '../../util/helpers';
2020

2121
import { describeSpec, specTest } from './describe_spec';
2222
import { spec } from './spec_builder';
2323

2424
describeSpec('Collections:', [], () => {
25-
2625
specTest('8474', [], () => {
27-
2826
// onSnapshot(fullQuery)
2927
const fullQuery = query('collection');
3028

3129
// getDocs(filterQuery)
3230
const filterQuery = query('collection', filter('included', '==', true));
3331

34-
const docA = doc('collection/a', 1000, {key: 'a', included: false});
35-
const docA2 = doc('collection/a', 1007, {key: 'a', included: true});
36-
const docC = doc('collection/c', 1002, {key: 'c', included: true});
32+
const docA = doc('collection/a', 1000, { key: 'a', included: false });
33+
const docA2 = doc('collection/a', 1007, { key: 'a', included: true });
34+
const docC = doc('collection/c', 1002, { key: 'c', included: true });
3735

3836
const limboQueryC = newQueryForPath(docC.key.path);
3937

40-
return spec()
41-
// onSnapshot(fullQuery) - fullQuery is listening to documents in the collection for the full test
42-
.userListens(fullQuery)
43-
.watchAcksFull(fullQuery, 1001, docA, docC)
44-
.expectEvents(fullQuery, {
45-
fromCache: false,
46-
added: [docA, docC]
47-
})
48-
49-
// docC was deleted, this puts docC in limbo and causes a snapshot from cache (metadata-only change)
50-
.watchSends({removed: [fullQuery]}, docC)
51-
.watchCurrents(fullQuery, 'resume-token-1002')
52-
.watchSnapshots(1002)
53-
.expectLimboDocs(docC.key)
54-
.expectEvents(fullQuery, {
55-
fromCache: true,
56-
})
57-
58-
// User begins getDocs(filterQuery)
59-
.userListensForGet(filterQuery)
60-
61-
// getDocs(filterQuery) will not resolve on the snapshot from cache
62-
.expectEvents(filterQuery, {
63-
fromCache: true,
64-
added: [docC]
65-
})
66-
67-
// Watch acks limbo and filter queries
68-
.watchAcks(limboQueryC)
69-
.watchAcks(filterQuery)
70-
71-
// Watch responds to limboQueryC - docC was deleted
72-
.watchSends({affects: [limboQueryC]})
73-
.watchCurrents(limboQueryC, 'resume-token-1009')
74-
.watchSnapshots(1009, [limboQueryC, fullQuery])
75-
76-
// However, docC is still in limbo because there has not been a global snapshot
77-
.expectLimboDocs(docC.key)
78-
79-
// Rapid events of document update and delete caused by application
80-
.watchSends({removed: [filterQuery]}, docA)
81-
.watchCurrents(filterQuery, 'resume-token-1004')
82-
.watchSends({affects: [filterQuery]}, docC)
83-
.watchCurrents(filterQuery, 'resume-token-1005')
84-
.watchSends({removed: [filterQuery]}, docC)
85-
.watchSends({affects: [filterQuery]}, docA2)
86-
.watchCurrents(filterQuery, 'resume-token-1007')
87-
88-
.watchSnapshots(1010, [fullQuery, limboQueryC])
89-
90-
// All changes are current and we get a global snapshot
91-
.watchSnapshots(1010, [])
92-
93-
// Now docC is out of limbo
94-
.expectLimboDocs()
95-
.expectEvents(fullQuery, {
96-
fromCache: false,
97-
modified: [docA2],
98-
removed: [docC]
99-
})
100-
// Now getDocs(filterQuery) can be resolved
101-
.expectEvents(filterQuery, {
102-
fromCache: false,
103-
removed: [docC],
104-
added: [docA2]
105-
});
38+
return (
39+
spec()
40+
// onSnapshot(fullQuery) - fullQuery is listening to documents in the collection for the full test
41+
.userListens(fullQuery)
42+
.watchAcksFull(fullQuery, 1001, docA, docC)
43+
.expectEvents(fullQuery, {
44+
fromCache: false,
45+
added: [docA, docC]
46+
})
47+
48+
// docC was deleted, this puts docC in limbo and causes a snapshot from cache (metadata-only change)
49+
.watchSends({ removed: [fullQuery] }, docC)
50+
.watchCurrents(fullQuery, 'resume-token-1002')
51+
.watchSnapshots(1002)
52+
.expectLimboDocs(docC.key)
53+
.expectEvents(fullQuery, {
54+
fromCache: true
55+
})
56+
57+
// User begins getDocs(filterQuery)
58+
.userListensForGet(filterQuery)
59+
60+
// getDocs(filterQuery) will not resolve on the snapshot from cache
61+
.expectEvents(filterQuery, {
62+
fromCache: true,
63+
added: [docC]
64+
})
65+
66+
// Watch acks limbo and filter queries
67+
.watchAcks(limboQueryC)
68+
.watchAcks(filterQuery)
69+
70+
// Watch responds to limboQueryC - docC was deleted
71+
.watchSends({ affects: [limboQueryC] })
72+
.watchCurrents(limboQueryC, 'resume-token-1009')
73+
.watchSnapshots(1009, [limboQueryC, fullQuery])
74+
75+
// However, docC is still in limbo because there has not been a global snapshot
76+
.expectLimboDocs(docC.key)
77+
78+
// Rapid events of document update and delete caused by application
79+
.watchSends({ removed: [filterQuery] }, docA)
80+
.watchCurrents(filterQuery, 'resume-token-1004')
81+
.watchSends({ affects: [filterQuery] }, docC)
82+
.watchCurrents(filterQuery, 'resume-token-1005')
83+
.watchSends({ removed: [filterQuery] }, docC)
84+
.watchSends({ affects: [filterQuery] }, docA2)
85+
.watchCurrents(filterQuery, 'resume-token-1007')
86+
87+
.watchSnapshots(1010, [fullQuery, limboQueryC])
88+
89+
// All changes are current and we get a global snapshot
90+
.watchSnapshots(1010, [])
91+
92+
// Now docC is out of limbo
93+
.expectLimboDocs()
94+
.expectEvents(fullQuery, {
95+
fromCache: false,
96+
modified: [docA2],
97+
removed: [docC]
98+
})
99+
// Now getDocs(filterQuery) can be resolved
100+
.expectEvents(filterQuery, {
101+
fromCache: false,
102+
removed: [docC],
103+
added: [docA2]
104+
})
105+
);
106106
});
107107
specTest('8474-deleted', [], () => {
108-
109108
// onSnapshot(fullQuery)
110109
const fullQuery = query('collection');
111110

112111
// getDocs(filterQuery)
113112
const filterQuery = query('collection', filter('included', '==', true));
114113

115-
const docA = doc('collection/a', 1000, {key: 'a', included: false});
116-
const docA2 = doc('collection/a', 1007, {key: 'a', included: true});
117-
const docC = doc('collection/c', 1002, {key: 'c', included: true});
114+
const docA = doc('collection/a', 1000, { key: 'a', included: false });
115+
const docA2 = doc('collection/a', 1007, { key: 'a', included: true });
116+
const docC = doc('collection/c', 1002, { key: 'c', included: true });
118117
const docCDeleted = deletedDoc('collection/c', 1009);
119118

120119
const limboQueryC = newQueryForPath(docC.key.path);
121120

122-
return spec()
123-
// onSnapshot(fullQuery) - fullQuery is listening to documents in the collection for the full test
124-
.userListens(fullQuery)
125-
.watchAcksFull(fullQuery, 1001, docA, docC)
126-
.expectEvents(fullQuery, {
127-
fromCache: false,
128-
added: [docA, docC]
129-
})
130-
131-
// docC was deleted, this puts docC in limbo and causes a snapshot from cache (metadata-only change)
132-
.watchSends({removed: [fullQuery]}, docC)
133-
.watchCurrents(fullQuery, 'resume-token-1002')
134-
.watchSnapshots(1002)
135-
.expectLimboDocs(docC.key)
136-
.expectEvents(fullQuery, {
137-
fromCache: true,
138-
})
139-
140-
// User begins getDocs(filterQuery)
141-
.userListensForGet(filterQuery)
142-
143-
// getDocs(filterQuery) will not resolve on the snapshot from cache
144-
.expectEvents(filterQuery, {
145-
fromCache: true,
146-
added: [docC]
147-
})
148-
149-
// Watch acks limbo and filter queries
150-
.watchAcks(limboQueryC)
151-
.watchAcks(filterQuery)
152-
153-
// Watch responds to limboQueryC - docC was deleted
154-
.watchSends({affects: [limboQueryC]}, docCDeleted)
155-
.watchCurrents(limboQueryC, 'resume-token-1009')
156-
.watchSnapshots(1009, [limboQueryC, fullQuery])
157-
158-
// However, docC is still in limbo because there has not been a global snapshot
159-
.expectLimboDocs(docC.key)
160-
161-
// Rapid events of document update and delete caused by application
162-
.watchSends({removed: [filterQuery]}, docA)
163-
.watchCurrents(filterQuery, 'resume-token-1004')
164-
.watchSends({affects: [filterQuery]}, docC)
165-
.watchCurrents(filterQuery, 'resume-token-1005')
166-
.watchSends({removed: [filterQuery]}, docC)
167-
.watchSends({affects: [filterQuery]}, docA2)
168-
.watchCurrents(filterQuery, 'resume-token-1007')
169-
170-
.watchSnapshots(1010, [fullQuery, limboQueryC])
171-
172-
// All changes are current and we get a global snapshot
173-
.watchSnapshots(1010, [])
174-
175-
// Now docC is out of limbo
176-
.expectLimboDocs()
177-
.expectEvents(fullQuery, {
178-
fromCache: false,
179-
modified: [docA2],
180-
removed: [docC]
181-
})
182-
// Now getDocs(filterQuery) can be resolved
183-
.expectEvents(filterQuery, {
184-
fromCache: false,
185-
removed: [docC],
186-
added: [docA2]
187-
})
188-
189-
// No more expected events
190-
.watchSnapshots(1100, []);
121+
return (
122+
spec()
123+
// onSnapshot(fullQuery) - fullQuery is listening to documents in the collection for the full test
124+
.userListens(fullQuery)
125+
.watchAcksFull(fullQuery, 1001, docA, docC)
126+
.expectEvents(fullQuery, {
127+
fromCache: false,
128+
added: [docA, docC]
129+
})
130+
131+
// docC was deleted, this puts docC in limbo and causes a snapshot from cache (metadata-only change)
132+
.watchSends({ removed: [fullQuery] }, docC)
133+
.watchCurrents(fullQuery, 'resume-token-1002')
134+
.watchSnapshots(1002)
135+
.expectLimboDocs(docC.key)
136+
.expectEvents(fullQuery, {
137+
fromCache: true
138+
})
139+
140+
// User begins getDocs(filterQuery)
141+
.userListensForGet(filterQuery)
142+
143+
// getDocs(filterQuery) will not resolve on the snapshot from cache
144+
.expectEvents(filterQuery, {
145+
fromCache: true,
146+
added: [docC]
147+
})
148+
149+
// Watch acks limbo and filter queries
150+
.watchAcks(limboQueryC)
151+
.watchAcks(filterQuery)
152+
153+
// Watch responds to limboQueryC - docC was deleted
154+
.watchSends({ affects: [limboQueryC] }, docCDeleted)
155+
.watchCurrents(limboQueryC, 'resume-token-1009')
156+
.watchSnapshots(1009, [limboQueryC, fullQuery])
157+
158+
// However, docC is still in limbo because there has not been a global snapshot
159+
.expectLimboDocs(docC.key)
160+
161+
// Rapid events of document update and delete caused by application
162+
.watchSends({ removed: [filterQuery] }, docA)
163+
.watchCurrents(filterQuery, 'resume-token-1004')
164+
.watchSends({ affects: [filterQuery] }, docC)
165+
.watchCurrents(filterQuery, 'resume-token-1005')
166+
.watchSends({ removed: [filterQuery] }, docC)
167+
.watchSends({ affects: [filterQuery] }, docA2)
168+
.watchCurrents(filterQuery, 'resume-token-1007')
169+
170+
.watchSnapshots(1010, [fullQuery, limboQueryC])
171+
172+
// All changes are current and we get a global snapshot
173+
.watchSnapshots(1010, [])
174+
175+
// Now docC is out of limbo
176+
.expectLimboDocs()
177+
.expectEvents(fullQuery, {
178+
fromCache: false,
179+
modified: [docA2],
180+
removed: [docC]
181+
})
182+
// Now getDocs(filterQuery) can be resolved
183+
.expectEvents(filterQuery, {
184+
fromCache: false,
185+
removed: [docC],
186+
added: [docA2]
187+
})
188+
189+
// No more expected events
190+
.watchSnapshots(1100, [])
191+
);
191192
});
192193

193194
specTest('Events are raised after watch ack', [], () => {

packages/firestore/test/unit/specs/spec_builder.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,10 @@ export class SpecBuilder {
317317

318318
/** Listen to query using the same options as executing a getDoc or getDocs */
319319
userListensForGet(query: Query, resume?: ResumeSpec): this {
320-
this.addUserListenStep(query, resume, { includeMetadataChanges: true, waitForSyncWhenOnline: true });
320+
this.addUserListenStep(query, resume, {
321+
includeMetadataChanges: true,
322+
waitForSyncWhenOnline: true
323+
});
321324
return this;
322325
}
323326

0 commit comments

Comments
 (0)