소스 검색

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 }
+}