Skip to content

Commit 1107e7b

Browse files
committed
add vuex migration guide
1 parent 597a547 commit 1107e7b

File tree

4 files changed

+102
-6
lines changed

4 files changed

+102
-6
lines changed

src/guide/comparison.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Comparison with Other Frameworks
33
type: guide
4-
order: 27
4+
order: 28
55
---
66

77
This is definitely the most difficult page in the guide to write, but we do feel it's important. Odds are, you've had problems you tried to solve and you've used another library to solve them. You're here because you want to know if Vue can solve your specific problems better. That's what we hope to answer for you.

src/guide/join.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Join the Vue.js Community!
33
type: guide
4-
order: 28
4+
order: 29
55
---
66

77
Vue's community is growing incredibly fast and if you're reading this, there's a good chance you're ready to join it. So... welcome!

src/guide/migration-vuex.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
title: Migration from Vuex 0.6.x to 1.0
3+
type: guide
4+
order: 27
5+
---
6+
7+
> Vuex 2.0 is released, but this guide only covers the migration to 1.0? Is that a typo? Also, it looks like Vuex 1.0 and 2.0 were released simultaneously. What's going on? Which one should I use and what's compatible with Vue 2.0?
8+
9+
Both Vuex 1.0 and 2.0:
10+
11+
- fully support both Vue 1.0 and 2.0
12+
- will be maintained for the forseeable future
13+
14+
They have slightly different target users however.
15+
16+
__Vuex 2.0__ is a radical redesign and simplification of the API, for those who are starting new projects or want to be on the cutting edge of client-side state management. __It is not covered by this migration guide__, so you should check out [the Vuex 2.0 docs](https://vuex.vuejs.org/en/index.html) if you'd like to learn more about it.
17+
18+
__Vuex 1.0__ is mostly backwards-compatible, so requires very few changes to upgrade. It is recommended for those with large existing codebases or who just want the smoothest possible upgrade path to Vue 2.0. This guide is dedicated to facilitating that process, but only includes migration notes. For the complete usage guide, see [the Vuex 1.0 docs](https://github.com/vuejs/vuex/tree/1.0/docs/en).
19+
20+
<p class="tip">The list of deprecations below should be relatively complete, but the migration helper is still being updated to catch them.</p>
21+
22+
## `store.watch` with String Property Path <sup>deprecated</sup>
23+
24+
`store.watch` now only accept functions. So for example, you would have to replace:
25+
26+
``` js
27+
store.watch('user.notifications', callback)
28+
```
29+
30+
with:
31+
32+
``` js
33+
store.watch(
34+
// When the returned result changes...
35+
function (state) {
36+
return state.user.notifications
37+
},
38+
// Run this callback
39+
callback
40+
)
41+
```
42+
43+
This gives you more complete control over the reactive properties you'd like to watch.
44+
45+
{% raw %}
46+
<div class="upgrade-path">
47+
<h4>Upgrade Path</h4>
48+
<p>Run the <a href="https://github.com/vuejs/vue-migration-helper">migration helper</a> on your codebase to find examples of <code>store.watch</code> with a string as the first argument.</p>
49+
</div>
50+
{% endraw %}
51+
52+
## Store's Event Emitter <sup>deprecated</sup>
53+
54+
The store instance no longer exposes the event emitter interface (`on`, `off`, `emit`). If you were previously using the store as a global event bus, [see this section](http://vuejs.org/guide/migration.html#dispatch-and-broadcast-deprecated) for migration instructions.
55+
56+
Instead of using this interface to watch events emitted by the store itself (e.g. `store.on('mutation', callback)`), a new method `store.subscribe` is introduced. Typical usage inside a plugin would be:
57+
58+
``` js
59+
var myPlugin = store => {
60+
store.subscribe(function (mutation, state) {
61+
// Do something...
62+
})
63+
}
64+
65+
```
66+
67+
See example [the plugins docs](https://github.com/vuejs/vuex/blob/1.0/docs/en/plugins.md) for more info.
68+
69+
{% raw %}
70+
<div class="upgrade-path">
71+
<h4>Upgrade Path</h4>
72+
<p>Run the <a href="https://github.com/vuejs/vue-migration-helper">migration helper</a> on your codebase to find examples of <code>store.on</code>, <code>store.off</code>, and <code>store.emit</code>.</p>
73+
</div>
74+
{% endraw %}
75+
76+
## Middlewares <sup>deprecated</sup>
77+
78+
Middlewares are replaced by plugins. A plugin is simply a function that receives the store as the only argument, and can listen to the mutation event on the store:
79+
80+
``` js
81+
const myPlugins = store => {
82+
store.subscribe('mutation', (mutation, state) => {
83+
// Do something...
84+
})
85+
}
86+
```
87+
88+
For more details, see [the plugins docs](https://github.com/vuejs/vuex/blob/1.0/docs/en/plugins.md).
89+
90+
{% raw %}
91+
<div class="upgrade-path">
92+
<h4>Upgrade Path</h4>
93+
<p>Run the <a href="https://github.com/vuejs/vue-migration-helper">migration helper</a> on your codebase to find examples of the <code>middlewares</code> option on a store.</p>
94+
</div>
95+
{% endraw %}

themes/vue/source/css/_migration.styl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
.migration-guide, .migration-vue-router-guide
2-
h3 > sup
3-
margin-left: .3em
4-
color: #b9465c
1+
.content.guide[class*="migration"]
2+
h2, h3
3+
> sup
4+
margin-left: .3em
5+
color: #b9465c
56
.upgrade-path
67
padding: 2em
78
background: rgba(73, 195, 140, .1)

0 commit comments

Comments
 (0)