remote state management for frontend applications.
- Typed API
- Zero dependencies
- Flexible implementation
Setup all the shared pieces:
Cache
to store all the remote statePubSub
to notify the query instances that the value has changed.
and make a new RemoteStateQuery()
for all the queries that can be cached.
const cacheStore = new CacheStore();
const stateProvider = new PubSub();
async function getUserInfo() { /* ... */ }
// in component UserInfo
const queryA = new RemoteStateQuery({ cacheStore, stateProvider, queryFn: getUserInfo });
// in component ShoppingCart
const queryB = new RemoteStateQuery({ cacheStore, stateProvider, 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 --coverage
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.