Skip to content

Commit

Permalink
docs: testing actions devtools
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed May 12, 2021
1 parent 26a1fe3 commit 06b72f5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/.vitepress/components/ThemeToggle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@
<p>Counter :{{ counterStore.n }}</p>

<button @click="counterStore.increment">Increment</button>
<button @click="counterStore.n++">Direct Increment</button>
<button
@click="
counterStore.$patch((state) => {
state.n++
state.incrementedTimes++
})
"
>
Direct patch
</button>
<button @click="counterStore.fail">Fail</button>
<button @click="counterStore.decrementToZero(300, true)">To ZERO</button>
</template>

Expand Down
13 changes: 13 additions & 0 deletions docs/.vitepress/stores/counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const useCounter = defineStore({
n: 0,
incrementedTimes: 0,
decrementedTimes: 0,
numbers: [] as number[],
}),

getters: {
Expand All @@ -24,6 +25,18 @@ export const useCounter = defineStore({
this.n += amount
},

async fail() {
const n = this.n
await delay(1000)
this.numbers.push(n)
await delay(1000)
if (this.n !== n) {
throw new Error('Someone changed n!')
}

return n
},

async decrementToZero(interval: number = 300, usePatch = true) {
if (this.n <= 0) return

Expand Down

0 comments on commit 06b72f5

Please sign in to comment.