Skip to content

Commit 81195bb

Browse files
blake-newmanyyx990803
authored andcommitted
support vuex 2.0 migration (#18)
1 parent e28dd02 commit 81195bb

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ exports.sync = function (store, router) {
22
patchStore(store)
33
store.router = router
44

5+
var commit = store.commit || store.dispatch
56
var isTimeTraveling = false
67
var currentPath
78

@@ -29,20 +30,28 @@ exports.sync = function (store, router) {
2930
}
3031
var to = transition.to
3132
currentPath = to.path
32-
store.dispatch('router/ROUTE_CHANGED', to)
33+
commit('router/ROUTE_CHANGED', to)
3334
})
3435
}
3536

37+
function applyMutationState(store, state) {
38+
// support above 2.0
39+
if (store.hasOwnProperty('_committing')) {
40+
return store._committing = state
41+
}
42+
return store._dispatching = state
43+
}
44+
3645
function patchStore (store) {
3746
// add state
3847
var set = store._vm.constructor.set
39-
store._dispatching = true
48+
applyMutationState(store, true);
4049
set(store.state, 'route', {
4150
path: '',
4251
query: null,
4352
params: null
4453
})
45-
store._dispatching = false
54+
applyMutationState(store, false);
4655
// add mutations
4756
store.hotUpdate({
4857
modules: {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vuex-router-sync",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "Effortlessly keep vue-router and vuex store in sync.",
55
"main": "index.js",
66
"repository": {
@@ -19,7 +19,7 @@
1919
},
2020
"homepage": "https://github.com/vuejs/vuex-router-sync#readme",
2121
"peerDependencies": {
22-
"vuex": ">=0.6.2",
22+
"vuex": ">= 0.6.2 < 3",
2323
"vue-router": ">=0.7.11"
2424
}
2525
}

0 commit comments

Comments
 (0)