Skip to content

Commit 1ace7e3

Browse files
committed
refactor: rework todos
1 parent eb04206 commit 1ace7e3

File tree

5 files changed

+62
-53
lines changed

5 files changed

+62
-53
lines changed

src/auth/user.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,23 @@ export function updateCurrentUserProfile(profile: {
5454
})
5555
}
5656

57+
/**
58+
* Updates the current user and synchronizes the current user state. This function internally calls `updateEmail()`
59+
*
60+
* @experimental
61+
*
62+
* @param newEmail - the new email address
63+
* @param credential -
64+
*/
5765
export function updateCurrentUserEmail(
5866
newEmail: string,
5967
credential: AuthCredential
6068
) {
6169
return getCurrentUser()
6270
.then((user) => {
6371
if (user) {
64-
// TODO: Maybe this whole function should be dropped since it depends on reauthenticating first or we should let the user do it. Otherwise, we need a way to retrieve the credential token when logging in
72+
// TODO: Maybe this whole function should be dropped since it depends on re-authenticating first or we should
73+
// let the user do it. Otherwise, we need a way to retrieve the credential token when logging in
6574
reauthenticateWithCredential(user, credential)
6675
}
6776
return user

src/firestore/index.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,28 +152,21 @@ export function _useFirestoreRef(
152152
}
153153

154154
// only add the first promise to the pending ones
155-
// TODO: can we make this tree shakeable?
156155
if (initialSourceValue) {
157156
removePendingPromise = addPendingPromise(
158157
promise.value,
159158
initialSourceValue,
160159
options.ssrKey
161160
)
162161
}
163-
164-
// TODO: SSR serialize the values for Nuxt to expose them later and use them
165-
// as initial values while specifying a wait: true to only swap objects once
166-
// Firebase has done its initial sync. Also, on server, you don't need to
167-
// create sync, you can read only once the whole thing so maybe we
168-
// should take an option like once: true to not setting up any listener
162+
if (getCurrentInstance()) {
163+
// wait for the promise during SSR
164+
// TODO: configurable ssrKey: false to disable this
165+
onServerPrefetch(() => promise.value)
166+
}
169167

170168
if (hasCurrentScope) {
171169
onScopeDispose(stop)
172-
if (getCurrentInstance()) {
173-
// wait for the promise during SSR
174-
// TODO: configurable ssrKey: false to disable this
175-
onServerPrefetch(() => promise.value)
176-
}
177170
}
178171

179172
function stop(reset: ResetOption = options.reset) {

src/firestore/subscribe.ts

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -161,44 +161,49 @@ function subscribeToDocument(
161161
let unbind = noop
162162

163163
if (options.once) {
164-
getDoc(ref).then((snapshot) => {
165-
if (snapshot.exists()) {
166-
updateDataFromDocumentSnapshot(
167-
options,
168-
target,
169-
path,
170-
snapshot,
171-
subs,
172-
ops,
173-
depth,
174-
resolve,
175-
reject
176-
)
177-
} else {
178-
ops.set(target, path, null)
179-
resolve()
180-
}
181-
})
182-
// TODO: catch?
164+
getDoc(ref)
165+
.then((snapshot) => {
166+
if (snapshot.exists()) {
167+
updateDataFromDocumentSnapshot(
168+
options,
169+
target,
170+
path,
171+
snapshot,
172+
subs,
173+
ops,
174+
depth,
175+
resolve,
176+
reject
177+
)
178+
} else {
179+
ops.set(target, path, null)
180+
resolve()
181+
}
182+
})
183+
.catch(reject)
183184
} else {
184-
unbind = onSnapshot(ref, (snapshot) => {
185-
if (snapshot.exists()) {
186-
updateDataFromDocumentSnapshot(
187-
options,
188-
target,
189-
path,
190-
snapshot,
191-
subs,
192-
ops,
193-
depth,
194-
resolve,
195-
reject
196-
)
197-
} else {
198-
ops.set(target, path, null)
199-
resolve()
200-
}
201-
})
185+
unbind = onSnapshot(
186+
ref,
187+
(snapshot) => {
188+
if (snapshot.exists()) {
189+
updateDataFromDocumentSnapshot(
190+
options,
191+
target,
192+
path,
193+
snapshot,
194+
subs,
195+
ops,
196+
depth,
197+
resolve,
198+
reject
199+
)
200+
} else {
201+
ops.set(target, path, null)
202+
resolve()
203+
}
204+
},
205+
reject
206+
)
202207
}
203208

204209
return () => {
@@ -274,6 +279,8 @@ function subscribeToRefs(
274279
})
275280
}
276281

282+
// TODO: Remove ops and use just a getter function to be able to retrieve the current target ref and make things work with wait as well
283+
277284
export function bindCollection<T = unknown>(
278285
target: Ref<unknown[]>,
279286
collection: CollectionReference<T> | Query<T>,
@@ -286,7 +293,6 @@ export function bindCollection<T = unknown>(
286293

287294
const { snapshotListenOptions, snapshotOptions, wait, once } = options
288295

289-
// TODO: remove ops
290296
const key = 'value'
291297
// with wait we delay changes to the target until all values are resolved
292298
let arrayRef = ref(wait ? [] : target.value)

src/firestore/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const firestoreDefaultConverter: FirestoreDataConverter<VueFirestoreDocum
2626
? (Object.defineProperties(snapshot.data(options)!, {
2727
id: { value: snapshot.id },
2828
// TODO: check if worth adding or should be through an option
29+
// It could also be an example in the docs about converters
2930
// $meta: {
3031
// value: snapshot.metadata,
3132
// },

src/storage/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ export function useStorageMetadata(
137137
return (metadata.value = newData)
138138
}
139139
)
140-
} else {
141-
// TODO: DEV warning
140+
} else if (process.env.NODE_ENV !== 'production') {
141+
console.warn('[VueFire]: "update()" called with no storage source.')
142142
}
143143
return promise.value
144144
}

0 commit comments

Comments
 (0)