Releases: hazae41/glacier
Releases · hazae41/glacier
1.0.58 - The storage garbage collection update
BREAKING CHANGES
- AsyncLocalStorage and SyncLocalStorage (along with their hooks) now accept a prefix as first parameter
useAsyncLocalStorage("mycache")
Default prefix is xswr:
CHANGES
- Storages are now doing garbage collection out of the box! ⚡️
- Added garbage collection on unmount and on page unload for SyncLocalStorage and AsyncLocalStorage
- Added garbage collection on unmount and on page load for IDBStorage
- Added
collect()
andunmount()
methods on all storages
1.0.57 - The time update
BREAKING CHANGES
- Renamed jsoneq to jsonEquals
- Catched errors are no longer deduplicated or expired
CHANGES
- You can now return a custom time in your fetcher
async function fetchAsJson<T>(url: string, more: XSWR.PosterMore<T>) {
const { signal } = more
const res = await fetch(url, { signal })
const cooldown = Date.now() + (5 * 1000)
const expiration = Date.now() + (10 * 1000)
if (!res.ok) {
const error = new Error(await res.text())
return { error, cooldown, expiration } // implicit Date.now()
}
const data = await res.json() as T
return { data, time: data.time, cooldown, expiration } // explicit date.time (milliseconds)
}
- Fixed bugs
1.0.56 - The error update
NO BREAKING CHANGES
CHANGES
- You can now return an error in your fetcher instead of throwing
async function fetchAsJson<T>(url: string, more: XSWR.PosterMore<T>) {
const { signal } = more
const res = await fetch(url, { signal })
const cooldown = Date.now() + (5 * 1000)
const expiration = Date.now() + (10 * 1000)
if (!res.ok) {
const error = new Error(await res.text())
return { error, cooldown, expiration }
}
const data = await res.json() as T
return { data, cooldown, expiration }
}
This way you can still set expiration and cooldown
- Added scroll tests
- New mutation merge strategy (not breaking)
- Bug fixes and performances improvements
1.0.55 - The optimistic update
BREAKING CHANGES
refetch()
now cancels ongoing requests (unless it's an optimistic update)update()
no longer throws on error, it just mutates the state with the error (you can still check for error by checking the returned state)
CHANGES
handle.aborter
is now available on optimistic updateshandle.optimistic
is now available to tell whether the ongoing request is optimistic- Lot of bug fixes and behaviour fixes
1.0.52 - The IndexedDB update
NO BREAKING CHANGE
CHANGES
- You can now use IndexedDB storage 🚀
const storage = new XSWR.IDBStorage("mydb")
function getHelloSchema() { // See the docs for the new schema pattern
return XSWR.single("/api/hello", fetchAsJson, { storage })
}
- Improved performances
1.0.51 - The schema memo update
BREAKING CHANGES
- New syntax for
XSWR.use
:XSWR.use(schema)
=>XSWR.use(factory, deps)
function getCatShema(id: string) {
return XSWR.single(["/api/cat", id], fetchAsJson)
}
function useCatBase(id: string) {
return XSWR.use(getCatSchema, [id])
}
It works like useMemo
but the deps are passed to the factory.
1.0.49 - The schemas update
NO BREAKING CHANGES
CHANGES
- You can now use your favorite resources without using a hook, thanks to schemas and objects:
// Create a schema for your resource
function getHelloSchema(id: string) {
return XSWR.single("/api/hello", fetchAsJson)
}
// Use it in a hook
function useHello(id: string) {
const handle = XSWR.use(getHelloSchema(id))
XSWR.useFetch(handle)
return handle
}
// Or in a function
function Setter() {
const { make } = XSWR.useXSWR()
const set = useCallback(async () => {
const object = make(getHelloSchema("123"))
await object.mutate({ data: "hello world" })
await object.refetch()
}, [make])
return <button onClick={set}>
Click me
</button>
}
1.0.45 - The core parameters update
NO BREAKING CHANGES
CHANGES
- You can now use
XSWR.ParamsProvider
to provide custom params to all children without changing the core provider
export default function Wrapper() {
return <XSWR.ParamsProvider
serializer={GZIP}>
<Page />
</XSWR.ParamsProvider>
}
Since params = { ...parent, ...current }
the downmost params will override.
If I then use a custom serializer in my handle, JSON will be used instead of GZIP.
useSingle(url, fetcher, { serializer: JSON })
1.0.42 - The parameters update
NO BREAKING CHANGES
CHANGES
- You can now use a custom storage in handle factories
// Create a storage in the hook or at top-level
const storage = XSWR.useAsyncLocalStorage()
const handle = XSWR.useSingle(
"/api/hello",
fetchAsJson,
{ storage })
XSWR.useFetch(handle)
return handle
- You can now use a custom key serializer in handle factories
const handle = XSWR.useSingle(
"/api/hello",
fetchAsJson,
{ serializer: GZIP })
XSWR.useFetch(handle)
return handle
- You can now use a custom equals function in handle factories
const handle = XSWR.useSingle(
"/api/hello",
fetchAsJson,
{ equals: deepCompare })
XSWR.useFetch(handle)
return handle
1.0.40 - The serializer update
NO BREAKING CHANGES
CHANGES
- Allow custom serializer in Core, for serializing arbitrary keys
- Allow custom serializer in LocalStorages, for serializing states
- Default serializer is JSON, i added GZIP example in tests