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

Add { root: true } option support to dispatch. #6

Merged
merged 1 commit into from Feb 24, 2017
Merged

Add { root: true } option support to dispatch. #6

merged 1 commit into from Feb 24, 2017

Conversation

ghost
Copy link

@ghost ghost commented Feb 22, 2017

I've encountered a couple of cases where dispatching in the global namespace might become in handy.

This PR provide a way to dispatch on the global namespace by providing a { root: true } option as the third argument to dispatch.

@ktsn
Copy link
Owner

ktsn commented Feb 23, 2017

Thank you for your PR!
Honestly, I'm not sure if we would like to dispatch actions out of local modules. Can you explain a bit more about your use case? Why do you think that it is not suffice to just use VM's methods for that case?

@ghost
Copy link
Author

ghost commented Feb 23, 2017

Anytime!
I'm using local() for managing per-instance form states and the remote model (a user profile, for example) is only modified once the whole saving operation is successful.

Using a dispatch like dispatch('user/updateAttributes', attributes, { root: true }) enables me to trigger the final update from within the local store.

As a matter of fact, I'm using an afterSave callback as a solution already.

I was just wondering if the actual implementation can take advantage of the same escape-from-isolation root: option we have in vuex modules.

Copy link
Owner

@ktsn ktsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better if we also have root level commit? 🙂

src/register.ts Outdated
if (typeof type === 'object') {
type = type.type
payload = type
}
return dispatch(localKey(type, moduleName), payload)

if (!options || !options.root) {
Copy link
Owner

@ktsn ktsn Feb 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also unify the options like commit method does? In current implementation, the options object always be 3rd argument even if the users call object style dispatch.

test/register.ts Outdated
actions: {
foo ({ dispatch, rootGetters }: any) {
dispatch('rootAction', 'bar', { root: true }).then(() => {
assert(rootGetters.propertyGetter() === 'bar')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this test is finished before executing this line. We need to use mocha's done callback here.

- Update localDispatch to support options.
- Implement root option on both commit and dispatch.
- Update README.md file (sentence specifying the root option).
@ghost
Copy link
Author

ghost commented Feb 23, 2017

Absolutely!
@ktsn I've made the changes, not so sure about the ternary operator though.

@ktsn
Copy link
Owner

ktsn commented Feb 24, 2017

Looks nice, thank you!

@ktsn ktsn merged commit e2bf8ef into ktsn:master Feb 24, 2017
@ghost ghost deleted the root_option_support branch February 24, 2017 12:27
@ghost
Copy link
Author

ghost commented Feb 24, 2017

You're welcome! Thank you for your time.

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

Successfully merging this pull request may close these issues.

2 participants