Skip to content

Commit 5eb4378

Browse files
committed
feat(vue2): inspect getters in mutation tl layer
1 parent f402008 commit 5eb4378

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

packages/app-backend-vue2/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const backend: DevtoolsBackend = {
7676
const { Vue } = appRecord.options.meta
7777
const app = appRecord.options.app
7878
wrapVueForEvents(app, Vue, api.ctx)
79-
setupPlugin(api, app)
79+
setupPlugin(api, app, Vue)
8080
}
8181
}
8282

packages/app-backend-vue2/src/plugin.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import copy from 'clone-deep'
55

66
let actionId = 0
77

8-
export function setupPlugin (api: DevtoolsApi, app: App) {
8+
export function setupPlugin (api: DevtoolsApi, app: App, Vue) {
99
const ROUTER_INSPECTOR_ID = 'vue2-router-inspector'
1010
const ROUTER_CHANGES_LAYER_ID = 'vue2-router-changes'
1111

@@ -198,6 +198,29 @@ export function setupPlugin (api: DevtoolsApi, app: App) {
198198
})
199199
}
200200
}, { prepend: true })
201+
202+
// Inspect getters on mutations
203+
api.on.inspectTimelineEvent(payload => {
204+
if (payload.layerId === VUEX_MUTATIONS_ID) {
205+
const getterKeys = Object.keys(store.getters)
206+
if (getterKeys.length) {
207+
const vm = new Vue({
208+
data: {
209+
$$state: payload.data.state
210+
},
211+
computed: store._vm.$options.computed
212+
})
213+
const originalVm = store._vm
214+
store._vm = vm
215+
216+
const tree = transformPathsToObjectTree(store.getters)
217+
payload.data.getters = copy(tree)
218+
219+
store._vm = originalVm
220+
vm.$destroy()
221+
}
222+
}
223+
})
201224
}
202225
})
203226
}

0 commit comments

Comments
 (0)