Skip to content

Commit 382ade7

Browse files
committed
chore: some todos
1 parent 54a2c67 commit 382ade7

File tree

11 files changed

+48
-51
lines changed

11 files changed

+48
-51
lines changed

src/app/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export const _FirebaseAppInjectionKey: InjectionKey<FirebaseApp> =
1212
* @returns the firebase app
1313
*/
1414
export function useFirebaseApp(name?: string): FirebaseApp {
15-
// TODO: warn no current scope
1615
return (
1716
(getCurrentInstance() &&
1817
inject(

src/auth/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function VueFireAuth(_app?: never) {
2626
// ^
2727
// app: never to prevent the user from just passing `VueFireAuth` without calling the function
2828

29-
// TODO: refactor to share across modules
29+
// TODO: Hopefully we should be able to remove this with the next Vue release
3030
if (process.env.NODE_ENV !== 'production') {
3131
if (_app != null) {
3232
console.warn(`Did you forget to call the VueFireAuth function? It should look like

src/auth/user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const AuthUserInjectSymbol: InjectionKey<Ref<User | null | undefined>> =
1010
* authenticated or when the user logs out. The ref is undefined when the user is not yet loaded.
1111
*/
1212
export function useCurrentUser() {
13-
// TODO: warn no current instance
13+
// TODO: warn no current instance in DEV
1414
return inject(AuthUserInjectSymbol)!
1515
}
1616

src/database/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function _useDatabaseRef(
7575
const p = new Promise<unknown | null>((resolve, reject) => {
7676
if (!referenceValue) {
7777
_unbind = noop
78-
// TODO: maybe we shouldn't resolve this at all?
78+
// resolve to avoid an ever pending promise
7979
return resolve(null)
8080
}
8181

@@ -147,7 +147,8 @@ export function _useDatabaseRef(
147147
_unbind(reset)
148148
}
149149

150-
return Object.defineProperties(data, {
150+
return Object.defineProperties(data as _RefDatabase<unknown>, {
151+
// allow destructuring without interfering with the ref itself
151152
data: { get: () => data },
152153
error: { get: () => error },
153154
pending: { get: () => error },
@@ -166,9 +167,6 @@ export function internalUnbind(
166167
unbinds[key](reset)
167168
delete unbinds[key]
168169
}
169-
// TODO: move to $firestoreUnbind
170-
// delete vm._firebaseSources[key]
171-
// delete vm._firebaseUnbinds[key]
172170
}
173171

174172
export type UseListOptions = UseDatabaseRefOptions

src/database/optionsApi.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ export function databasePlugin(
7373
internalUnbind(key, databaseUnbinds.get(this), reset)
7474
// @ts-expect-error: readonly for the users
7575
delete this.$firebaseRefs[key]
76+
// delete this._firebaseSources[key]
77+
// delete this._firebaseUnbinds[key]
7678
}
7779

7880
GlobalTarget[bindName] = function databaseBind(

src/database/subscribe.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export function bindAsArray(
121121
ops.add(array, index, options.serialize(snapshot))
122122
}
123123
// TODO: cancelcallback
124+
// reject,
124125
)
125126

126127
const removeChildRemovedListener = onChildRemoved(
@@ -158,13 +159,14 @@ export function bindAsArray(
158159
// TODO: cancelcallback
159160
)
160161

161-
const removeValueListener = onValue(
162+
// in case the removeValueListener() is called before onValue returns
163+
let removeValueListener = noop
164+
removeValueListener = onValue(
162165
collection,
163166
(data) => {
164167
const array = unref(arrayRef)
165168
if (options.wait) ops.set(target, key, array)
166169
resolve(data)
167-
// FIXME: this can be called before it's initialized
168170
removeValueListener()
169171
},
170172
reject

src/firestore/index.ts

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function _useFirestoreRef(
7070
const data = options.target || ref<unknown | null>()
7171
// set the initial value from SSR even if the ref comes from outside
7272
data.value = getInitialValue(initialSourceValue, options.ssrKey, data.value)
73-
// TODO: allow passing pending and error refs as option for when this is called using the options api
73+
7474
const pending = ref(true)
7575
const error = ref<FirestoreError>()
7676
// force the type since its value is set right after and undefined isn't possible
@@ -141,12 +141,11 @@ export function _useFirestoreRef(
141141
// create sync, you can read only once the whole thing so maybe we
142142
// should take an option like once: true to not setting up any listener
143143

144-
// TODO: warn else
145144
if (hasCurrentScope) {
146145
onScopeDispose(unbind)
147146
if (getCurrentInstance()) {
148147
// wait for the promise during SSR
149-
// TODO: configurable
148+
// TODO: configurable ssrKey: false to disable this
150149
onServerPrefetch(() => promise.value)
151150
}
152151
}
@@ -159,26 +158,13 @@ export function _useFirestoreRef(
159158
}
160159

161160
// allow to destructure the returned value
162-
Object.defineProperties(data, {
163-
error: {
164-
get: () => error,
165-
},
166-
data: {
167-
get: () => data,
168-
},
169-
pending: {
170-
get: () => pending,
171-
},
172-
promise: {
173-
get: () => promise,
174-
},
175-
unbind: {
176-
get: () => unbind,
177-
},
161+
return Object.defineProperties(data as _RefFirestore<unknown>, {
162+
error: { get: () => error },
163+
data: { get: () => data },
164+
pending: { get: () => pending },
165+
promise: { get: () => promise },
166+
stop: { get: () => stop },
178167
})
179-
180-
// no unwrapRef to have a simpler type
181-
return data as _RefFirestore<unknown>
182168
}
183169

184170
export interface UseCollectionOptions extends _UseFirestoreRefOptions {}
@@ -194,7 +180,6 @@ export function useCollection<
194180
// explicit generic as unknown to allow arbitrary types like numbers or strings
195181
R extends CollectionReference<unknown> | Query<unknown>
196182
>(
197-
// TODO: add MaybeRef
198183
collectionRef: _MaybeRef<_Nullable<R>>,
199184
options?: UseCollectionOptions
200185
): _RefFirestore<_InferReferenceType<R>[]>
@@ -224,7 +209,7 @@ export function useCollection<T>(
224209
}) as _RefFirestore<VueFirestoreQueryData<T>>
225210
}
226211

227-
// TODO: split document and collection into two different parts
212+
// TODO: split document and collection into two different files
228213

229214
export interface UseDocumentOptions extends _UseFirestoreRefOptions {}
230215

src/firestore/subscribe.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,13 @@ function subscribeToRefs(
212212
})
213213
}
214214

215-
// TODO: get rid of the any
216215
interface CommonBindOptionsParameter {
217216
// vm: Record<string, any>
218-
target: Ref<any>
217+
target: Ref<unknown>
219218
// key: string
220219
// Override this property in necessary functions
221-
resolve: (value: any) => void
222-
reject: (error: any) => void
220+
resolve: (value: unknown) => void
221+
reject: (error: unknown) => void
223222
ops: OperationsType
224223
}
225224

@@ -318,8 +317,8 @@ export function bindCollection<T = unknown>(
318317
validDocs[docChanges[i].doc.id] = true
319318
}
320319

321-
resolve = ({ id }) => {
322-
if (id in validDocs) {
320+
resolve = (data) => {
321+
if (data && (data as any).id in validDocs) {
323322
if (++count >= expectedItems) {
324323
// if wait is true, finally set the array
325324
if (options.wait) {
@@ -382,8 +381,6 @@ export function bindDocument<T>(
382381
) {
383382
const options = Object.assign({}, DEFAULT_OPTIONS, extraOptions) // fill default values
384383
const key = 'value'
385-
// TODO: warning check if key exists?
386-
// const boundRefs = Object.create(null)
387384

388385
const subs: Record<string, FirestoreSubscription> = Object.create(null)
389386
// bind here the function so it can be resolved anywhere

src/firestore/utils.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ export const firestoreDefaultConverter: FirestoreDataConverter<VueFirestoreDocum
2323
fromFirestore(snapshot, options) {
2424
return snapshot.exists()
2525
? (Object.defineProperties(snapshot.data(options)!, {
26-
id: {
27-
// TODO: can the `id` change? If so this should be a get
28-
value: snapshot.id,
29-
},
26+
id: { value: snapshot.id },
3027
// TODO: check if worth adding or should be through an option
3128
// $meta: {
3229
// value: snapshot.metadata,
@@ -38,7 +35,7 @@ export const firestoreDefaultConverter: FirestoreDataConverter<VueFirestoreDocum
3835
}
3936

4037
export function extractRefs(
41-
// FIXME: unknown
38+
// TODO: should be unknown instead of DocumentData
4239
doc: DocumentData,
4340
oldDoc: DocumentData | void,
4441
subs: Record<string, { path: string; data: () => DocumentData | null }>
@@ -83,7 +80,9 @@ export function extractRefs(
8380
// TODO: check and remove
8481
// Firestore < 4.13
8582
ref instanceof Date ||
83+
// TODO: instanceof Timestamp?
8684
isTimestamp(ref) ||
85+
// TODO: same?
8786
isGeoPoint(ref)
8887
) {
8988
data[key] = ref

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { FirebaseApp } from 'firebase/app'
22
import type { App } from 'vue'
3-
import { databasePlugin } from '../dist'
43
import { _FirebaseAppInjectionKey } from './app'
54

65
// Database

0 commit comments

Comments
 (0)