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

feat(store): bind mutation and action handlers to store #872

Merged
merged 1 commit into from
Jul 19, 2017

Conversation

pi0
Copy link
Contributor

@pi0 pi0 commented Jul 19, 2017

  • Feature
  • Not affecting current API

As of vue's runInNewContext enhancement for SSR, everything should be stateless in server side to prevent each request affecting others so when implementing Actions which need access to ssrContext (Like axios with configured proper auth headers - nuxt-community/legacy-modules#26) the only way is passing those references from caller as action/mutation parameters (example), this is working but makes usage ugly and really harder. This enhancement is required for workaround and fixes by simply binding handlers to store instance. So we can inject state into store and access it using this inside action/mutation functions. (this is currently undefined inside handlers)

@yyx990803 yyx990803 merged commit 67da622 into vuejs:dev Jul 19, 2017
This was referenced Aug 3, 2017
@LinusBorg
Copy link
Member

@pi0 It's currently quite common to write actions as fat arrow functions. those would have to be converted to normal functions, right?

@pi0
Copy link
Contributor Author

pi0 commented Aug 20, 2017

@LinusBorg Yep, actually using bind to context instead of using 3rd argument or something like that was intentional as arrow functions are commonly considered pure functions without any side effects like access and modify store instance. Another point with this context binding is having a familiar API just like vm instances which we can access things using this.*.

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.

3 participants