feat(core): add error feature (#713)

This commit is contained in:
rahim
2026-03-04 23:36:26 -08:00
committed by GitHub
parent ae754eec8f
commit 879d55d1d2
9 changed files with 63 additions and 0 deletions
+1
View File
@@ -7,6 +7,7 @@ import type { AnySlice, InferSliceState, StateContext } from './slice';
const stateContext: StateContext<unknown> = {
target: throwNoTargetError,
signals: new AbortControllerRegistry(),
set: throwNoTargetError,
};
/**
+2
View File
@@ -40,6 +40,8 @@ export interface StateContext<Target> {
* (e.g., loading a new source cancels pending seeks).
*/
signals: AbortControllerRegistry;
/** Patch the slice state. Safe to use inside action closures (not during `state()` init). */
set: (partial: Record<string, unknown>) => void;
}
// ----------------------------------------
+1
View File
@@ -38,6 +38,7 @@ export function createStore<Target = unknown>(): <State>(
return target!;
},
signals,
set: (partial) => state.patch(partial as Partial<State>),
} satisfies StateContext<Target>);
state = createState(initialState);