Compare commits

...

2 Commits

Author SHA1 Message Date
90e90779e1 remove unused dependencies 2024-08-09 10:31:03 -04:00
ac53f1d24b different import type 2024-08-09 10:27:41 -04:00
5 changed files with 16 additions and 29 deletions

View File

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

View File

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

View File

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

View File

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

View File

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