@nanostores/query
Advanced tools
Comparing version 0.1.0 to 0.1.1
import { MapStore, ReadableAtom } from "nanostores"; | ||
export declare type KeyInput = string | Array<string | ReadableAtom<string | null | undefined>>; | ||
declare type NoKey = null | undefined | void; | ||
export declare type KeyInput = string | Array<string | ReadableAtom<string | NoKey>>; | ||
declare type Key = string; | ||
@@ -4,0 +5,0 @@ declare type KeyParts = string[]; |
@@ -22,12 +22,7 @@ import { map, onStart, onStop, atom } from "nanostores"; | ||
return; | ||
const isKeyStillSame = () => store.key === key; | ||
const set = (v) => { | ||
if (isKeyStillSame()) { | ||
if (store.key === key) { | ||
store.set(v); | ||
events.emit(SET_CACHE, key, v, true); | ||
} | ||
}, setKey = (k, v) => { | ||
if (isKeyStillSame()) { | ||
store.setKey(k, v); | ||
} | ||
}; | ||
@@ -53,6 +48,5 @@ const { dedupeTime = 4e3, fetcher } = { | ||
_runningFetches.add(key); | ||
setKey("loading", true); | ||
try { | ||
const promise = fetcher(...keyParts); | ||
setKey("promise", promise); | ||
set({ data: store.value.data, ...loading, promise }); | ||
const res = await promise; | ||
@@ -153,8 +147,9 @@ cache.set(key, res); | ||
}; | ||
const newImplFactory = (origin) => (listener) => { | ||
const originListen = fetcherStore.listen; | ||
fetcherStore.listen = (listener) => { | ||
const unsub = originListen(listener); | ||
listener(fetcherStore.value); | ||
handleNewListener(); | ||
return origin(listener); | ||
return unsub; | ||
}; | ||
fetcherStore.listen = newImplFactory(fetcherStore.listen); | ||
fetcherStore.subscribe = newImplFactory(fetcherStore.subscribe); | ||
onStop(fetcherStore, () => { | ||
@@ -161,0 +156,0 @@ fetcherStore.value = { ...notLoading }; |
{ | ||
"name": "@nanostores/query", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Tiny remote data fetching library for Nano Stores", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -8,3 +8,3 @@ # Nano Stores Query | ||
- **Small**. 1.61 Kb (minified and gzipped). | ||
- **Small**. 1.59 Kb (minified and gzipped). | ||
- **Familiar DX**. If you've used [`swr`](https://swr.vercel.app/) or | ||
@@ -11,0 +11,0 @@ [`react-query`](https://react-query-v3.tanstack.com/), you'll get the same treatment, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33127
640