0.14.16 • Published 4 months ago
@data-client/core v0.14.16
Reducer/flux normalized, framework-agnostic data store. Includes managers/middleware, global referential equality guarantees, automatic expiry policies, data normalization. Consumes TypeScript Standard Endpoints
📖Read The Docs | 🏁Getting Started | 🎮Todo Demo | 🎮Github Demo | 🎮NextJS SSR Demo
Framework Implementations
Sample React Hook suspense implementation
function useSuspense(endpoint, ...args)
const state = useCacheState();
const controller = useController();
const key = args[0] !== null ? endpoint.key(...args) : '';
const cacheResults = key && state.endpoints[key];
const meta = state.meta[key];
// Compute denormalized value
const { data, expiryStatus, expiresAt } = useMemo(() => {
return controller.getResponse(endpoint, ...args, state);
}, [
cacheResults,
state.indexes,
state.entities,
state.entityMeta,
meta,
key,
]);
const error = controller.getError(endpoint, ...args, state);
// If we are hard invalid we must fetch regardless of triggering or staleness
const forceFetch = expiryStatus === ExpiryStatus.Invalid;
const maybePromise = useMemo(() => {
// null params mean don't do anything
if ((Date.now() <= expiresAt && !forceFetch) || !key) return;
return controller.fetch(endpoint, ...args);
// we need to check against serialized params, since params can change frequently
}, [expiresAt, controller, key, forceFetch, state.lastReset]);
// fully "valid" data will not suspend even if it is not fresh
if (expiryStatus !== ExpiryStatus.Valid && maybePromise) {
throw maybePromise;
}
if (error) throw error;
return data;
}
API
- Controller
- Middleware: LogoutManager, NetworkManager, SubscriptionManager, PollingSubscription, DevToolsManager
- State: createReducer(), initialState, applyManager
0.14.16
4 months ago
0.14.13
5 months ago
0.14.10
6 months ago
0.14.5
7 months ago
0.14.6
7 months ago
0.14.8
7 months ago
0.13.0
8 months ago
0.14.0
7 months ago
0.13.1
8 months ago
0.14.1
7 months ago
0.14.2
7 months ago
0.14.4
7 months ago
0.13.5
8 months ago
0.12.5
9 months ago
0.12.3
9 months ago
0.12.1
9 months ago
0.11.5
10 months ago
0.11.4
10 months ago
0.11.0
10 months ago
0.10.0
1 year ago
0.9.7
1 year ago
0.9.4
1 year ago
0.9.3
1 year ago
0.9.2
1 year ago
0.9.0
1 year ago
0.8.1
1 year ago
0.8.0
1 year ago
0.4.3
1 year ago
0.4.2
1 year ago
0.4.1
1 year ago
0.4.0
1 year ago
0.3.0
2 years ago
0.2.1
2 years ago
0.2.0
2 years ago
0.1.0
2 years ago