File tree 2 files changed +18
-0
lines changed
2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -123,6 +123,9 @@ function install (Vue, options) {
123
123
124
124
// TODO test if $bind exist and warns
125
125
Vue . prototype . $bind = function ( key , ref ) {
126
+ if ( this . _firestoreUnbinds [ key ] ) {
127
+ this . $unbind ( key )
128
+ }
126
129
const promise = bind ( {
127
130
vm : this ,
128
131
key,
Original file line number Diff line number Diff line change @@ -64,3 +64,18 @@ test('rejects the promise when errors', async t => {
64
64
document . onSnapshot . restore ( )
65
65
collection . onSnapshot . restore ( )
66
66
} )
67
+
68
+ test ( 'unbinds previously bound refs' , async t => {
69
+ const { vm, document } = t . context
70
+ await document . update ( { foo : 'foo' } )
71
+ const doc2 = db . collection ( ) . doc ( )
72
+ await doc2 . update ( { bar : 'bar' } )
73
+ await vm . $bind ( 'item' , document )
74
+ t . is ( vm . $firestoreRefs . item , document )
75
+ t . deepEqual ( vm . item , { foo : 'foo' } )
76
+ await vm . $bind ( 'item' , doc2 )
77
+ t . deepEqual ( vm . item , { bar : 'bar' } )
78
+ await document . update ( { foo : 'baz' } )
79
+ t . is ( vm . $firestoreRefs . item , doc2 )
80
+ t . deepEqual ( vm . item , { bar : 'bar' } )
81
+ } )
You can’t perform that action at this time.
0 commit comments