Commit 1932a8d6 authored by Adam Procter's avatar Adam Procter 💩

better naming

improved naming of functions to step fwd and backwards in time and added option to make sure initial selection enters store
parent 259d347c
......@@ -2,13 +2,14 @@
<div>
<label for="flavour">Select your favorite ice cream flavour?</label>
<select @input="changed">
<option disabled selected value>-- select an option --</option>
<option value="Choc">Choc</option>
<option value="Vanilla">Vanilla</option>
<option value="Strawberry">Strawberry</option>
</select>
<button v-on:click="undo">Undo</button>
<button v-on:click="redo">Redo</button>
<button v-on:click="stepback">BacK</button>
<button v-on:click="stepfwd">FwD</button>
<button v-on:click="reset">Clear State</button>
</div>
</template>
......@@ -22,13 +23,13 @@ export default {
reset() {
this.$store.commit('CLEAR_STATE')
},
redo() {
stepfwd() {
// call the method here
this.$emit('redo')
this.$emit('stepfwd')
},
undo() {
stepback() {
// call the method here
this.$emit('undo')
this.$emit('stepback')
}
}
}
......
<template>
<div class="entryform">
<EntryForm v-on:redo="redo()" v-on:undo="undo()" />
<EntryForm v-on:stepfwd="fwd()" v-on:stepback="back()" />
<DisplayText />
</div>
</template>
......@@ -20,36 +20,36 @@ export default {
data() {
return {
done: [],
undone: [],
stepfwd: [],
stepback: [],
newMutation: true
}
},
//any mutations are put into the done array
//any mutations are put into the stepfwd array
created() {
this.$store.subscribe(mutation => {
if (mutation.type !== CLEAR_STATE) {
this.done.push(mutation)
this.stepfwd.push(mutation)
}
if (this.newMutation) {
this.undone = []
this.stepback = []
}
})
},
methods: {
redo() {
let commit = this.undone.pop()
fwd() {
let commit = this.stepback.pop()
this.newMutation = false
this.$store.commit(`${commit.type}`, commit.payload)
this.newMutation = true
},
undo() {
this.undone.push(this.done.pop())
back() {
this.stepback.push(this.stepfwd.pop())
this.newMutation = false
this.$store.commit(CLEAR_STATE)
this.done.forEach(mutation => {
this.stepfwd.forEach(mutation => {
this.$store.commit(`${mutation.type}`, mutation.payload)
this.done.pop()
this.stepfwd.pop()
})
this.newMutation = true
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment