redux-sacala 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/redux-sacala.cjs +2 -1
- package/build/redux-sacala.cjs.map +1 -0
- package/build/redux-sacala.d.ts +4 -4
- package/build/redux-sacala.js +38 -47
- package/build/redux-sacala.js.map +1 -0
- package/package.json +1 -1
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/jsLinters/eslint.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/prettier.xml +0 -7
- package/.idea/redux-sacala.iml +0 -13
- package/.idea/vcs.xml +0 -6
- package/.idea/webResources.xml +0 -14
- package/.prettierignore +0 -5
- package/.prettierrc +0 -8
- package/eslint.config.js +0 -23
- package/src/redux-sacala.spec.ts +0 -55
- package/src/redux-sacala.ts +0 -132
- package/tsconfig.json +0 -14
- package/vite.config.ts +0 -29
package/build/redux-sacala.cjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=e=>{const r={};for(const c in e)r[c]=e[c].bind(e);return r},a=(e,r)=>{const c={};for(const n in r)c[e+n]=r[n];return c},l=e=>r=>r===void 0?{type:e}:{type:e,payload:r},p=e=>r=>({type:e,payload:r}),f=(e,r,c)=>{const n=a(e+"/",u(c));return(o=r,s)=>{if(s&&s.type){const t=n[s.type];return t?t(o,s.payload):o}else return o}},y=(e,r)=>(c=>n=>{const o=a(e+"/",u(r(n.dispatch,n.getState)));return s=>t=>{t&&Object.prototype.hasOwnProperty.call(o,t.type)?o[t.type](t.payload,c):s(t)}}),i=()=>{throw new Error("Can't have access to 'dispatch' and 'getState' during initialization")},b=()=>({name:e,initial:r,actions:c,effects:n})=>{const o=Object.keys(c).reduce((t,d)=>(t[d]=l(`${e}/${d}`),t),{}),s=Object.keys(n?n(i,i):{}).reduce((t,d)=>(t[d]=p(`${e}/${d}`),t),{});return{name:e,reducer:f(e,r,c),createMiddleware:n?y(e,n):(()=>t=>d=>d),actions:{...o,...s}}};exports.createReduxBlock=b;
|
|
2
|
+
//# sourceMappingURL=redux-sacala.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redux-sacala.cjs","sources":["../src/redux-sacala.ts"],"sourcesContent":["import { Dispatch, Action, Reducer, Middleware, AnyAction, MiddlewareAPI } from \"redux\";\n\ntype UnknownToUndefined<T> = unknown extends T ? undefined : T;\n\ntype FirstArgument<F> = F extends (arg1: infer U, ...args: any[]) => any ? UnknownToUndefined<U> : undefined;\ntype SecondArgument<F> = F extends (arg1: any, arg2: infer U, ...args: any[]) => any\n ? UnknownToUndefined<U>\n : undefined;\n\nconst bindAll = <T extends { [key: string]: Function }>(map: T): T => {\n const result = {} as any as T;\n for (const i in map) {\n result[i] = map[i].bind(map);\n }\n return result;\n};\n\nconst appendPrefix = <T>(prefix: string, map: { [key: string]: T }) => {\n const r: { [key: string]: any } = {};\n for (const i in map) {\n r[prefix + i] = map[i];\n }\n return r;\n};\n\n// Input\ntype ActionHandler<BlockState, Payload> = (state: BlockState, payload: Payload) => BlockState;\ntype ActionMap<BlockState> = { [action: string]: ActionHandler<BlockState, any> };\ntype EffectsMap<GlobalState, ExtraArgument> = (\n dispatch: Dispatch,\n getState: () => GlobalState,\n) => { [effect: string]: (payload: any, extraArgument: ExtraArgument) => any };\n\n// Output\ntype ActionCreator<Handler extends ActionHandler<any, any>> =\n undefined extends SecondArgument<Handler>\n ? () => Action<string>\n : (payload: SecondArgument<Handler>) => Action<string> & { payload: SecondArgument<Handler> };\n\ntype ActionCreatorMap<Actions extends ActionMap<any>> = {\n [name in keyof Actions]: ActionCreator<Actions[name]>;\n};\n\ntype EffectsCreatorMap<GlobalState, ExtraArgument, Map extends EffectsMap<GlobalState, ExtraArgument>> = {\n [key in keyof ReturnType<Map>]: undefined extends FirstArgument<ReturnType<Map>[key]>\n ? () => Action\n : (payload: FirstArgument<ReturnType<Map>[key]>) => Action;\n};\n\n// Transformation\nconst createActionCreator = (type: string) => (payload?: any) => (payload === undefined ? { type } : { type, payload });\nconst createEffectCreator = (type: string) => (payload: any) => ({ type, payload });\n\nconst createReducer = <BlockState>(prefix: string, initial: BlockState, actionMap: ActionMap<BlockState>): Reducer => {\n const actions: ActionMap<BlockState> = appendPrefix(prefix + \"/\", bindAll(actionMap));\n return (state: BlockState = initial, action?: AnyAction) => {\n if (action && action.type) {\n const handler: (state: BlockState, payload?: any) => BlockState = actions[action.type];\n if (handler) {\n return handler(state, action.payload);\n } else {\n return state;\n }\n } else {\n return state;\n }\n };\n};\n\ntype MiddlewareCreator<T> = T extends undefined ? () => Middleware : (argument: T) => Middleware;\n\nconst createMiddlewareCreator = <GlobalState, ExtraArgument>(\n prefix: string,\n effectsMap: EffectsMap<GlobalState, ExtraArgument>,\n): MiddlewareCreator<ExtraArgument> =>\n ((argument: ExtraArgument) => (store: MiddlewareAPI) => {\n const effects = appendPrefix(prefix + \"/\", bindAll(effectsMap(store.dispatch, store.getState)));\n return (next: Dispatch) => (action: Action<string> & { payload: any[] }) => {\n if (action && Object.prototype.hasOwnProperty.call(effects, action.type)) {\n effects[action.type](action.payload, argument);\n } else {\n next(action);\n }\n };\n }) as MiddlewareCreator<ExtraArgument>;\n\nconst fail = (): never => {\n throw new Error(\"Can't have access to 'dispatch' and 'getState' during initialization\");\n};\n\nexport const createReduxBlock =\n <GlobalState, ExtraArgument = undefined>() =>\n <\n Name extends keyof GlobalState & string,\n Actions extends ActionMap<GlobalState[Name]>,\n Effects extends EffectsMap<GlobalState, ExtraArgument>,\n >({\n name,\n initial,\n actions,\n effects,\n }: {\n name: Name;\n initial: GlobalState[Name];\n actions: Actions;\n effects?: Effects;\n }): {\n name: Name;\n reducer: Reducer<GlobalState[Name]>;\n actions: ActionCreatorMap<Actions> & EffectsCreatorMap<GlobalState, ExtraArgument, Effects>;\n } & ({} extends ReturnType<Effects> ? {} : { createMiddleware: MiddlewareCreator<ExtraArgument> }) => {\n const actionCreators = Object.keys(actions).reduce((r, key) => {\n r[key] = createActionCreator(`${name}/${key}`);\n return r;\n }, {} as any);\n const effectCreators = Object.keys(effects ? effects(fail, fail) : {}).reduce((r, key) => {\n r[key] = createEffectCreator(`${name}/${key}`);\n return r;\n }, {} as any);\n\n return {\n name,\n reducer: createReducer(name as string, initial, actions),\n createMiddleware: effects\n ? createMiddlewareCreator<GlobalState, ExtraArgument>(name as string, effects)\n : ((() => (_: MiddlewareAPI) => (next: Dispatch) => next) as MiddlewareCreator<ExtraArgument>),\n actions: {\n ...actionCreators,\n ...effectCreators,\n },\n };\n };\n"],"names":["bindAll","map","result","i","appendPrefix","prefix","r","createActionCreator","type","payload","createEffectCreator","createReducer","initial","actionMap","actions","state","action","handler","createMiddlewareCreator","effectsMap","argument","store","effects","next","fail","createReduxBlock","name","actionCreators","key","effectCreators","_"],"mappings":"gFASA,MAAMA,EAAkDC,GAAc,CAClE,MAAMC,EAAS,CAAA,EACf,UAAWC,KAAKF,EACZC,EAAOC,CAAC,EAAIF,EAAIE,CAAC,EAAE,KAAKF,CAAG,EAE/B,OAAOC,CACX,EAEME,EAAe,CAAIC,EAAgBJ,IAA8B,CACnE,MAAMK,EAA4B,CAAA,EAClC,UAAWH,KAAKF,EACZK,EAAED,EAASF,CAAC,EAAIF,EAAIE,CAAC,EAEzB,OAAOG,CACX,EA2BMC,EAAuBC,GAAkBC,GAAmBA,IAAY,OAAY,CAAE,KAAAD,CAAA,EAAS,CAAE,KAAAA,EAAM,QAAAC,CAAA,EACvGC,EAAuBF,GAAkBC,IAAkB,CAAE,KAAAD,EAAM,QAAAC,IAEnEE,EAAgB,CAAaN,EAAgBO,EAAqBC,IAA8C,CAClH,MAAMC,EAAiCV,EAAaC,EAAS,IAAKL,EAAQa,CAAS,CAAC,EACpF,MAAO,CAACE,EAAoBH,EAASI,IAAuB,CACxD,GAAIA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atch } from 'redux';
|
|
|
3
3
|
import { Middleware } from 'redux';
|
|
4
4
|
import { Reducer } from 'redux';
|
|
5
5
|
|
|
6
|
-
declare type ActionCreator<Handler extends ActionHandler<any, any>> = undefined extends SecondArgument<Handler> ? () => Action<string> : (payload: SecondArgument<Handler>) =>
|
|
6
|
+
declare type ActionCreator<Handler extends ActionHandler<any, any>> = undefined extends SecondArgument<Handler> ? () => Action<string> : (payload: SecondArgument<Handler>) => Action<string> & {
|
|
7
7
|
payload: SecondArgument<Handler>;
|
|
8
|
-
}
|
|
8
|
+
};
|
|
9
9
|
|
|
10
10
|
declare type ActionCreatorMap<Actions extends ActionMap<any>> = {
|
|
11
11
|
[name in keyof Actions]: ActionCreator<Actions[name]>;
|
|
@@ -17,7 +17,7 @@ declare type ActionMap<BlockState> = {
|
|
|
17
17
|
[action: string]: ActionHandler<BlockState, any>;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
export declare
|
|
20
|
+
export declare const createReduxBlock: <GlobalState, ExtraArgument = undefined>() => <Name extends keyof GlobalState & string, Actions extends ActionMap<GlobalState[Name]>, Effects extends EffectsMap<GlobalState, ExtraArgument>>({ name, initial, actions, effects, }: {
|
|
21
21
|
name: Name;
|
|
22
22
|
initial: GlobalState[Name];
|
|
23
23
|
actions: Actions;
|
|
@@ -31,7 +31,7 @@ export declare function createReduxBlock<GlobalState, ExtraArgument = undefined>
|
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
declare type EffectsCreatorMap<GlobalState, ExtraArgument, Map extends EffectsMap<GlobalState, ExtraArgument>> = {
|
|
34
|
-
[key in keyof ReturnType<Map>]:
|
|
34
|
+
[key in keyof ReturnType<Map>]: undefined extends FirstArgument<ReturnType<Map>[key]> ? () => Action : (payload: FirstArgument<ReturnType<Map>[key]>) => Action;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
declare type EffectsMap<GlobalState, ExtraArgument> = (dispatch: Dispatch, getState: () => GlobalState) => {
|
package/build/redux-sacala.js
CHANGED
|
@@ -1,56 +1,47 @@
|
|
|
1
|
-
|
|
1
|
+
const u = (e) => {
|
|
2
2
|
const r = {};
|
|
3
|
-
for (const
|
|
4
|
-
r[
|
|
3
|
+
for (const c in e)
|
|
4
|
+
r[c] = e[c].bind(e);
|
|
5
5
|
return r;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return (r) => ({ type: e, payload: r });
|
|
18
|
-
}
|
|
19
|
-
function C(e, r, t) {
|
|
20
|
-
const c = a(e + "/", f(t));
|
|
21
|
-
return (n = r, u) => {
|
|
22
|
-
if (u && u.type) {
|
|
23
|
-
const o = c[u.type];
|
|
24
|
-
return o ? o(n, u.payload) : n;
|
|
6
|
+
}, a = (e, r) => {
|
|
7
|
+
const c = {};
|
|
8
|
+
for (const n in r)
|
|
9
|
+
c[e + n] = r[n];
|
|
10
|
+
return c;
|
|
11
|
+
}, l = (e) => (r) => r === void 0 ? { type: e } : { type: e, payload: r }, p = (e) => (r) => ({ type: e, payload: r }), f = (e, r, c) => {
|
|
12
|
+
const n = a(e + "/", u(c));
|
|
13
|
+
return (o = r, s) => {
|
|
14
|
+
if (s && s.type) {
|
|
15
|
+
const t = n[s.type];
|
|
16
|
+
return t ? t(o, s.payload) : o;
|
|
25
17
|
} else
|
|
26
|
-
return
|
|
18
|
+
return o;
|
|
27
19
|
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
function s() {
|
|
20
|
+
}, h = (e, r) => ((c) => (n) => {
|
|
21
|
+
const o = a(e + "/", u(r(n.dispatch, n.getState)));
|
|
22
|
+
return (s) => (t) => {
|
|
23
|
+
t && Object.prototype.hasOwnProperty.call(o, t.type) ? o[t.type](t.payload, c) : s(t);
|
|
24
|
+
};
|
|
25
|
+
}), i = () => {
|
|
38
26
|
throw new Error("Can't have access to 'dispatch' and 'getState' during initialization");
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
27
|
+
}, y = () => ({
|
|
28
|
+
name: e,
|
|
29
|
+
initial: r,
|
|
30
|
+
actions: c,
|
|
31
|
+
effects: n
|
|
32
|
+
}) => {
|
|
33
|
+
const o = Object.keys(c).reduce((t, d) => (t[d] = l(`${e}/${d}`), t), {}), s = Object.keys(n ? n(i, i) : {}).reduce((t, d) => (t[d] = p(`${e}/${d}`), t), {});
|
|
34
|
+
return {
|
|
35
|
+
name: e,
|
|
36
|
+
reducer: f(e, r, c),
|
|
37
|
+
createMiddleware: n ? h(e, n) : (() => (t) => (d) => d),
|
|
38
|
+
actions: {
|
|
39
|
+
...o,
|
|
40
|
+
...s
|
|
41
|
+
}
|
|
52
42
|
};
|
|
53
|
-
}
|
|
43
|
+
};
|
|
54
44
|
export {
|
|
55
45
|
y as createReduxBlock
|
|
56
46
|
};
|
|
47
|
+
//# sourceMappingURL=redux-sacala.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redux-sacala.js","sources":["../src/redux-sacala.ts"],"sourcesContent":["import { Dispatch, Action, Reducer, Middleware, AnyAction, MiddlewareAPI } from \"redux\";\n\ntype UnknownToUndefined<T> = unknown extends T ? undefined : T;\n\ntype FirstArgument<F> = F extends (arg1: infer U, ...args: any[]) => any ? UnknownToUndefined<U> : undefined;\ntype SecondArgument<F> = F extends (arg1: any, arg2: infer U, ...args: any[]) => any\n ? UnknownToUndefined<U>\n : undefined;\n\nconst bindAll = <T extends { [key: string]: Function }>(map: T): T => {\n const result = {} as any as T;\n for (const i in map) {\n result[i] = map[i].bind(map);\n }\n return result;\n};\n\nconst appendPrefix = <T>(prefix: string, map: { [key: string]: T }) => {\n const r: { [key: string]: any } = {};\n for (const i in map) {\n r[prefix + i] = map[i];\n }\n return r;\n};\n\n// Input\ntype ActionHandler<BlockState, Payload> = (state: BlockState, payload: Payload) => BlockState;\ntype ActionMap<BlockState> = { [action: string]: ActionHandler<BlockState, any> };\ntype EffectsMap<GlobalState, ExtraArgument> = (\n dispatch: Dispatch,\n getState: () => GlobalState,\n) => { [effect: string]: (payload: any, extraArgument: ExtraArgument) => any };\n\n// Output\ntype ActionCreator<Handler extends ActionHandler<any, any>> =\n undefined extends SecondArgument<Handler>\n ? () => Action<string>\n : (payload: SecondArgument<Handler>) => Action<string> & { payload: SecondArgument<Handler> };\n\ntype ActionCreatorMap<Actions extends ActionMap<any>> = {\n [name in keyof Actions]: ActionCreator<Actions[name]>;\n};\n\ntype EffectsCreatorMap<GlobalState, ExtraArgument, Map extends EffectsMap<GlobalState, ExtraArgument>> = {\n [key in keyof ReturnType<Map>]: undefined extends FirstArgument<ReturnType<Map>[key]>\n ? () => Action\n : (payload: FirstArgument<ReturnType<Map>[key]>) => Action;\n};\n\n// Transformation\nconst createActionCreator = (type: string) => (payload?: any) => (payload === undefined ? { type } : { type, payload });\nconst createEffectCreator = (type: string) => (payload: any) => ({ type, payload });\n\nconst createReducer = <BlockState>(prefix: string, initial: BlockState, actionMap: ActionMap<BlockState>): Reducer => {\n const actions: ActionMap<BlockState> = appendPrefix(prefix + \"/\", bindAll(actionMap));\n return (state: BlockState = initial, action?: AnyAction) => {\n if (action && action.type) {\n const handler: (state: BlockState, payload?: any) => BlockState = actions[action.type];\n if (handler) {\n return handler(state, action.payload);\n } else {\n return state;\n }\n } else {\n return state;\n }\n };\n};\n\ntype MiddlewareCreator<T> = T extends undefined ? () => Middleware : (argument: T) => Middleware;\n\nconst createMiddlewareCreator = <GlobalState, ExtraArgument>(\n prefix: string,\n effectsMap: EffectsMap<GlobalState, ExtraArgument>,\n): MiddlewareCreator<ExtraArgument> =>\n ((argument: ExtraArgument) => (store: MiddlewareAPI) => {\n const effects = appendPrefix(prefix + \"/\", bindAll(effectsMap(store.dispatch, store.getState)));\n return (next: Dispatch) => (action: Action<string> & { payload: any[] }) => {\n if (action && Object.prototype.hasOwnProperty.call(effects, action.type)) {\n effects[action.type](action.payload, argument);\n } else {\n next(action);\n }\n };\n }) as MiddlewareCreator<ExtraArgument>;\n\nconst fail = (): never => {\n throw new Error(\"Can't have access to 'dispatch' and 'getState' during initialization\");\n};\n\nexport const createReduxBlock =\n <GlobalState, ExtraArgument = undefined>() =>\n <\n Name extends keyof GlobalState & string,\n Actions extends ActionMap<GlobalState[Name]>,\n Effects extends EffectsMap<GlobalState, ExtraArgument>,\n >({\n name,\n initial,\n actions,\n effects,\n }: {\n name: Name;\n initial: GlobalState[Name];\n actions: Actions;\n effects?: Effects;\n }): {\n name: Name;\n reducer: Reducer<GlobalState[Name]>;\n actions: ActionCreatorMap<Actions> & EffectsCreatorMap<GlobalState, ExtraArgument, Effects>;\n } & ({} extends ReturnType<Effects> ? {} : { createMiddleware: MiddlewareCreator<ExtraArgument> }) => {\n const actionCreators = Object.keys(actions).reduce((r, key) => {\n r[key] = createActionCreator(`${name}/${key}`);\n return r;\n }, {} as any);\n const effectCreators = Object.keys(effects ? effects(fail, fail) : {}).reduce((r, key) => {\n r[key] = createEffectCreator(`${name}/${key}`);\n return r;\n }, {} as any);\n\n return {\n name,\n reducer: createReducer(name as string, initial, actions),\n createMiddleware: effects\n ? createMiddlewareCreator<GlobalState, ExtraArgument>(name as string, effects)\n : ((() => (_: MiddlewareAPI) => (next: Dispatch) => next) as MiddlewareCreator<ExtraArgument>),\n actions: {\n ...actionCreators,\n ...effectCreators,\n },\n };\n };\n"],"names":["bindAll","map","result","i","appendPrefix","prefix","r","createActionCreator","type","payload","createEffectCreator","createReducer","initial","actionMap","actions","state","action","handler","createMiddlewareCreator","effectsMap","argument","store","effects","next","fail","createReduxBlock","name","act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I,MAAM,sEAAsE;AAC1F,GAEaC,IACT,MACA,CAIE;AAAA,EACE,MAAAC;AAAA,EACA,SAAAd;AAAA,EACA,SAAAE;AAAA,EACA,SAAAQ;AACJ,MASsG;AAClG,QAAMK,IAAiB,OAAO,KAAKb,CAAO,EAAE,OAAO,CAACR,GAAGsB,OACnDtB,EAAEsB,CAAG,IAAIrB,EAAoB,GAAGmB,CAAI,IAAIE,CAAG,EAAE,GACtCtB,IACR,CAAA,CAAS,GACNuB,IAAiB,OAAO,KAAKP,IAAUA,EAAQE,GAAMA,CAAI,IAAI,CAAA,CAAE,EAAE,OAAO,CAAClB,GAAGsB,OAC9EtB,EAAEsB,CAAG,IAAIlB,EAAoB,GAAGgB,CAAI,IAAIE,CAAG,EAAE,GACtCtB,IACR,CAAA,CAAS;AAEZ,SAAO;AAAA,IACH,MAAAoB;AAAA,IACA,SAASf,EAAce,GAAgBd,GAASE,CAAO;AAAA,IACvD,kBAAkBQ,IACZJ,EAAoDQ,GAAgBJ,CAAO,KACzE,MAAM,CAACQ,MAAqB,CAACP,MAAmBA;AAAA,IACxD,SAAS;AAAA,MACL,GAAGI;AAAA,MACH,GAAGE;AAAA,IAAA;AAAA,EACP;AAER;"}
|
package/package.json
CHANGED
package/.idea/modules.xml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ProjectModuleManager">
|
|
4
|
-
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/redux-sacala.iml" filepath="$PROJECT_DIR$/.idea/redux-sacala.iml" />
|
|
6
|
-
</modules>
|
|
7
|
-
</component>
|
|
8
|
-
</project>
|
package/.idea/prettier.xml
DELETED
package/.idea/redux-sacala.iml
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="WEB_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager">
|
|
4
|
-
<content url="file://$MODULE_DIR$">
|
|
5
|
-
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
|
6
|
-
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
|
7
|
-
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
|
8
|
-
<excludeFolder url="file://$MODULE_DIR$/build" />
|
|
9
|
-
</content>
|
|
10
|
-
<orderEntry type="inheritedJdk" />
|
|
11
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
12
|
-
</component>
|
|
13
|
-
</module>
|
package/.idea/vcs.xml
DELETED
package/.idea/webResources.xml
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="WebResourcesPaths">
|
|
4
|
-
<contentEntries>
|
|
5
|
-
<entry url="file://$PROJECT_DIR$">
|
|
6
|
-
<entryData>
|
|
7
|
-
<resourceRoots>
|
|
8
|
-
<path value="file://$PROJECT_DIR$/src" />
|
|
9
|
-
</resourceRoots>
|
|
10
|
-
</entryData>
|
|
11
|
-
</entry>
|
|
12
|
-
</contentEntries>
|
|
13
|
-
</component>
|
|
14
|
-
</project>
|
package/.prettierignore
DELETED
package/.prettierrc
DELETED
package/eslint.config.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import eslint from "@eslint/js";
|
|
2
|
-
import tseslint from "typescript-eslint";
|
|
3
|
-
import prettierConfig from "eslint-config-prettier";
|
|
4
|
-
|
|
5
|
-
export default tseslint.config(
|
|
6
|
-
eslint.configs.recommended,
|
|
7
|
-
...tseslint.configs.recommended,
|
|
8
|
-
prettierConfig,
|
|
9
|
-
{
|
|
10
|
-
rules: {
|
|
11
|
-
"prefer-arrow-callback": "error",
|
|
12
|
-
"arrow-body-style": ["error", "as-needed"],
|
|
13
|
-
"func-style": ["error", "expression", { allowArrowFunctions: true }],
|
|
14
|
-
"@typescript-eslint/no-explicit-any": "off",
|
|
15
|
-
"@typescript-eslint/no-unsafe-function-type": "off",
|
|
16
|
-
"@typescript-eslint/no-empty-object-type": "off",
|
|
17
|
-
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
ignores: ["build/", "node_modules/", "coverage/"],
|
|
22
|
-
},
|
|
23
|
-
);
|
package/src/redux-sacala.spec.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { applyMiddleware, combineReducers, createStore } from "redux";
|
|
2
|
-
import { createReduxBlock } from "./redux-sacala";
|
|
3
|
-
|
|
4
|
-
interface LocalState {
|
|
5
|
-
count: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
interface MyState {
|
|
9
|
-
local: LocalState;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const {
|
|
13
|
-
actions: local,
|
|
14
|
-
reducer: localReducer,
|
|
15
|
-
createMiddleware: createLocalMiddleware,
|
|
16
|
-
} = createReduxBlock<MyState, number>()({
|
|
17
|
-
name: "local",
|
|
18
|
-
initial: { count: 0 },
|
|
19
|
-
actions: {
|
|
20
|
-
inc(state) {
|
|
21
|
-
return { count: state.count + 1 };
|
|
22
|
-
},
|
|
23
|
-
set(_, count: number) {
|
|
24
|
-
return { count };
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
effects: (dispatch) => ({
|
|
28
|
-
incEffect() {
|
|
29
|
-
dispatch(local.inc());
|
|
30
|
-
},
|
|
31
|
-
}),
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const createMyStore = () =>
|
|
35
|
-
createStore(
|
|
36
|
-
combineReducers({
|
|
37
|
-
local: localReducer,
|
|
38
|
-
}),
|
|
39
|
-
applyMiddleware(createLocalMiddleware(100)),
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
describe("Store with reducer and middleware", () => {
|
|
43
|
-
it("Should be updated on action without payload", () => {
|
|
44
|
-
const store = createMyStore();
|
|
45
|
-
store.dispatch(local.inc());
|
|
46
|
-
store.dispatch(local.inc());
|
|
47
|
-
expect(store.getState()).toEqual({ local: { count: 2 } });
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("Should be updated on action with payload", () => {
|
|
51
|
-
const store = createMyStore();
|
|
52
|
-
store.dispatch(local.set(12));
|
|
53
|
-
expect(store.getState()).toEqual({ local: { count: 12 } });
|
|
54
|
-
});
|
|
55
|
-
});
|
package/src/redux-sacala.ts
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { Dispatch, Action, Reducer, Middleware, AnyAction, MiddlewareAPI } from "redux";
|
|
2
|
-
|
|
3
|
-
type UnknownToUndefined<T> = unknown extends T ? undefined : T;
|
|
4
|
-
|
|
5
|
-
type FirstArgument<F> = F extends (arg1: infer U, ...args: any[]) => any ? UnknownToUndefined<U> : undefined;
|
|
6
|
-
type SecondArgument<F> = F extends (arg1: any, arg2: infer U, ...args: any[]) => any
|
|
7
|
-
? UnknownToUndefined<U>
|
|
8
|
-
: undefined;
|
|
9
|
-
|
|
10
|
-
const bindAll = <T extends { [key: string]: Function }>(map: T): T => {
|
|
11
|
-
const result = {} as any as T;
|
|
12
|
-
for (const i in map) {
|
|
13
|
-
result[i] = map[i].bind(map);
|
|
14
|
-
}
|
|
15
|
-
return result;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const appendPrefix = <T>(prefix: string, map: { [key: string]: T }) => {
|
|
19
|
-
const r: { [key: string]: any } = {};
|
|
20
|
-
for (const i in map) {
|
|
21
|
-
r[prefix + i] = map[i];
|
|
22
|
-
}
|
|
23
|
-
return r;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// Input
|
|
27
|
-
type ActionHandler<BlockState, Payload> = (state: BlockState, payload: Payload) => BlockState;
|
|
28
|
-
type ActionMap<BlockState> = { [action: string]: ActionHandler<BlockState, any> };
|
|
29
|
-
type EffectsMap<GlobalState, ExtraArgument> = (
|
|
30
|
-
dispatch: Dispatch,
|
|
31
|
-
getState: () => GlobalState,
|
|
32
|
-
) => { [effect: string]: (payload: any, extraArgument: ExtraArgument) => any };
|
|
33
|
-
|
|
34
|
-
// Output
|
|
35
|
-
type ActionCreator<Handler extends ActionHandler<any, any>> =
|
|
36
|
-
undefined extends SecondArgument<Handler>
|
|
37
|
-
? () => Action<string>
|
|
38
|
-
: (payload: SecondArgument<Handler>) => Action<string> & { payload: SecondArgument<Handler> };
|
|
39
|
-
|
|
40
|
-
type ActionCreatorMap<Actions extends ActionMap<any>> = {
|
|
41
|
-
[name in keyof Actions]: ActionCreator<Actions[name]>;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
type EffectsCreatorMap<GlobalState, ExtraArgument, Map extends EffectsMap<GlobalState, ExtraArgument>> = {
|
|
45
|
-
[key in keyof ReturnType<Map>]: undefined extends FirstArgument<ReturnType<Map>[key]>
|
|
46
|
-
? () => Action
|
|
47
|
-
: (payload: FirstArgument<ReturnType<Map>[key]>) => Action;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// Transformation
|
|
51
|
-
const createActionCreator = (type: string) => (payload?: any) => (payload === undefined ? { type } : { type, payload });
|
|
52
|
-
const createEffectCreator = (type: string) => (payload: any) => ({ type, payload });
|
|
53
|
-
|
|
54
|
-
const createReducer = <BlockState>(prefix: string, initial: BlockState, actionMap: ActionMap<BlockState>): Reducer => {
|
|
55
|
-
const actions: ActionMap<BlockState> = appendPrefix(prefix + "/", bindAll(actionMap));
|
|
56
|
-
return (state: BlockState = initial, action?: AnyAction) => {
|
|
57
|
-
if (action && action.type) {
|
|
58
|
-
const handler: (state: BlockState, payload?: any) => BlockState = actions[action.type];
|
|
59
|
-
if (handler) {
|
|
60
|
-
return handler(state, action.payload);
|
|
61
|
-
} else {
|
|
62
|
-
return state;
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
return state;
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
type MiddlewareCreator<T> = T extends undefined ? () => Middleware : (argument: T) => Middleware;
|
|
71
|
-
|
|
72
|
-
const createMiddlewareCreator = <GlobalState, ExtraArgument>(
|
|
73
|
-
prefix: string,
|
|
74
|
-
effectsMap: EffectsMap<GlobalState, ExtraArgument>,
|
|
75
|
-
): MiddlewareCreator<ExtraArgument> =>
|
|
76
|
-
((argument: ExtraArgument) => (store: MiddlewareAPI) => {
|
|
77
|
-
const effects = appendPrefix(prefix + "/", bindAll(effectsMap(store.dispatch, store.getState)));
|
|
78
|
-
return (next: Dispatch) => (action: Action<string> & { payload: any[] }) => {
|
|
79
|
-
if (action && Object.prototype.hasOwnProperty.call(effects, action.type)) {
|
|
80
|
-
effects[action.type](action.payload, argument);
|
|
81
|
-
} else {
|
|
82
|
-
next(action);
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
}) as MiddlewareCreator<ExtraArgument>;
|
|
86
|
-
|
|
87
|
-
const fail = (): never => {
|
|
88
|
-
throw new Error("Can't have access to 'dispatch' and 'getState' during initialization");
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export const createReduxBlock =
|
|
92
|
-
<GlobalState, ExtraArgument = undefined>() =>
|
|
93
|
-
<
|
|
94
|
-
Name extends keyof GlobalState & string,
|
|
95
|
-
Actions extends ActionMap<GlobalState[Name]>,
|
|
96
|
-
Effects extends EffectsMap<GlobalState, ExtraArgument>,
|
|
97
|
-
>({
|
|
98
|
-
name,
|
|
99
|
-
initial,
|
|
100
|
-
actions,
|
|
101
|
-
effects,
|
|
102
|
-
}: {
|
|
103
|
-
name: Name;
|
|
104
|
-
initial: GlobalState[Name];
|
|
105
|
-
actions: Actions;
|
|
106
|
-
effects?: Effects;
|
|
107
|
-
}): {
|
|
108
|
-
name: Name;
|
|
109
|
-
reducer: Reducer<GlobalState[Name]>;
|
|
110
|
-
actions: ActionCreatorMap<Actions> & EffectsCreatorMap<GlobalState, ExtraArgument, Effects>;
|
|
111
|
-
} & ({} extends ReturnType<Effects> ? {} : { createMiddleware: MiddlewareCreator<ExtraArgument> }) => {
|
|
112
|
-
const actionCreators = Object.keys(actions).reduce((r, key) => {
|
|
113
|
-
r[key] = createActionCreator(`${name}/${key}`);
|
|
114
|
-
return r;
|
|
115
|
-
}, {} as any);
|
|
116
|
-
const effectCreators = Object.keys(effects ? effects(fail, fail) : {}).reduce((r, key) => {
|
|
117
|
-
r[key] = createEffectCreator(`${name}/${key}`);
|
|
118
|
-
return r;
|
|
119
|
-
}, {} as any);
|
|
120
|
-
|
|
121
|
-
return {
|
|
122
|
-
name,
|
|
123
|
-
reducer: createReducer(name as string, initial, actions),
|
|
124
|
-
createMiddleware: effects
|
|
125
|
-
? createMiddlewareCreator<GlobalState, ExtraArgument>(name as string, effects)
|
|
126
|
-
: ((() => (_: MiddlewareAPI) => (next: Dispatch) => next) as MiddlewareCreator<ExtraArgument>),
|
|
127
|
-
actions: {
|
|
128
|
-
...actionCreators,
|
|
129
|
-
...effectCreators,
|
|
130
|
-
},
|
|
131
|
-
};
|
|
132
|
-
};
|
package/tsconfig.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"strict": true,
|
|
4
|
-
"noImplicitAny": true,
|
|
5
|
-
"moduleResolution": "bundler",
|
|
6
|
-
"module": "ESNext",
|
|
7
|
-
"outDir": "build",
|
|
8
|
-
"sourceMap": true,
|
|
9
|
-
"declaration": true,
|
|
10
|
-
"target": "ESNext",
|
|
11
|
-
"types": ["vitest/globals"]
|
|
12
|
-
},
|
|
13
|
-
"include": ["src/*.ts"]
|
|
14
|
-
}
|
package/vite.config.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "vitest/config";
|
|
2
|
-
import dts from "vite-plugin-dts";
|
|
3
|
-
import { resolve } from "path";
|
|
4
|
-
|
|
5
|
-
export default defineConfig({
|
|
6
|
-
build: {
|
|
7
|
-
lib: {
|
|
8
|
-
entry: resolve(__dirname, "src/redux-sacala.ts"),
|
|
9
|
-
name: "ReduxSacala",
|
|
10
|
-
fileName: "redux-sacala",
|
|
11
|
-
formats: ["es", "cjs"],
|
|
12
|
-
},
|
|
13
|
-
outDir: "build",
|
|
14
|
-
rollupOptions: {
|
|
15
|
-
external: ["redux"],
|
|
16
|
-
output: {
|
|
17
|
-
globals: {
|
|
18
|
-
redux: "Redux",
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
plugins: [dts({ rollupTypes: true })],
|
|
24
|
-
test: {
|
|
25
|
-
globals: true,
|
|
26
|
-
environment: "node",
|
|
27
|
-
exclude: ["**/node_modules/**", "**/build/**"],
|
|
28
|
-
},
|
|
29
|
-
});
|