Skip to content

Commit 4a3afb4

Browse files
committed
refactor(database): use only one onValue
1 parent 5137a99 commit 4a3afb4

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/database/subscribe.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,20 @@ export function bindAsObject(
8181
) {
8282
const key = 'value'
8383
const options = Object.assign({}, DEFAULT_OPTIONS, extraOptions)
84-
const unsub = onValue(
84+
85+
const unsubscribe = onValue(
8586
document,
8687
(snapshot) => {
87-
resolve(snapshot)
88-
unsub()
88+
const value = options.serialize(snapshot)
89+
ops.set(target, key, value)
90+
// resolve the promise
91+
resolve(value)
8992
},
9093
reject
9194
)
92-
// FIXME: Use only one onValue and
93-
const listener = onValue(
94-
document,
95-
(snapshot) => {
96-
ops.set(target, key, options.serialize(snapshot))
97-
}
98-
// TODO: allow passing a cancel callback
99-
// cancelCallback
100-
)
10195

10296
return (reset?: ResetOption) => {
103-
listener()
97+
unsubscribe()
10498
if (reset !== false) {
10599
const value = typeof reset === 'function' ? reset() : null
106100
ops.set(target, key, value)

0 commit comments

Comments
 (0)