Skip to content

List getters in Vuex tab #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions shells/dev/target/Counter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<p>{{ count }}</p>
<button class="increment" @click="increment">+1</button>
<button class="decrement" @click="decrement">-1</button>

<p>Your counter is {{ $store.getters.isPositive ? 'positive' : 'negative' }}</p>
</div>
</template>

Expand Down
3 changes: 3 additions & 0 deletions shells/dev/target/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ export default new Vuex.Store({
mutations: {
INCREMENT: state => state.count++,
DECREMENT: state => state.count--
},
getters: {
isPositive: state => state.count >= 0
}
})
16 changes: 14 additions & 2 deletions src/backend/vuex.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { stringify, parse } from '../util'
export function initVuexBackend (hook, bridge) {
const store = hook.store
let recording = true
bridge.send('vuex:init', stringify(store.state))
bridge.send('vuex:init', {
state: stringify(store.state),
getters: stringify(store.getters)
})

// deal with multiple backend injections
hook.off('vuex:mutation')
Expand All @@ -17,7 +20,8 @@ export function initVuexBackend (hook, bridge) {
payload: stringify(mutation.payload)
},
timestamp: Date.now(),
state: stringify(state)
state: stringify(state),
getters: stringify(store.getters)
})
})

Expand All @@ -26,6 +30,14 @@ export function initVuexBackend (hook, bridge) {
hook.emit('vuex:travel-to-state', parse(state, true /* revive */))
})

bridge.on('vuex:import-state', state => {
hook.emit('vuex:travel-to-state', parse(state, true /* revive */))
bridge.send('vuex:init', {
state,
getters: stringify(store.getters)
})
})

bridge.on('vuex:toggle-recording', enabled => {
recording = enabled
})
Expand Down
4 changes: 2 additions & 2 deletions src/devtools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ function initApp (shell) {
store.commit('components/RECEIVE_INSTANCE_DETAILS', parse(details))
})

bridge.on('vuex:init', state => {
store.commit('vuex/INIT', state)
bridge.on('vuex:init', payload => {
store.commit('vuex/INIT', payload)
})

bridge.on('vuex:mutation', payload => {
Expand Down
2 changes: 1 addition & 1 deletion src/devtools/views/vuex/VuexStateInspector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default {
} else {
try {
parse(importedStr) // Try to parse
this.$store.dispatch('vuex/importState', importedStr)
bridge.send('vuex:import-state', importedStr)
this.showBadJSONMessage = false
} catch (e) {
this.showBadJSONMessage = true
Expand Down
8 changes: 2 additions & 6 deletions src/devtools/views/vuex/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,14 @@ export function toggleRecording ({ state, commit }) {
bridge.send('vuex:toggle-recording', state.enabled)
}

export function importState ({ commit, dispatch }, importedState) {
commit('INIT', importedState)
dispatch('reset')
}

export function updateFilter ({ commit }, filter) {
commit('UPDATE_FILTER', filter)
}

function travelTo (state, commit, index) {
const { history, base } = state
const targetState = index > -1 ? history[index].state : base
const targetState = index > -1 ? history[index].state : base.state

bridge.send('vuex:travel-to-state', targetState)
commit('TIME_TRAVEL', index)
}
18 changes: 13 additions & 5 deletions src/devtools/views/vuex/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const state = {
}

const mutations = {
'INIT' (state, initialState) {
state.initial = state.base = initialState
'INIT' (state, initial) {
state.initial = state.base = {state: initial.state, getters: initial.getters}
state.hasVuex = true
reset(state)
},
Expand All @@ -35,15 +35,21 @@ const mutations = {
}
},
'COMMIT_ALL' (state) {
state.base = state.history[state.history.length - 1].state
state.base = {
state: state.history[state.history.length - 1].state,
getters: state.history[state.history.length - 1].getters
}
state.lastCommit = Date.now()
reset(state)
},
'REVERT_ALL' (state) {
reset(state)
},
'COMMIT' (state, index) {
state.base = state.history[index].state
state.base = {
state: state.history[index].state,
getters: state.history[index].getters
}
state.lastCommit = Date.now()
state.history = state.history.slice(index + 1)
state.inspectedIndex = -1
Expand Down Expand Up @@ -100,7 +106,9 @@ const getters = {
res.payload = parse(entry.mutation.payload)
}
}
res.state = parse(entry ? entry.state : base)

res.state = parse(entry ? entry.state : base.state)
res.getters = parse(entry ? entry.getters : base.getters)
return res
},

Expand Down
12 changes: 11 additions & 1 deletion test/specs/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ module.exports = {
.assert.containsText('#counter p', '2')
.frame(null)

// getters
.assert.containsText('.vuex-state-inspector', 'isPositive:true')
.frame('target')
.click('.decrement')
.click('.decrement')
.click('.decrement')
.frame(null)
.click('.history .entry:nth-child(4)')
.assert.containsText('.vuex-state-inspector', 'isPositive:false')

// toggle recording
.click('.toggle-recording')
.assert.containsText('.toggle-recording', 'Paused')
Expand All @@ -158,7 +168,7 @@ module.exports = {
.frame('target')
.click('.increment')
.frame(null)
.assert.count('.history .entry', 1)
.assert.count('.history .entry', 4)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because 3 more mutations added


// copy vuex state
.click('.export')
Expand Down