question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to create dynamic modules extended from some parent module? I tried it that way:

My parent-module.ts:

import {Action, getModule, Module, Mutation, VuexModule} from 'vuex-module-decorators';

export class ParentStore extends VuexModule {
    public get getterForInherit(): any {
        return someData
    }
}

Child modules: child-one.ts:

import {Action, getModule, Module, Mutation, VuexModule} from 'vuex-module-decorators'
import {ParentModule} from './parent-module';

@Module({dynamic: true, store: Store, name: 'childOne', namespaced: true})
class FirstChildModule extends ParentModule {
    public get SecondChildGetter(): number {
        return 1;
    }
}

export const FirstChildStore: ParentModule = getModule(FirstChildModule)

child-two.ts:

import {Action, getModule, Module, Mutation, VuexModule} from 'vuex-module-decorators'
import {ParentModule} from './parent-module';

@Module({dynamic: true, store: Store, name: 'childTwo', namespaced: true})
class SecondChildModule extends ParentModule {
    public get FirstChildGetter(): number {
        return 2;
    }
}

export const SecondChildStore: ParentModule = getModule(SecondChildModule)

But when I import those modules to components getterForInherit is not available. Is it possible to do it this way?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:12

github_iconTop GitHub Comments

3reactions
FullPintcommented, Aug 20, 2020

@fen89 we use this: https://github.com/gertqin/vuex-class-modules

But it looks like they may have merged a fix with this package. Haven’t tested it yet.

3reactions
Exeterescommented, Dec 8, 2019

@dan-an @rendrom This workaround may interest you.

import { getModule, VuexModule, Module } from "vuex-module-decorators";

class CollectionBase<T> extends VuexModule {
    items: T[] = [];
    get last() {
        return this.items[this.items.length - 1];
    }
}

@Module({ name: "numbers", namespaced: true })
class NumberCollection extends CollectionBase<number> {
    items = [0, 5, 2];
}

// Get wrapped parent module to access getters
const base: any = Module({})(CollectionBase);
// Copy parent getters to child
Object.assign(NumberCollection.getters, base.getters);
// Manually register module
store.registerModule("numbers", NumberCollection);

const numbers = getModule(NumberCollection, store);
console.log(numbers.last); // 2
Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating reusable getters in vuex-module-decorators
You can use vuex if you already have it installed. You can do something like this: import { mapGetters, mapActions, mapMutations } from...
Read more >
Dynamic reusable Vuex store - Medium
Use the Getter isVisible for retrieving the state value. Mutations/Actions for actual mutating of the state — showing and hiding the Modal ...
Read more >
Modules | Vuex
Each module can contain its own state, mutations, actions, getters, and even nested modules - it's fractal all the way down:.
Read more >
how i can create reusable javascript getters and setters?
how i can create reusable javascript getters and setters? my friend send this test to me and after i make some search ,...
Read more >
Team Go Getters - P90X | Go getter, Reusable tote bags, Laundry bag
Jun 18, 2013 - This Pin was discovered by Big Frog Round Rock. Discover (and save!) your own Pins on Pinterest.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found