Skip to content

Commit 2da0924

Browse files
bajzarpasp1ker
authored andcommitted
fix(vuex): Refactor legacy VueX checking, closes vuejs#939 (vuejs#970)
* Change isLegacy checking strategy, adapt mutation handling to vuex 1 * ./src/backend remove setting and related data * Check the legacy mode before converting the payload
1 parent 4a67310 commit 2da0924

File tree

4 files changed

+17
-26
lines changed

4 files changed

+17
-26
lines changed

src/backend/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ function connect (Vue) {
128128

129129
// vuex
130130
if (hook.store) {
131-
initVuexBackend(hook, bridge, isLegacy)
131+
initVuexBackend(hook, bridge, hook.store.commit === undefined)
132132
} else {
133133
hook.once('vuex:init', store => {
134-
initVuexBackend(hook, bridge, isLegacy)
134+
initVuexBackend(hook, bridge, store.commit === undefined)
135135
})
136136
}
137137

src/backend/vuex.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,13 +442,21 @@ class VuexBackend {
442442
} else if (mutation.handlers) {
443443
this.store._committing = true
444444
try {
445-
const payload = mutation.payload
445+
let payload = mutation.payload
446+
447+
if (this.isLegacy && !Array.isArray(payload)) {
448+
payload = [payload]
449+
}
450+
446451
if (Array.isArray(mutation.handlers)) {
447-
mutation.handlers.forEach(handler => handler(payload))
452+
if (this.isLegacy) {
453+
mutation.handlers.forEach(handler => handler(this.store.state, ...payload))
454+
} else {
455+
mutation.handlers.forEach(handler => handler(payload))
456+
}
448457
} else {
449-
if (this.isLegacy || SharedData.vuex1) {
450-
// Vuex 1
451-
mutation.handlers(this.store.state, payload)
458+
if (this.isLegacy) {
459+
mutation.handlers(this.store.state, ...payload)
452460
} else {
453461
mutation.handlers(payload)
454462
}

src/devtools/views/settings/GlobalPreferences.vue

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,5 @@
9191
May impact performance or cause crashes
9292
</template>
9393
</VueFormField>
94-
95-
<VueFormField
96-
title="Vuex Legacy"
97-
>
98-
<VueSwitch v-model="$shared.vuex1">
99-
Enable compatibility mode
100-
</VueSwitch>
101-
<template #subtitle>
102-
<VueIcon
103-
icon="warning"
104-
class="medium"
105-
/>
106-
If you use Vuex 1.x, enable this option
107-
</template>
108-
</VueFormField>
10994
</div>
11095
</template>

src/shared-data.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ const internalSharedData = {
1313
recordPerf: false,
1414
editableProps: false,
1515
logDetected: true,
16-
vuexAutoload: false,
17-
vuex1: false
16+
vuexAutoload: false
1817
}
1918

2019
const persisted = [
@@ -24,8 +23,7 @@ const persisted = [
2423
'recordVuex',
2524
'editableProps',
2625
'logDetected',
27-
'vuexAutoload',
28-
'vuex1'
26+
'vuexAutoload'
2927
]
3028

3129
// ---- INTERNALS ---- //

0 commit comments

Comments
 (0)