Skip to content

Commit 2a94031

Browse files
committed
refactor: rename obj to target
obj was the object where we're setting data using the key. updateDataFromDocumentSnapshot and subscribeToDocument where both using obj, but I think that it was too generic and that target is better
1 parent 3b301b0 commit 2a94031

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/index.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function bindCollection ({
3939
subs[refKey] = {
4040
unbind: subscribeToDocument({
4141
ref,
42-
obj: innerObj,
42+
target: innerObj,
4343
key: innerKey,
4444
depth,
4545
// TODO parentSubs
@@ -79,10 +79,10 @@ function bindCollection ({
7979
}, reject)
8080
}
8181

82-
function updateDataFromDocumentSnapshot ({ snapshot, obj, key, subs, depth = 0, resolve }) {
82+
function updateDataFromDocumentSnapshot ({ snapshot, target, key, subs, depth = 0, resolve }) {
8383
// TODO extract refs
8484
const [data, refs] = extractRefs(snapshot)
85-
obj[key] = data
85+
target[key] = data
8686
const refKeys = Object.keys(refs)
8787
if (!refKeys.length) return resolve()
8888
// TODO check if no ref is missing
@@ -96,11 +96,11 @@ function updateDataFromDocumentSnapshot ({ snapshot, obj, key, subs, depth = 0,
9696
sub.unbind()
9797
}
9898
// maybe wrap the unbind function to call unbind on every child
99-
const [innerObj, innerKey] = deepGetSplit(obj[key], refKey)
99+
const [innerObj, innerKey] = deepGetSplit(target[key], refKey)
100100
subs[refKey] = {
101101
unbind: subscribeToDocument({
102102
ref,
103-
obj: innerObj,
103+
target: innerObj,
104104
key: innerKey,
105105
depth,
106106
// TODO parentSubs
@@ -115,20 +115,20 @@ function updateDataFromDocumentSnapshot ({ snapshot, obj, key, subs, depth = 0,
115115
})
116116
}
117117

118-
function subscribeToDocument ({ ref, obj, key, depth, resolve }) {
118+
function subscribeToDocument ({ ref, target, key, depth, resolve }) {
119119
const subs = Object.create(null)
120120
const unbind = ref.onSnapshot(doc => {
121121
if (doc.exists) {
122122
updateDataFromDocumentSnapshot({
123123
snapshot: createSnapshot(doc),
124-
obj,
124+
target,
125125
key,
126126
subs,
127127
depth,
128128
resolve
129129
})
130130
} else {
131-
obj[key] = null
131+
target[key] = null
132132
resolve()
133133
}
134134
})
@@ -160,7 +160,7 @@ function bindDocument ({
160160
if (doc.exists) {
161161
updateDataFromDocumentSnapshot({
162162
snapshot: createSnapshot(doc),
163-
obj: vm,
163+
target: vm,
164164
key,
165165
subs,
166166
resolve

0 commit comments

Comments
 (0)