Skip to content

Commit 2ebb67b

Browse files
committed
refactor: add notes
1 parent e05d020 commit 2ebb67b

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Diff for: packages/@posva/vuefire-core/src/firestore/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function unsubscribeAll(subs: Record<string, FirestoreSubscription>) {
2828
}
2929

3030
interface UpdateDataFromDocumentSnapshot {
31-
snapshot: firestore.DocumentSnapshot
31+
readonly snapshot: firestore.DocumentSnapshot
3232
subs: Record<string, FirestoreSubscription>
3333
target: CommonBindOptionsParameter['vm']
3434
path: string
@@ -41,6 +41,7 @@ function updateDataFromDocumentSnapshot(
4141
{ snapshot, target, path, subs, ops, depth, resolve }: UpdateDataFromDocumentSnapshot,
4242
options: Required<FirestoreOptions>
4343
) {
44+
// TODO: maybe we should options.serialize the snapshot here
4445
const [data, refs] = extractRefs(snapshot, walkGet(target, path))
4546
// NOTE use ops
4647
ops.set(target, path, data)

Diff for: packages/@posva/vuefire-core/src/firestore/utils.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ export function extractRefs(
2121
): [firestore.DocumentData, Record<string, firestore.DocumentReference>] {
2222
// must be set here because walkGet can return null or undefined
2323
oldDoc = oldDoc || {}
24+
const [data, refs] = result
25+
// TODO: this won't work if the user defines their own defined properties
26+
// should we do it for every non enumerable property?
2427
const idDescriptor = Object.getOwnPropertyDescriptor(doc, 'id')
2528
if (idDescriptor && !idDescriptor.enumerable) {
26-
Object.defineProperty(result[0], 'id', idDescriptor)
29+
Object.defineProperty(data, 'id', idDescriptor)
2730
}
28-
const [data, refs] = result
2931
for (const key in doc) {
3032
const ref = doc[key]
3133
// if it's a ref

0 commit comments

Comments
 (0)