remote state management for frontend applications.
- Typed API
- Zero dependencies
- Flexible integration
npm install restatement- Setup your cache of choice. lru-cache supported by default.
- Create a config object.
- Start using queries and mutations on your project.
import { restatementConfig } from 'restatement';
import { LRUCache } from 'lru-cache';
const cache = new LRUCache<string, number>(/* ... */);
const cacheStore = new LRUCacheAdapter(cache);
const config = restatementConfig(cacheStore);
async function getUserInfo() { /* ... */ }
// in component UserInfo
const queryA = Query.create(makeQueryInput(
config,
{ key: ['account', 'user', 123], queryFn: getUserInfo }
));
// in component ShoppingCart
const queryB = Query.create(makeQueryInput(
config,
{ key: ['account', 'user', 123], queryFn: getUserInfo }
));This will result in only 1 query being executed, since the queryA will cache the value returned by the getUserInfo, making queryB return the most recent value from the cache.
Clone the repo and run pnpm install.
To run the tests, use the package script test or test:cov for code coverage.
To build the js files, run build:js and build:type for typescript declaration files.
For a full build (.d.ts, .js), run the build script.