@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.
21 lines (20 loc) • 659 B
JavaScript
import { shallowEqual } from "fast-equals";
//#region src/utils/store/create-reducer.ts
var createReducer = (initialState) => {
const handlers = {};
const withReducer = (action, reducer) => {
handlers[action.type] = reducer;
return storeReducer;
};
const storeReducer = (state = initialState, action) => {
const handler = handlers[action.type];
const nextState = handler?.(state, action) ?? state;
return shallowEqual(nextState, state) ? state : nextState;
};
storeReducer.with = withReducer;
storeReducer.initialState = initialState;
return storeReducer;
};
//#endregion
export { createReducer };
//# sourceMappingURL=create-reducer.js.map