@@ -27,6 +27,14 @@ class Something extends VuexModule {
2727 something = 'nothing'
2828}
2929
30+ @Module ( { namespacedPath : 'books/' } )
31+ class Books extends VuexModule {
32+ books : string [ ] = [ ]
33+
34+ @mutation addBook ( book : string ) {
35+ this . books . push ( book )
36+ }
37+ }
3038
3139@Module ( { namespacedPath : 'user/' } )
3240class UserStore extends VuexModule {
@@ -60,6 +68,11 @@ class UserStore extends VuexModule {
6068 return this . $store . state . globalValue
6169 }
6270
71+ @action async addBook ( book : string ) {
72+ const booksProxy = Books . CreateProxy ( this . $store , Books )
73+ booksProxy . addBook ( book )
74+ }
75+
6376 // Explicitly define a vuex getter using class getters.
6477 get fullName ( ) {
6578 return this . firstname + ' ' + this . lastname
@@ -169,11 +182,29 @@ describe('CreateProxy', () => {
169182 expect ( user . lastname ) . toEqual ( 'Olofinjana' )
170183 } )
171184
185+ it ( 'should create proxy inside module' , async ( ) => {
186+ UserStore . ClearProxyCache ( UserStore )
187+ localVue = createLocalVue ( )
188+ localVue . use ( Vuex )
189+ store = new Store ( {
190+ modules : {
191+ user : UserStore . ExtractVuexModule ( UserStore ) ,
192+ books : Books . ExtractVuexModule ( Books )
193+ }
194+ } )
195+
196+ const user = UserStore . CreateProxy ( store , UserStore )
197+ const books = Books . CreateProxy ( store , Books )
198+
199+ expect ( books . books ) . toEqual ( [ ] )
200+ await user . addBook ( 'My new book' )
201+ expect ( books . books ) . toContain ( 'My new book' )
202+ } )
203+
172204 it ( 'should provide store instance on $store field' , async ( ) => {
173205 UserStore . ClearProxyCache ( UserStore )
174206 localVue = createLocalVue ( )
175207 localVue . use ( Vuex )
176- const mock = jest . fn ( )
177208 store = new Store ( {
178209 modules : {
179210 user : UserStore . ExtractVuexModule ( UserStore )
0 commit comments