different import type
This commit is contained in:
parent
55e65bd5d8
commit
ac53f1d24b
15
src/Updux.ts
15
src/Updux.ts
@ -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>;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
@ -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));
|
||||||
|
Loading…
Reference in New Issue
Block a user