Skip to content

hazae41/glacier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Dec 10, 2024
46ef833 Β· Dec 10, 2024
Jan 5, 2023
Nov 16, 2024
Dec 10, 2024
Nov 4, 2022
Oct 12, 2023
Dec 14, 2023
Dec 10, 2024
Dec 10, 2024
Jan 17, 2023
Sep 2, 2024

Repository files navigation

npm i @hazae41/glacier

Node Package πŸ“¦ β€’ Read the docs πŸ“š β€’ Next.js Example πŸͺ£ β€’ Expo Example πŸͺ£ β€’ Comparison with other libs 🌐

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.
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 <MyError error={error} />
  if (data == null)
    return <MyLoading />
  return <MyPage data={data} />
}

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