Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hazae41/glacier
Keep your data fresh
https://github.com/hazae41/glacier
ethersjs fetch garbage-collection graphql indexeddb localstorage nextjs normalization react react-hooks react-query react-suspense redux rest server-side-rendering suspense swr typescript
Last synced: 3 days ago
JSON representation
Keep your data fresh
- Host: GitHub
- URL: https://github.com/hazae41/glacier
- Owner: hazae41
- Created: 2022-06-10T15:37:42.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-12-10T21:57:38.000Z (about 1 month ago)
- Last Synced: 2025-01-01T03:06:47.107Z (10 days ago)
- Topics: ethersjs, fetch, garbage-collection, graphql, indexeddb, localstorage, nextjs, normalization, react, react-hooks, react-query, react-suspense, redux, rest, server-side-rendering, suspense, swr, typescript
- Language: TypeScript
- Homepage:
- Size: 2.1 MB
- Stars: 126
- Watchers: 5
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
- awesome-ccamel - hazae41/glacier - Keep your data fresh (TypeScript)
README
```bash
npm i @hazae41/glacier
```[**Node Package 📦**](https://www.npmjs.com/package/@hazae41/glacier) • [**Read the docs 📚**](https://github.com/hazae41/glacier/blob/master/docs) • [**Next.js Example 🪣**](https://codesandbox.io/p/github/hazae41/glacier-example-next) • [**Expo Example 🪣**](https://snack.expo.dev/@git/github.com/hazae41/xswr-example-expo) • [**Comparison with other libs 🌐**](https://github.com/hazae41/glacier/blob/master/docs/comparison.md)
## Philosophy 🧠
Glacier uses two new approaches compared to other data fetching libraries like swr or react-query:
1) Encapsulating key+fetcher+params in a single abstraction called schema.
2) Composing features with very simple hooks instead of having bloated configuration and unexpected behaviors.```tsx
function useAutoFetchMixture(query: Query) {
useFetch(query) // Fetch on mount and url change
useVisible(query) // Fetch when the page is focused
useOnline(query) // Fetch when the browser is online
}function useHelloWithAutoFetch() {
const query = useQuery(createHelloQuery, [])
useAutoFetchMixture(query)
return query
}function MyApp() {
const { data, error } = useHelloWithAutoFetch()if (error != null)
return
if (data == null)
return
return
}
```## Features 🔥
- 100% TypeScript and ESM
- No external dependency
- Composition-based hooks
- Rust-like patterns
- Transport agnostic (REST, GraphQL, WebSocket)
- Storage agnostic (IndexedDB, localStorage)
- Works in a Service Worker or in a serverless function
- Per-query, encrypted, garbage-collected, persistent storage
- Store normalization and indexes
- Concurrent and multi-step optimistic states
- Request deduplication, cooldown, timeout, cancellation, expiration, and retrying
- Automatic refetching based on various signals
- Page-based and cursor-based pagination
- SSR & ISR support
- React Suspense support
- React Native support