Skip to content

Commit

Permalink
feat: accept function in setEntryData
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Dec 25, 2023
1 parent 0ee5c8a commit 2abb7c0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/data-fetching-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,23 @@ export const useDataFetchingStore = defineStore('PiniaColada', () => {
}
}

function setEntryData<TResult = unknown>(key: UseQueryKey, data: TResult) {
function setEntryData<TResult = unknown>(
key: UseQueryKey,
data: TResult | ((data: Ref<TResult | undefined>) => void)
) {
const entry = entryStateRegistry.get(key) as
| UseQueryStateEntry<TResult>
| undefined
if (!entry) {
return
}

entry.data.value = data
if (typeof data === 'function') {
// the remaining type is TResult & Fn, so we need a cast
;(data as (data: Ref<TResult | undefined>) => void)(entry.data)
} else {
entry.data.value = data
}
// TODO: complete and test
entry.error.value = null
}
Expand Down

0 comments on commit 2abb7c0

Please sign in to comment.