Skip to content
This repository was archived by the owner on May 12, 2024. It is now read-only.

Commit 575afb4

Browse files
committed
refactor: wip firestore [skip ci]
1 parent a3a3852 commit 575afb4

File tree

7 files changed

+139
-149
lines changed

7 files changed

+139
-149
lines changed

__tests__/core/firestore/collection.spec.ts

+15-65
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@ describe('collections', () => {
2020
await new Promise((res, rej) => {
2121
resolve = jest.fn(res)
2222
reject = jest.fn(rej)
23-
unbind = bindCollection({
24-
target,
25-
collection,
26-
resolve,
27-
reject,
28-
ops,
29-
})
23+
unbind = bindCollection(target, collection, ops, resolve, reject)
3024
})
3125
})
3226

@@ -122,13 +116,7 @@ describe('collections', () => {
122116
throw new Error('Promise was not called')
123117
}
124118
await new Promise((resolve, reject) => {
125-
unbind = bindCollection({
126-
target,
127-
collection,
128-
resolve,
129-
reject,
130-
ops,
131-
})
119+
unbind = bindCollection(target, collection, ops, resolve, reject)
132120
})
133121

134122
expect(unbindSpy).not.toHaveBeenCalled()
@@ -154,7 +142,7 @@ describe('collections', () => {
154142
collection.onSnapshot = jest.fn(fakeOnSnapshot)
155143
await expect(
156144
new Promise((resolve, reject) => {
157-
bindCollection({ target, collection, resolve, reject, ops })
145+
bindCollection(target, collection, ops, resolve, reject)
158146
})
159147
).rejects.toThrow()
160148
// @ts-ignore
@@ -165,13 +153,7 @@ describe('collections', () => {
165153
await collection.add({ foo: 'foo' })
166154
await collection.add({ foo: 'foo' })
167155
const promise = new Promise((resolve, reject) => {
168-
bindCollection({
169-
target,
170-
collection,
171-
resolve,
172-
reject,
173-
ops,
174-
})
156+
bindCollection(target, collection, ops, resolve, reject)
175157
})
176158
await promise
177159
expect(target.value).toEqual([{ foo: 'foo' }, { foo: 'foo' }])
@@ -183,13 +165,7 @@ describe('collections', () => {
183165
throw new Error('Promise was not called')
184166
}
185167
const promise = new Promise((resolve, reject) => {
186-
unbind = bindCollection({
187-
target,
188-
collection,
189-
resolve,
190-
reject,
191-
ops,
192-
})
168+
unbind = bindCollection(target, collection, ops, resolve, reject)
193169
})
194170
await promise
195171
expect(target.value).toEqual([{ foo: 'foo' }])
@@ -203,13 +179,7 @@ describe('collections', () => {
203179
throw new Error('Promise was not called')
204180
}
205181
const promise = new Promise((resolve, reject) => {
206-
unbind = bindCollection({
207-
target,
208-
collection,
209-
resolve,
210-
reject,
211-
ops,
212-
})
182+
unbind = bindCollection(target, collection, ops, resolve, reject)
213183
})
214184
await promise
215185
expect(target.value).toEqual([{ foo: 'foo' }])
@@ -223,13 +193,7 @@ describe('collections', () => {
223193
throw new Error('Promise was not called')
224194
}
225195
const promise = new Promise((resolve, reject) => {
226-
unbind = bindCollection({
227-
target,
228-
collection,
229-
resolve,
230-
reject,
231-
ops,
232-
})
196+
unbind = bindCollection(target, collection, ops, resolve, reject)
233197
})
234198
await promise
235199
expect(target.value).toEqual([{ foo: 'foo' }])
@@ -244,10 +208,9 @@ describe('collections', () => {
244208
await other.add({ b: 1 })
245209

246210
await new Promise((resolve, reject) => {
247-
unbind = bindCollection(
248-
{ target, collection: other, resolve, reject, ops },
249-
{ reset: false }
250-
)
211+
unbind = bindCollection(target, other, ops, resolve, reject, {
212+
reset: false,
213+
})
251214
})
252215
expect(target.value).toEqual([{ a: 0 }, { b: 1 }])
253216
unbind()
@@ -265,10 +228,7 @@ describe('collections', () => {
265228
// force the unbind without resetting the value
266229
unbind(false)
267230
const promise = new Promise((resolve, reject) => {
268-
bindCollection(
269-
{ target, collection: other, resolve, reject, ops },
270-
{ wait: true }
271-
)
231+
bindCollection(target, other, ops, resolve, reject, { wait: true })
272232
})
273233
expect(target.value).toEqual([{ foo: 'foo' }, { foo: 'foo' }])
274234
await promise
@@ -283,16 +243,9 @@ describe('collections', () => {
283243
// @ts-ignore
284244
target.value = 'foo'
285245
await new Promise((resolve, reject) => {
286-
bindCollection(
287-
{
288-
target,
289-
collection: db.collection() as any,
290-
resolve,
291-
reject,
292-
ops,
293-
},
294-
{ wait: true }
295-
)
246+
bindCollection(target, db.collection() as any, ops, resolve, reject, {
247+
wait: true,
248+
})
296249
})
297250
expect(target.value).toEqual([])
298251
})
@@ -309,10 +262,7 @@ describe('collections', () => {
309262
// force the unbind without resetting the value
310263
unbind(false)
311264
const promise = new Promise((resolve, reject) => {
312-
bindCollection(
313-
{ target, collection: other, resolve, reject, ops },
314-
{ wait: true }
315-
)
265+
bindCollection(target, other, ops, resolve, reject, { wait: true })
316266
})
317267
expect(target.value).toEqual([])
318268
await promise

__tests__/core/firestore/document.spec.ts

+12-20
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('documents', () => {
2222
await new Promise((res, rej) => {
2323
resolve = jest.fn(res)
2424
reject = jest.fn(rej)
25-
bindDocument({ target, document, resolve, reject, ops })
25+
bindDocument(target, document, ops, resolve, reject)
2626
})
2727
})
2828

@@ -40,14 +40,7 @@ describe('documents', () => {
4040
await new Promise((res, rej) => {
4141
resolve = jest.fn(res)
4242
reject = jest.fn(rej)
43-
bindDocument({
44-
target,
45-
46-
document: collection.doc(),
47-
resolve,
48-
reject,
49-
ops,
50-
})
43+
bindDocument(target, collection.doc(), ops, resolve, reject)
5144
})
5245
expect(target.value).toBe(null)
5346
expect(resolve).toHaveBeenCalledWith(null)
@@ -75,7 +68,7 @@ describe('documents', () => {
7568

7669
it('adds non-enumerable id', async () => {
7770
document = collection.doc('some-id')
78-
bindDocument({ target, document, resolve, reject, ops })
71+
bindDocument(target, document, ops, resolve, reject)
7972
await document.update({ foo: 'foo' })
8073
expect(Object.getOwnPropertyDescriptor(target.value, 'id')).toEqual({
8174
configurable: false,
@@ -93,7 +86,7 @@ describe('documents', () => {
9386
throw new Error('Promise was not called')
9487
}
9588
await new Promise((resolve, reject) => {
96-
unbind = bindDocument({ target, document, resolve, reject, ops })
89+
unbind = bindDocument(target, document, ops, resolve, reject)
9790
})
9891

9992
expect(unbindSpy).not.toHaveBeenCalled()
@@ -118,7 +111,7 @@ describe('documents', () => {
118111
document.onSnapshot = jest.fn(fakeOnSnapshot)
119112
await expect(
120113
new Promise((resolve, reject) => {
121-
bindDocument({ target, document, resolve, reject, ops })
114+
bindDocument(target, document, ops, resolve, reject)
122115
})
123116
).rejects.toThrow()
124117
// @ts-ignore
@@ -128,7 +121,7 @@ describe('documents', () => {
128121
it('resolves when the document is set', async () => {
129122
await document.update({ foo: 'foo' })
130123
const promise = new Promise((resolve, reject) => {
131-
bindDocument({ target, document, resolve, reject, ops })
124+
bindDocument(target, document, ops, resolve, reject)
132125
})
133126
await promise
134127
expect(target.value).toEqual({ foo: 'foo' })
@@ -140,7 +133,7 @@ describe('documents', () => {
140133
throw new Error('Promise was not called')
141134
}
142135
const promise = new Promise((resolve, reject) => {
143-
unbind = bindDocument({ target, document, resolve, reject, ops })
136+
unbind = bindDocument(target, document, ops, resolve, reject)
144137
})
145138
await promise
146139
expect(target.value).toEqual({ foo: 'foo' })
@@ -154,7 +147,7 @@ describe('documents', () => {
154147
throw new Error('Promise was not called')
155148
}
156149
const promise = new Promise((resolve, reject) => {
157-
unbind = bindDocument({ target, document, resolve, reject, ops })
150+
unbind = bindDocument(target, document, ops, resolve, reject)
158151
})
159152
await promise
160153
expect(target.value).toEqual({ foo: 'foo' })
@@ -168,7 +161,7 @@ describe('documents', () => {
168161
throw new Error('Promise was not called')
169162
}
170163
const promise = new Promise((resolve, reject) => {
171-
unbind = bindDocument({ target, document, resolve, reject, ops })
164+
unbind = bindDocument(target, document, ops, resolve, reject)
172165
})
173166
await promise
174167
expect(target.value).toEqual({ foo: 'foo' })
@@ -182,10 +175,9 @@ describe('documents', () => {
182175
throw new Error('Promise was not called')
183176
}
184177
const promise = new Promise((resolve, reject) => {
185-
unbind = bindDocument(
186-
{ target, document, resolve, reject, ops },
187-
{ reset: false }
188-
)
178+
unbind = bindDocument(target, document, ops, resolve, reject, {
179+
reset: false,
180+
})
189181
})
190182
await promise
191183
expect(target.value).toEqual({ foo: 'foo' })

__tests__/core/firestore/options.spec.ts

+6-10
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ describe('options', () => {
2929
await new Promise((res, rej) => {
3030
resolve = jest.fn(res)
3131
reject = jest.fn(rej)
32-
bindDocument(
33-
{ target, document, resolve, reject, ops },
34-
{ serialize: spy }
35-
)
32+
bindDocument(target, document, ops, resolve, reject, { serialize: spy })
3633
})
3734
expect(spy).toHaveBeenCalledTimes(1)
3835
expect(spy).toBeCalledWith(
@@ -46,10 +43,9 @@ describe('options', () => {
4643
await new Promise((res, rej) => {
4744
resolve = jest.fn(res)
4845
reject = jest.fn(rej)
49-
bindCollection(
50-
{ target, collection, resolve, reject, ops },
51-
{ serialize: spy }
52-
)
46+
bindCollection(target, collection, ops, resolve, reject, {
47+
serialize: spy,
48+
})
5349
})
5450
expect(spy).toHaveBeenCalledTimes(1)
5551
expect(spy).toBeCalledWith(
@@ -65,7 +61,7 @@ describe('options', () => {
6561
await new Promise((res, rej) => {
6662
resolve = jest.fn(res)
6763
reject = jest.fn(rej)
68-
bindDocument({ target, document, resolve, reject, ops })
64+
bindDocument(target, document, ops, resolve, reject)
6965
})
7066
expect(spy).toHaveBeenCalledTimes(1)
7167
expect(spy).toBeCalledWith(
@@ -83,7 +79,7 @@ describe('options', () => {
8379
await new Promise((res, rej) => {
8480
resolve = jest.fn(res)
8581
reject = jest.fn(rej)
86-
bindCollection({ target, collection, resolve, reject, ops })
82+
bindCollection(target, collection, ops, resolve, reject)
8783
})
8884
expect(spy).toHaveBeenCalledTimes(1)
8985
expect(spy).toBeCalledWith(

__tests__/core/firestore/refs-collections.spec.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@ describe('refs in collections', () => {
3232
return new Promise(
3333
(resolve, reject) =>
3434
(unbind = bindCollection(
35-
{
36-
target: target[key],
37-
collection,
38-
resolve,
39-
reject,
40-
ops,
41-
},
35+
target[key],
36+
collection,
37+
ops,
38+
resolve,
39+
reject,
4240
options
4341
))
4442
)

__tests__/core/firestore/refs-documents.spec.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ describe('refs in documents', () => {
6363
return new Promise(
6464
(resolve, reject) =>
6565
(unbind = bindDocument(
66-
{ target: target[key], document, resolve, reject, ops },
66+
target[key],
67+
document,
68+
ops,
69+
resolve,
70+
reject,
6771
options
6872
))
6973
)

src/firestore/index.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@ interface BindCollectionParameter extends CommonBindOptionsParameter {
182182
// TODO: refactor without using an object to improve size like the other functions
183183

184184
export function bindCollection(
185-
{ target, collection, ops, resolve, reject }: BindCollectionParameter,
185+
target: BindCollectionParameter['target'],
186+
collection: BindCollectionParameter['collection'],
187+
ops: BindCollectionParameter['ops'],
188+
resolve: BindCollectionParameter['resolve'],
189+
reject: BindCollectionParameter['reject'],
186190
extraOptions: FirestoreOptions = DEFAULT_OPTIONS
187191
) {
188192
const options = Object.assign({}, DEFAULT_OPTIONS, extraOptions) // fill default values
@@ -318,7 +322,11 @@ interface BindDocumentParameter extends CommonBindOptionsParameter {
318322
* @param extraOptions
319323
*/
320324
export function bindDocument(
321-
{ target, document, resolve, reject, ops }: BindDocumentParameter,
325+
target: BindDocumentParameter['target'],
326+
document: BindDocumentParameter['document'],
327+
ops: BindDocumentParameter['ops'],
328+
resolve: BindDocumentParameter['resolve'],
329+
reject: BindDocumentParameter['reject'],
322330
extraOptions: FirestoreOptions = DEFAULT_OPTIONS
323331
) {
324332
const options = Object.assign({}, DEFAULT_OPTIONS, extraOptions) // fill default values

0 commit comments

Comments
 (0)