فهرست منبع

add composable to handle updating options, with rollback

Jason Gorst 3 هفته پیش
والد
کامیت
2f9e9f2cda
1فایلهای تغییر یافته به همراه17 افزوده شده و 0 حذف شده
  1. 17 0
      app/composables/useOptionsCache.js

+ 17 - 0
app/composables/useOptionsCache.js

@@ -0,0 +1,17 @@
+export default function useOptionsCache() {
+  const queryCache = useQueryCache()
+  const oldOptions = ref()
+
+  const update = () => {
+    oldOptions.value = queryCache.getQueryData(characterListQuery.key)
+
+    queryCache.setQueryData(characterOptionsQuery.key, () =>
+      getCharacterOptions(queryCache.getQueryData(characterOptionsQuery.key))
+    )
+  }
+
+  const rollback = () =>
+    queryCache.setQueryData(characterOptionsQuery.key, () => oldOptions.value)
+
+  return { update, rollback }
+}