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

Proposal: root actions for namespaced module #770

Closed
ChenMachluf opened this issue May 9, 2017 · 2 comments
Closed

Proposal: root actions for namespaced module #770

ChenMachluf opened this issue May 9, 2017 · 2 comments

Comments

@ChenMachluf
Copy link

What problem does this feature solve?

I have app that contain dynamic views (kinda of mini app). Each view have its own module.
Also , in my app have a global filters of the data each view need to show.

Now , every time I change the global filters ,i need to make sure my dynamic view is refresh its own data.
Until now every module implement its own "refresh" action.

Since every dynamic view is like mini-app here , we decide to make them namespaced.
Now when "refresh" is dispatched my module didn't get the "global refresh event".

Simply what I want is to enable the namespaced module to register the some actions under the root namespace. Its enable namespaced modules to participate in root events while changing the namespaced module.
The root actions get the same context of the regular ones.

It's easy to implement in vuex , the question if this is necessary

P.S

maybe do the same for mutations

What does the proposed API look like?

Root propertry :

const store = new Vuex.Store({
  modules: {
    files: {
      namespaced: true,

      // module assets
      state: { ... }, // module state is already nested and not affected by namespace option
      getters: {
        bigFiles () { ... } // -> getters['files/bigFiles']
      },
      actions: {
        delete (namespacedContext) { ... }, // -> dispatch('files/delete')
        refresh: {
            root: true,
            handler (sameNamespacedContext) { ... } // -> dispatch('refresh')
        }
      },
      mutations: {
        delete () { ... } // -> commit('files/delete')
      }

    }
  }
})

or new "rootActions" :

const store = new Vuex.Store({
  modules: {
    files: {
      namespaced: true,

      // module assets
      state: { ... }, // module state is already nested and not affected by namespace option
      actions: {
        delete (namespaceContext) { ... } // -> dispatch('files/delete')
      },
      rootActions: {
        refresh (sameNamespaceContext) { ... } // -> dispatch('refresh')
      },
      mutations: {
        delete () { ... } // -> commit('files/delete')
      }

    }
  }
})
@posva posva added the proposal label May 9, 2017
@gustavopch
Copy link

This proposal would be useful for cases where we want every module to have a chance of doing something when an action is dispatched.

For example, many modules may need to handle differently a userUpdated action, but calling each and every namespaced action is unnecessarily more complex than just dispatching a global userUpdated and letting the interested modules catch it.

@fxmaxvl
Copy link

fxmaxvl commented Mar 15, 2018

Api reference still don't contain info about this feature.

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

4 participants