sascha245 / vuex-simple

A simpler way to write your Vuex store in Typescript
MIT License
180 stars 15 forks source link

Is there a way to split the module into files? #9

Closed jmotes closed 5 years ago

jmotes commented 5 years ago

Thanks!

sascha245 commented 5 years ago

Hi @jmotes ,

As I don't know exactly what you have in the module I will just propose different solutions you could use for now:

  1. Do all the heavy lifting (API calls and such ) in different files or services
  2. Split up your module into smaller modules ( if it's possible )
  3. I could eventually introduce inheritance handling on the fly in 1.2.0, as it shouldn't be too difficult to add. That way you could split up your code in the following way:
    
    class CounterState {
    @State()
    public counter: number = 10;
    }

class CounterGetters extends CounterState { @Getter() public get counterPlusHundred() { return this.counter + 100; } }

class CounterMutations extends CounterGetters { @Mutation() public increment() { this.counter++; } }

class CounterActions extends CounterMutations { public async incrementAsync() { await new Promise(r => setTimeout(r, 500)); this.increment(); } }

@Module('counter') class CounterModule extends CounterActions {}



What do you think about the last solution? Though it isn't perfect and probably also isn't the best way to handle this problem, it should enable us to split the module into separate parts.

Don't hesitate to tell me if you have other better ideas!
sascha245 commented 5 years ago

Hi @jmotes,

1.2.0 is now out with #10 and includes as said inheritance in the same way as presented above. Hope it solves your problems.

Sascha

jmotes commented 5 years ago

Thanks @sascha245!