Skip to content

ModuleTree<S, R> #1689

@rodolphocastro

Description

@rodolphocastro

What problem does this feature solve?

This interface might help when dealing with nested modules on stores using Typescript.

Currently the Module<S, R> interface exposes a single `ModuleTree´ which allows us to create one level of nested modules.

Exposing a ModuleTree<R> or a ModuleTree<S, R> would be inline with the current GetterTree<S, R> and other Trees and allow us to deeper nest our Modules.

I ran into this issue when attempting to create a nested module within a nested module using Typescript. The "parent" modules holds state for some supported features on the application and its children require to check those features in order to validate their actions. The root state (or parent of the parent, in this case) simply holds environment and version information.

What does the proposed API look like?

I belive that a new interface ModuleTree<S,R> might solve the issue:

export interface ModuleTree<S, R> {
  [key: string]: Module<S, R>;
}

Which could be added to the Current Module<S, R> interface as an or:

export interface Module<S, R> {
  namespaced?: boolean;
  state?: S | (() => S);
  getters?: GetterTree<S, R>;
  actions?: ActionTree<S, R>;
  mutations?: MutationTree<S>;
  modules?: ModuleTree<R> | ModuleTree<S, R>;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    typesRelated to typings only

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions