File tree 2 files changed +51
-4
lines changed
2 files changed +51
-4
lines changed Original file line number Diff line number Diff line change @@ -116,10 +116,9 @@ function install (Vue, options) {
116
116
}
117
117
118
118
Vue . prototype . $unbind = function ( key ) {
119
- unbind ( {
120
- vm : this ,
121
- key,
122
- } )
119
+ this . _firestoreUnbinds [ key ] ( )
120
+ delete this . _firestoreUnbinds [ key ]
121
+ delete this . $firestoreRefs [ key ]
123
122
}
124
123
}
125
124
Original file line number Diff line number Diff line change
1
+ import test from 'ava'
2
+ import sinon from 'sinon'
3
+ import Vuefire from '../src'
4
+ import {
5
+ createSnapshot
6
+ } from '../src/utils'
7
+ import {
8
+ db ,
9
+ tick ,
10
+ Vue
11
+ } from './helpers'
12
+
13
+ Vue . use ( Vuefire )
14
+
15
+ test . beforeEach ( async t => {
16
+ t . context . collection = db . collection ( )
17
+ t . context . document = t . context . collection . doc ( )
18
+ t . context . vm = new Vue ( {
19
+ render ( h ) {
20
+ return h ( 'ul' , this . items && this . items . map (
21
+ item => h ( 'li' , [ item ] )
22
+ ) )
23
+ } ,
24
+ // purposely set items as null
25
+ // but it's a good practice to set it to an empty array
26
+ data : ( ) => ( {
27
+ items : null ,
28
+ item : null ,
29
+ } ) ,
30
+ firestore : {
31
+ items : t . context . collection ,
32
+ item : t . context . document
33
+ }
34
+ } ) . $mount ( )
35
+ await tick ( )
36
+ } )
37
+
38
+ test ( 'manually unbinds a collection' , async t => {
39
+ const vm = t . context . vm
40
+ const spy = sinon . spy ( vm . _firestoreUnbinds , 'items' )
41
+ vm . $unbind ( 'items' )
42
+ t . is ( spy . callCount , 1 )
43
+ t . deepEqual ( Object . keys ( vm . _firestoreUnbinds ) , [ 'item' ] )
44
+ t . deepEqual ( Object . keys ( vm . $firestoreRefs ) , [ 'item' ] )
45
+ t . deepEqual ( vm . items , [ ] )
46
+ await t . context . collection . add ( { text : 'foo' } )
47
+ t . deepEqual ( vm . items , [ ] )
48
+ } )
You can’t perform that action at this time.
0 commit comments