Skip to content

Commit f395e87

Browse files
committed
refactor: types and deprecations
1 parent 9b1c738 commit f395e87

File tree

3 files changed

+29
-37
lines changed

3 files changed

+29
-37
lines changed

src/firestore/optionsApi.ts

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,18 @@ import type {
66
} from 'firebase/firestore'
77
import { App, ComponentPublicInstance, effectScope, toRef } from 'vue'
88
import { isVue3 } from 'vue-demi'
9-
import {
10-
bindCollection,
11-
bindDocument,
12-
firestoreOptions,
13-
FirestoreRefOptions,
14-
_GlobalFirestoreRefOptions,
15-
} from './subscribe'
9+
import { FirestoreRefOptions, _GlobalFirestoreRefOptions } from './subscribe'
1610
import { internalUnbind, _useFirestoreRef } from '.'
17-
import { ResetOption, UnbindWithReset } from '../shared'
18-
import { firebaseApp } from '../../tests/utils'
11+
import { ResetOption, UnbindWithReset, _FirestoreDataSource } from '../shared'
1912
import { FirebaseApp } from 'firebase/app'
2013
import { getGlobalScope } from '../globals'
2114
import { useFirebaseApp } from '../app'
2215

23-
export type VueFirestoreObject = Record<
24-
string,
25-
DocumentReference<unknown> | Query<unknown> | CollectionReference<unknown>
26-
>
16+
// TODO: this should be an entry point to generate the corresponding .d.ts file that only gets included if the plugin is imported
2717

18+
export type VueFirestoreObject = Record<string, _FirestoreDataSource>
2819
export type FirestoreOption = VueFirestoreObject | (() => VueFirestoreObject)
2920

30-
// TODO: this should be an entry point to generate the corresponding .d.ts file that only gets included if the plugin is imported
31-
3221
export const firestoreUnbinds = new WeakMap<
3322
object,
3423
Record<string, UnbindWithReset>
@@ -40,7 +29,14 @@ export const firestoreUnbinds = new WeakMap<
4029
*/
4130
export interface FirestorePluginOptions
4231
extends Partial<_GlobalFirestoreRefOptions> {
32+
/**
33+
* @deprecated: was largely unused and not very useful. Please open an issue with use cases if you need this.
34+
*/
4335
bindName?: string
36+
37+
/**
38+
* @deprecated: was largely unused and not very useful. Please open an issue with use cases if you need this.
39+
*/
4440
unbindName?: string
4541
}
4642

@@ -90,10 +86,7 @@ export const firestorePlugin = function firestorePlugin(
9086
GlobalTarget[bindName] = function firestoreBind(
9187
this: ComponentPublicInstance,
9288
key: string,
93-
docOrCollectionRef:
94-
| Query<unknown>
95-
| CollectionReference<unknown>
96-
| DocumentReference<unknown>,
89+
docOrCollectionRef: _FirestoreDataSource,
9790
userOptions?: FirestoreRefOptions
9891
) {
9992
const options = Object.assign({}, globalOptions, userOptions)
@@ -195,20 +188,17 @@ declare module '@vue/runtime-core' {
195188
* @param reference
196189
* @param options
197190
*/
198-
$firestoreBind(
191+
$firestoreBind<T = DocumentData>(
199192
name: string,
200-
// TODO: create proper overloads with generics like in the composition API
201-
reference: Query<unknown> | CollectionReference<unknown>,
193+
reference: Query<T> | CollectionReference<T>,
202194
options?: FirestoreRefOptions
203-
// TODO: match the promise with the type of internalBind
204-
): Promise<DocumentData[]>
195+
): Promise<T[]>
205196

206-
$firestoreBind(
197+
$firestoreBind<T = DocumentData>(
207198
name: string,
208-
// TODO: create proper overloads with generics like in the composition API
209-
reference: DocumentReference<unknown>,
199+
reference: DocumentReference<T>,
210200
options?: FirestoreRefOptions
211-
): Promise<DocumentData>
201+
): Promise<T>
212202

213203
/**
214204
* Unbinds a bound reference

src/shared.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ export function isFirestoreDataReference<T = unknown>(
128128

129129
export function isFirestoreQuery(
130130
source: unknown
131-
): source is FirestoreQuery<unknown> & { path: undefined } { // makes some types so much easier
131+
): source is FirestoreQuery<unknown> & { path: undefined } {
132+
// makes some types so much easier
132133
return isObject(source) && source.type === 'query'
133134
}
134135

@@ -175,6 +176,11 @@ export function callOnceWithArg<T, K>(
175176
}
176177
}
177178

179+
export type _FirestoreDataSource =
180+
| DocumentReference<unknown>
181+
| CollectionReference<unknown>
182+
| FirestoreQuery<unknown>
183+
178184
/**
179185
* @internal
180186
*/

src/ssr/initialState.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
isDatabaseReference,
1212
isFirestoreDataReference,
1313
isFirestoreQuery,
14+
_FirestoreDataSource,
1415
_Nullable,
1516
} from '../shared'
1617

@@ -52,14 +53,9 @@ export function useSSRInitialState(
5253
return initialStatesMap.get(firebaseApp)!
5354
}
5455

55-
type FirestoreDataSource =
56-
| DocumentReference<unknown>
57-
| CollectionReference<unknown>
58-
| FirestoreQuery<unknown>
59-
6056
export function getInitialValue(
6157
dataSource: _Nullable<
62-
FirestoreDataSource | DatabaseReference | DatabaseQuery
58+
_FirestoreDataSource | DatabaseReference | DatabaseQuery
6359
>,
6460
ssrKey: string | undefined,
6561
fallbackValue: unknown
@@ -81,7 +77,7 @@ export function getInitialValue(
8177

8278
export function deferInitialValueSetup(
8379
dataSource: _Nullable<
84-
FirestoreDataSource | DatabaseReference | DatabaseQuery
80+
_FirestoreDataSource | DatabaseReference | DatabaseQuery
8581
>,
8682
ssrKey: string | undefined | null,
8783
promise: Promise<unknown>
@@ -103,7 +99,7 @@ export function deferInitialValueSetup(
10399
}
104100

105101
function getDataSourceInfo(
106-
dataSource: FirestoreDataSource | DatabaseReference | DatabaseQuery
102+
dataSource: _FirestoreDataSource | DatabaseReference | DatabaseQuery
107103
) {
108104
return isFirestoreDataReference(dataSource) || isFirestoreQuery(dataSource)
109105
? (['f', dataSource.path] as const)

0 commit comments

Comments
 (0)