PiniaHistoryPlugin that exposes undo and redo actions on stores.
undo action should reverse the most recent state update.redo action should reapply the most recent state update that was reversed by the undo action.<aside> 💡 Hint: useRefHistory from VueUse could be very helpful in this. Don’t forget to install VueUse:
npm i @vueuse/core
</aside>
<aside>
💡 Hint: The useRefHistory already returns the functions you need.
const state = ref({})
const { undo, redo } = useRefHistory(state, { deep: true })
Simply make those functions available in the stores that use the plugin.
</aside>
This is a tough one, feel free to ask for help! :)
✅ When complete you should be able to create undo redo buttons that trigger the undo and redo actions on the CartStore like this:
