<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>
n: 0,
incrementedTimes: 0,
decrementedTimes: 0,
+ numbers: [] as number[],
}),
getters: {
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