File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ class Store {
23
23
this . _wrappedGetters = Object . create ( null )
24
24
this . _runtimeModules = Object . create ( null )
25
25
this . _subscribers = [ ]
26
+ this . _watcherVM = new Vue ( )
26
27
27
28
// bind commit and dispatch to self
28
29
const store = this
@@ -109,7 +110,7 @@ class Store {
109
110
110
111
watch ( getter , cb , options ) {
111
112
assert ( typeof getter === 'function' , `store.watch only accepts a function.` )
112
- return this . _vm . $watch ( ( ) => getter ( this . state ) , cb , options )
113
+ return this . _watcherVM . $watch ( ( ) => getter ( this . state ) , cb , options )
113
114
}
114
115
115
116
replaceState ( state ) {
Original file line number Diff line number Diff line change @@ -928,4 +928,31 @@ describe('Vuex', () => {
928
928
done ( )
929
929
} )
930
930
} )
931
+
932
+ it ( 'watch: with resetting vm' , done => {
933
+ const store = new Vuex . Store ( {
934
+ state : {
935
+ count : 0
936
+ } ,
937
+ mutations : {
938
+ [ TEST ] : state => state . count ++
939
+ }
940
+ } )
941
+
942
+ const spy = jasmine . createSpy ( )
943
+ store . watch ( state => state . count , spy )
944
+
945
+ // reset store vm
946
+ store . registerModule ( 'test' , { } )
947
+
948
+ Vue . nextTick ( ( ) => {
949
+ store . commit ( TEST )
950
+ expect ( store . state . count ) . toBe ( 1 )
951
+
952
+ Vue . nextTick ( ( ) => {
953
+ expect ( spy ) . toHaveBeenCalled ( )
954
+ done ( )
955
+ } )
956
+ } )
957
+ } )
931
958
} )
You can’t perform that action at this time.
0 commit comments