@refinest/context
v0.2.0
Published
Refinest: DAG-based context engine with dependent pickers and reactive store
Readme
@refinest/context
DAG-based context engine for refinest: a reactive store whose slices may depend on one another, with dependent pickers and scope cascading.
Use it for the ambient state a whole admin is filtered by — the selected company, warehouse, product group — where changing one slice must invalidate the slices below it.
Install
pnpm add @refinest/context @refinest/coreUsage
defineContextSlices takes a factory and hands you a builder; each slice's key becomes its name, so it is never written twice:
import { defineContextSlices } from '@refinest/context';
const slices = defineContextSlices((s) => ({
company: s.static({ value: null }),
warehouse: s.picker({
resource: () => warehouseResource,
dependsOn: ['company'], // re-resolves when company changes
resetWhen: ['company'], // and clears, rather than keeping a stale pick
persist: 'localStorage',
required: true,
}),
}));Main exports
defineContextSliceswithdefineStaticSlice/defineAsyncSlice/definePickerSlice/defineFromAuthSlice— the four slice kinds: a plain value, an awaited value, a record chosen from a resource, and a value derived from the auth session.createStore/createAtom/createResolver— the reactive primitives underneath.topoSort/trackReads— dependency ordering and read tracking; a slice's dependencies are discovered, not declared twice.mergeScope/cascadeScope/checkRequireScope— merge a parent → child scope chain (child wins) and assert a resource'srequireScopeis satisfied before querying.
License
MIT
