feat(actions): add action context for safe nested dispatch with depth limit to prevent deadlocks
This commit is contained in:
@@ -1,7 +1,16 @@
|
||||
import { StatePart } from './smartstate.classes.statepart.js';
|
||||
|
||||
/**
|
||||
* Context object passed to action definitions, enabling safe nested dispatch.
|
||||
* Use `context.dispatch()` to dispatch sub-actions inline (bypasses the mutation queue).
|
||||
* Direct `statePart.dispatchAction()` from within an action will deadlock.
|
||||
*/
|
||||
export interface IActionContext<TStateType> {
|
||||
dispatch<T>(action: StateAction<TStateType, T>, payload: T): Promise<TStateType>;
|
||||
}
|
||||
|
||||
export interface IActionDef<TStateType, TActionPayloadType> {
|
||||
(stateArg: StatePart<any, TStateType>, actionPayload: TActionPayloadType): Promise<TStateType>;
|
||||
(stateArg: StatePart<any, TStateType>, actionPayload: TActionPayloadType, context?: IActionContext<TStateType>): Promise<TStateType>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user