Skip to content

Commit affb5ef

Browse files
committed
refactor: remove old interface
1 parent ae90bed commit affb5ef

File tree

2 files changed

+21
-25
lines changed

2 files changed

+21
-25
lines changed

src/firestore/subscribe.ts

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ResetOption,
88
_DataSourceOptions,
99
noop,
10+
_ResolveRejectFn,
1011
} from '../shared'
1112
import { ref, Ref, unref } from 'vue-demi'
1213
import type {
@@ -99,9 +100,9 @@ function updateDataFromDocumentSnapshot<T>(
99100
path: string,
100101
snapshot: DocumentSnapshot<T>,
101102
subs: Record<string, FirestoreSubscription>,
102-
ops: CommonBindOptionsParameter['ops'],
103+
ops: OperationsType,
103104
depth: number,
104-
resolve: CommonBindOptionsParameter['resolve']
105+
resolve: _ResolveRejectFn
105106
) {
106107
const [data, refs] = extractRefs(
107108
// @ts-expect-error: FIXME: use better types
@@ -119,7 +120,7 @@ interface SubscribeToDocumentParameter {
119120
path: string
120121
depth: number
121122
resolve: () => void
122-
ops: CommonBindOptionsParameter['ops']
123+
ops: OperationsType
123124
ref: DocumentReference
124125
}
125126

@@ -161,9 +162,9 @@ function subscribeToRefs(
161162
path: string | number,
162163
subs: Record<string, FirestoreSubscription>,
163164
refs: Record<string, DocumentReference>,
164-
ops: CommonBindOptionsParameter['ops'],
165+
ops: OperationsType,
165166
depth: number,
166-
resolve: CommonBindOptionsParameter['resolve']
167+
resolve: _ResolveRejectFn
167168
) {
168169
const refKeys = Object.keys(refs)
169170
const missingKeys = Object.keys(subs).filter(
@@ -217,22 +218,12 @@ function subscribeToRefs(
217218
})
218219
}
219220

220-
interface CommonBindOptionsParameter {
221-
// vm: Record<string, any>
222-
target: Ref<unknown>
223-
// key: string
224-
// Override this property in necessary functions
225-
resolve: (value: unknown) => void
226-
reject: (error: unknown) => void
227-
ops: OperationsType
228-
}
229-
230221
export function bindCollection<T = unknown>(
231222
target: Ref<unknown[]>,
232223
collection: CollectionReference<T> | Query<T>,
233-
ops: CommonBindOptionsParameter['ops'],
234-
resolve: CommonBindOptionsParameter['resolve'],
235-
reject: CommonBindOptionsParameter['reject'],
224+
ops: OperationsType,
225+
resolve: _ResolveRejectFn,
226+
reject: _ResolveRejectFn,
236227
extraOptions?: FirestoreRefOptions
237228
) {
238229
// FIXME: can be removed now
@@ -367,10 +358,6 @@ export function bindCollection<T = unknown>(
367358
}
368359
}
369360

370-
interface BindDocumentParameter extends CommonBindOptionsParameter {
371-
document: DocumentReference
372-
}
373-
374361
/**
375362
* Binds a Document to a property of vm
376363
* @param param0
@@ -379,9 +366,9 @@ interface BindDocumentParameter extends CommonBindOptionsParameter {
379366
export function bindDocument<T>(
380367
target: Ref<unknown>,
381368
document: DocumentReference<T>,
382-
ops: BindDocumentParameter['ops'],
383-
resolve: BindDocumentParameter['resolve'],
384-
reject: BindDocumentParameter['reject'],
369+
ops: OperationsType,
370+
resolve: _ResolveRejectFn,
371+
reject: _ResolveRejectFn,
385372
extraOptions?: FirestoreRefOptions
386373
) {
387374
const options = Object.assign({}, DEFAULT_OPTIONS, extraOptions) // fill default values

src/shared.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,12 @@ export interface _DataSourceOptions {
254254
export type _Mutable<T> = {
255255
-readonly [P in keyof T]: T[P]
256256
}
257+
258+
/**
259+
* helper type to get the type of a promise
260+
*
261+
* @internal
262+
*/
263+
export interface _ResolveRejectFn {
264+
(value: unknown): void
265+
}

0 commit comments

Comments
 (0)