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 {
2323 this . _wrappedGetters = Object . create ( null )
2424 this . _runtimeModules = Object . create ( null )
2525 this . _subscribers = [ ]
26+ this . _watcherVM = new Vue ( )
2627
2728 // bind commit and dispatch to self
2829 const store = this
@@ -109,7 +110,7 @@ class Store {
109110
110111 watch ( getter , cb , options ) {
111112 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 )
113114 }
114115
115116 replaceState ( state ) {
Original file line number Diff line number Diff line change @@ -928,4 +928,31 @@ describe('Vuex', () => {
928928 done ( )
929929 } )
930930 } )
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+ } )
931958} )
You can’t perform that action at this time.
0 commit comments