Repository: ktsn/vuex-smart-module (ts)

Issue:
Can't access subModules actions or mutations of a SubModule from context(store).modules
Hey, thanks for your last release allowing subModules access with symbols!

But there is a bug, we can't access actions or mutations of submodules with the `context(store).modules.nameOfModule` feature.
The only way to access it, is, with the `option.modules!.nameOfModule.context(store)` way.

![subModulesInMountedHook](https://user-images.githubusercontent.com/37144206/85847825-6aa7ec00-b7a8-11ea-894b-8bd173f006ad.png)

Here are the log of this mounted hook: 
![logOfSubModulesActions](https://user-images.githubusercontent.com/37144206/85847833-6c71af80-b7a8-11ea-9325-8b1ceccb7810.png)

As we can see the first way doesn't show anything when we try to show the actions of a submodules,  it's the same for `actions` and `mutations`. (getters and state are shown)

BTW: On the readme, there is only the first way specified.


Pull request description:
fix: allow to use `actions` and `mutations` of nested contexts
fix #242 

Patch:
diff --git a/src/context.ts b/src/context.ts
index 228a7bd..4c7cc0d 100644
--- a/src/context.ts
+++ b/src/context.ts
@@ -250,7 +250,8 @@ export class Context<Mod extends Module<any, any, any, any, any>> {
 
   get modules(): ModulesContexts<Mod> {
     const modules = {} as ModulesContexts<Mod>
-    const children = this.moduleOptions.modules
+    const children: Record<string, Module<any, any, any, any, any>> = this
+      .moduleOptions.modules
     if (!children) {
       return modules
     }
@@ -262,7 +263,7 @@ export class Context<Mod extends Module<any, any, any, any, any>> {
           return new Context(
             createLazyContextPosition(child),
             this.store,
-            child
+            child.options
           )
         },
       })


Test patch:
diff --git a/test/nested.spec.ts b/test/nested.spec.ts
index 359f78e..b7dbc00 100644
--- a/test/nested.spec.ts
+++ b/test/nested.spec.ts
@@ -60,4 +60,27 @@ describe('Nested modules', () => {
     expect(fooCtx.state.value).toBe(4)
     expect(fooCtx.getters.double).toBe(8)
   })
+
+  it("allows to access to nested module's actions and mutations", () => {
+    const root = new Module({
+      modules: {
+        foo,
+      },
+    })
+
+    const store = createStore(root)
+    const ctx = root.context(store)
+    const fooCtx = ctx.modules.foo
+
+    expect(fooCtx.state.value).toBe(1)
+    expect(fooCtx.getters.double).toBe(2)
+
+    fooCtx.mutations.inc(1)
+    expect(fooCtx.state.value).toBe(2)
+    expect(fooCtx.getters.double).toBe(4)
+
+    fooCtx.actions.inc(2)
+    expect(fooCtx.state.value).toBe(4)
+    expect(fooCtx.getters.double).toBe(8)
+  })
 })