Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get context of nested cloned module #516

Open
Dodje opened this issue Oct 19, 2021 · 0 comments
Open

Can't get context of nested cloned module #516

Dodje opened this issue Oct 19, 2021 · 0 comments

Comments

@Dodje
Copy link

Dodje commented Oct 19, 2021

Hi, I have a reusable module, which I wish to use as submodule in other different modules.

class ReusableState {
    data = {};
}

const reusableNested = new Module({
    namespaced: false,
    state: ReusableState,
});

// ...
class MainModuleActions extends Actions<
    MainModuleState,
    MainModuleGetters,
    MainModuleMutations,
    MainModuleActions
> {
    private nested!: Context<typeof reusableNested>;

    $init(store: Store<any>): void {
        this.nested = reusableNested.context(store);
    }

    getNestedState(): void {
        console.log(this.nested.state);
    }
}

const mainModule = new Module({
    namespaced: true,
    state: MainModuleState,
    getters: MainModuleGetters,
    mutations: MainModuleMutations,
    actions: MainModuleActions,
    modules: {
        nested: reusableNested.clone(),
    },
});

When I call getNestedState I have a message:

Error: [vuex-smart-module] The module need to be registered a store before using `Module#context` or `createMapper`
    at assert (vuex-smart-module.esm.js?675f:165)
    at Object.get path [as path] (vuex-smart-module.esm.js?675f:201)
    at Context.get (vuex-smart-module.esm.js?675f:300)

And that happens only if nested module is cloned, otherwise all works fine

Version 0.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant