@@ -117,30 +117,19 @@ export function databasePlugin(
117
117
) {
118
118
const options = Object . assign ( { } , globalOptions , userOptions )
119
119
const target = toRef ( this . $data as any , key )
120
- let unbinds = rtdbUnbinds . get ( this )
121
-
122
- if ( unbinds ) {
123
- if ( unbinds [ key ] ) {
124
- unbinds [ key ] (
125
- // if wait, allow overriding with a function or reset, otherwise, force reset to false
126
- // else pass the reset option
127
- options . wait
128
- ? typeof options . reset === 'function'
129
- ? options . reset
130
- : false
131
- : options . reset
132
- )
133
- }
134
- } else {
135
- rtdbUnbinds . set ( this , ( unbinds = { } ) )
120
+ if ( ! rtdbUnbinds . has ( this ) ) {
121
+ rtdbUnbinds . set ( this , { } )
136
122
}
123
+ const unbinds = rtdbUnbinds . get ( this ) !
137
124
138
- // TODO: ensure creating refs outside of the scope of the component here doesn't create a memory leak
125
+ if ( unbinds [ key ] ) {
126
+ unbinds [ key ] ( options . wait )
127
+ }
128
+
129
+ // FIXME: Create a single scopeEffect per instance that wraps thin call and stop the effect scope when `unbind()` is called
139
130
const { promise, unbind } = _useDatabaseRef ( source , { target, ...options } )
140
131
unbinds [ key ] = unbind
141
132
142
- // TODO:
143
- // this._firebaseSources[key] = source
144
133
// we make it readonly for the user but we must change it. Maybe there is a way to have an internal type here but expose a readonly type through a d.ts
145
134
; ( this . $firebaseRefs as Mutable < Record < string , DatabaseReference > > ) [ key ] =
146
135
source . ref
@@ -161,8 +150,13 @@ export function databasePlugin(
161
150
if ( ! bindings ) return
162
151
163
152
for ( const key in bindings ) {
164
- // @ts -expect-error: TODO: try fixing it
165
- this [ bindName ] ( key , bindings [ key ] , globalOptions )
153
+ // @ts -expect-error: bindName is a string here
154
+ this [ bindName ] (
155
+ // ts
156
+ key ,
157
+ bindings [ key ] ,
158
+ globalOptions
159
+ )
166
160
}
167
161
} ,
168
162
@@ -173,7 +167,7 @@ export function databasePlugin(
173
167
unbinds [ key ] ( )
174
168
}
175
169
}
176
- // @ts -expect-error: we are freeing the memory
170
+ // @ts -expect-error: we are freeing the references to avoid memory leaks
177
171
this . $firebaseRefs = null
178
172
} ,
179
173
} )
0 commit comments