Compare commits

..

No commits in common. "90e90779e1b6d568e2a81338a3a7e8349ce3fb32" and "55e65bd5d8483ee0d0261b7253261af71a983369" have entirely different histories.

5 changed files with 29 additions and 16 deletions

View File

@ -1,12 +1,12 @@
{
"version": "4.0.0-alpha.4",
"type": "module",
"dependencies": {
"@mobily/ts-belt": "4.0.0-rc.5",
"@yanick/updeep-remeda": "^2.3.1",
"immer": "^9.0.15",
"json-schema-shorthand": "^2.0.0",
"json-schema-to-ts": "^2.9.2",
"@reduxjs/toolkit": "^2.2.7",
"memoize-one": "^6.0.0",
"moize": "^6.1.6",
"redux": "^4.2.0",
"remeda": "^1.0.1",
@ -22,7 +22,10 @@
},
"name": "updux",
"description": "Updeep-friendly Redux helper framework",
"scripts": {},
"scripts": {
"docsify:serve": "docsify serve docs"
},
"version": "4.0.0-alpha.3",
"repository": {
"type": "git",
"url": "git+https://github.com/yanick/updux.git"
@ -37,13 +40,17 @@
},
"homepage": "https://github.com/yanick/updux#readme",
"devDependencies": {
"@reduxjs/toolkit": "^2.2.7",
"@vitest/browser": "^0.23.1",
"@vitest/ui": "^2.0.5",
"docsify": "^4.13.1",
"eslint": "^8.22.0",
"eslint-plugin-no-only-tests": "^3.0.0",
"eslint-plugin-todo-plz": "^1.2.1",
"jsdoc-to-markdown": "^7.1.1",
"prettier": "^2.7.1",
"redux-toolkit": "^1.1.2",
"tsdoc-markdown": "^0.0.4",
"typedoc": "^0.25.9",
"typedoc-plugin-markdown": "^3.17.1",
"typescript": "^4.9.5",

View File

@ -1,8 +1,11 @@
import * as rtk from '@reduxjs/toolkit';
const {
import {
configureStore,
} = rtk;
import { Action, AnyAction, EnhancedStore, PayloadAction } from '@reduxjs/toolkit';
EnhancedStore,
Action,
PayloadAction,
AnyAction,
ActionCreatorWithPreparedPayload,
} from '@reduxjs/toolkit';
import {
AugmentedMiddlewareAPI,
DuxActions,
@ -163,7 +166,7 @@ export default class Updux<D extends DuxConfig> {
>,
terminal?: boolean,
): Updux<D>;
addMutation<AC extends rtk.ActionCreatorWithPreparedPayload<any, any, string, never, never>>(
addMutation<AC extends ActionCreatorWithPreparedPayload<any, any, string, never, never>>(
actionCreator: AC,
mutation: Mutation<ReturnType<AC>, DuxState<D>>,
terminal?: boolean
@ -239,7 +242,7 @@ export default class Updux<D extends DuxConfig> {
DuxActions<D>[A] extends (...args: any[]) => infer R ? R : AnyAction
>,
): Updux<D>;
addEffect<AC extends rtk.ActionCreatorWithPreparedPayload<any, any, string, never, never>>(
addEffect<AC extends ActionCreatorWithPreparedPayload<any, any, string, never, never>>(
actionCreator: AC,
effect: EffectMiddleware<D, ReturnType<AC>>,
): Updux<D>;

View File

@ -1,13 +1,15 @@
import * as rtk from '@reduxjs/toolkit';
import { AnyAction } from '@reduxjs/toolkit';
import { Dispatch } from '@reduxjs/toolkit';
import { MiddlewareAPI } from '@reduxjs/toolkit';
import { augmentGetState } from './createStore.js';
import { AugmentedMiddlewareAPI } from './types.js';
//const composeMw = (mws) => (api) => (originalNext) =>
// mws.reduceRight((next, mw) => mw(api)(next), originalNext);
export interface EffectMiddleware<D, A = rtk.AnyAction> {
export interface EffectMiddleware<D, A = AnyAction> {
(api: AugmentedMiddlewareAPI<D>): (
next: rtk.Dispatch<rtk.AnyAction>,
next: Dispatch<AnyAction>,
) => (action: A) => any;
}

View File

@ -1,5 +1,6 @@
import Updux from './Updux.js';
export { withPayload, createAction } from './actions.js';
export { withPayload } from './actions.js';
export { createAction } from '@reduxjs/toolkit';
export default Updux;

View File

@ -1,12 +1,12 @@
import * as R from 'remeda';
import u from '@yanick/updeep-remeda';
import * as rtk from '@reduxjs/toolkit';
import { AnyAction } from '@reduxjs/toolkit';
import { DuxConfig, Mutation } from './types.js';
import { D } from '@mobily/ts-belt';
import Updux from './Updux.js';
export type MutationCase = {
matcher: (action: rtk.AnyAction) => boolean;
matcher: (action: AnyAction) => boolean;
mutation: Mutation;
terminal: boolean;
};
@ -22,7 +22,7 @@ export function buildReducer(
// TODO matcherMutation
// TODO defaultMutation
//
const reducer = (state = initialStateState, action: rtk.AnyAction) => {
const reducer = (state = initialStateState, action: AnyAction) => {
if (!action?.type) throw new Error('reducer called with a bad action');
let active = mutations.filter(({ matcher }) => matcher(action));