Skip to content

Commit 28efcaf

Browse files
author
Guillaume Chau
committed
perf(vuex): batch mutation insert
1 parent 07e8676 commit 28efcaf

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

packages/app-frontend/src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ function initApp (shell) {
151151
})
152152

153153
bridge.on('vuex:mutation', payload => {
154-
store.commit('vuex/RECEIVE_MUTATION', payload)
154+
store.dispatch('vuex/receiveMutation', payload)
155155
})
156156

157157
bridge.on('vuex:inspected-state', ({ index, snapshot }) => {
@@ -161,6 +161,8 @@ function initApp (shell) {
161161
store.commit('vuex/UPDATE_BASE_STATE', snapshot)
162162
} else if (store.getters['vuex/absoluteInspectedIndex'] === index) {
163163
store.commit('vuex/UPDATE_INSPECTED_STATE', snapshot)
164+
} else {
165+
console.log('vuex:inspected-state wrong index', index, 'expected:', store.getters['vuex/absoluteInspectedIndex'])
164166
}
165167

166168
if (VuexResolve.travel) {

packages/app-frontend/src/views/vuex/actions.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
import { snapshotsCache } from './cache'
22
import Resolve from './resolve'
33
import SharedData from '@utils/shared-data'
4+
import debounce from 'lodash/debounce'
5+
6+
const mutationBuffer = []
7+
8+
export function receiveMutation ({ commit }, entry) {
9+
mutationBuffer.push(entry)
10+
receiveMutations(commit)
11+
}
12+
13+
export const receiveMutations = debounce(commit => {
14+
commit('RECEIVE_MUTATIONS', mutationBuffer)
15+
mutationBuffer.length = 0
16+
}, 300, {
17+
maxWait: 1000
18+
})
419

520
export function commitAll ({ commit, state }) {
621
if (state.history.length > 0) {

packages/app-frontend/src/views/vuex/module.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ const mutations = {
3131
reset(state)
3232
},
3333

34-
'RECEIVE_MUTATION' (state, entry) {
34+
'RECEIVE_MUTATIONS' (state, entries) {
3535
const inspectingLastMutation = state.inspectedIndex === state.history.length - 1
36-
entry.id = uid++
37-
state.history.push(entry)
36+
for (const entry of entries) {
37+
entry.id = uid++
38+
}
39+
state.history.push(...entries)
3840
if (!state.filter) {
3941
state.activeIndex = state.history.length - 1
4042
if (inspectingLastMutation) {
@@ -131,7 +133,7 @@ const getters = {
131133
return filteredHistory[inspectedIndex]
132134
},
133135

134-
inspectedState ({ base, inspectedIndex, inspectedState, inspectedModule }, { inspectedEntry }) {
136+
inspectedState ({ base, inspectedState, inspectedModule }, { inspectedEntry }) {
135137
const data = inspectedEntry ? inspectedState : base
136138
return processInspectedState({ entry: inspectedEntry, data, inspectedModule })
137139
},

0 commit comments

Comments
 (0)