@augmentcode/ag-redux-toolkit
Version:
Redux + Saga state management for Svelte apps — designed for AI agents. Includes runtime TypeScript source, AI skills, and reference documentation for robust, observable, high-performance state management.
75 lines • 3.88 kB
TypeScript
import { EventChannel, Task } from 'redux-saga';
import { StoreSelector } from '../../types';
/**
* The payload type emitted by selector channels
*/
export type SelectorChannelPayload<R> = {
payload: R;
prevPayload: R | undefined | null;
};
/**
* Worker saga type for selector channel effects
*/
export type SelectorWorkerSaga<R> = (payload: SelectorChannelPayload<R>) => Generator<any, void, any>;
/**
* Creates an event channel from a selector that emits when the selector value changes.
* The channel must be closed when no longer needed to prevent memory leaks.
*
* Usage:
* ```typescript
* const channel = yield* createChannelFromSelector(mySelector, arg1, arg2);
* try {
* while (true) {
* const { payload, prevPayload } = yield* take(channel);
* // handle value change
* }
* } finally {
* channel.close();
* }
* ```
*
* @param selector - The store selector to watch
* @param args - Arguments to pass to the selector
* @returns An event channel that emits { payload, prevPayload } on value changes
*/
export declare function createChannelFromSelector<R, ARGS extends any[]>(selector: StoreSelector<R, ARGS, any>, ...args: ARGS): Generator<any, EventChannel<SelectorChannelPayload<R>>, any>;
/**
* Forks a task that spawns a new worker for each selector value change.
* Similar to `takeEvery` but:
* - Creates the channel from the selector automatically
* - Closes the channel when the saga is cancelled or fails
* - Automatically forks itself (no need to wrap in fork())
*
* @param selector - The store selector to watch
* @param argsOrWorker - Arguments to pass to the selector, or the worker if no args needed
* @param worker - Worker saga to run for each value change (optional if argsOrWorker is the worker)
*/
export declare function takeEveryFromSelector<R>(selector: StoreSelector<R, [], any>, worker: SelectorWorkerSaga<R>): Generator<any, Task, any>;
export declare function takeEveryFromSelector<R, ARGS extends any[]>(selector: StoreSelector<R, ARGS, any>, args: ARGS, worker: SelectorWorkerSaga<R>): Generator<any, Task, any>;
/**
* Forks a task that cancels previous worker and spawns a new one for each selector value change.
* Similar to `takeLatest` but:
* - Creates the channel from the selector automatically
* - Closes the channel when the saga is cancelled or fails
* - Automatically forks itself (no need to wrap in fork())
*
* @param selector - The store selector to watch
* @param argsOrWorker - Arguments to pass to the selector, or the worker if no args needed
* @param worker - Worker saga to run for each value change (optional if argsOrWorker is the worker)
*/
export declare function takeLatestFromSelector<R>(selector: StoreSelector<R, [], any>, worker: SelectorWorkerSaga<R>): Generator<any, Task, any>;
export declare function takeLatestFromSelector<R, ARGS extends any[]>(selector: StoreSelector<R, ARGS, any>, args: ARGS, worker: SelectorWorkerSaga<R>): Generator<any, Task, any>;
/**
* Forks a task that ignores new values while a worker is running.
* Similar to `takeLeading` but:
* - Creates the channel from the selector automatically
* - Closes the channel when the saga is cancelled or fails
* - Automatically forks itself (no need to wrap in fork())
*
* @param selector - The store selector to watch
* @param argsOrWorker - Arguments to pass to the selector, or the worker if no args needed
* @param worker - Worker saga to run (optional if argsOrWorker is the worker)
*/
export declare function takeLeadingFromSelector<R>(selector: StoreSelector<R, [], any>, worker: SelectorWorkerSaga<R>): Generator<any, Task, any>;
export declare function takeLeadingFromSelector<R, ARGS extends any[]>(selector: StoreSelector<R, ARGS, any>, args: ARGS, worker: SelectorWorkerSaga<R>): Generator<any, Task, any>;
//# sourceMappingURL=selector-channel-effects.d.ts.map