redux-astroglide 0.1.21 → 0.1.24
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/CHANGELOG.md +4 -0
- package/dist/index.js +98 -16
- package/dist/{index.es.js → index.mjs} +98 -16
- package/dist/index.umd.js +474 -42
- package/dist/selectors/index.umd.js +1573 -1223
- package/dist/types/astroglide.d.ts +98 -17
- package/dist/types/index.d.ts +1 -0
- package/package.json +46 -7
- package/dist/types/plugins/persist/__tests__/persist.test.d.ts +0 -1
- /package/dist/plugins/{index.es.js → index.mjs} +0 -0
- /package/dist/plugins/persist/{index.es.js → index.mjs} +0 -0
- /package/dist/plugins/set/{index.es.js → index.mjs} +0 -0
- /package/dist/plugins/type/{index.es.js → index.mjs} +0 -0
- /package/dist/selectors/{index.es.js → index.mjs} +0 -0
|
@@ -1,20 +1,101 @@
|
|
|
1
|
-
import
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { injectMiddleware } from "redux-injectable-middleware";
|
|
2
|
+
import type { Slice, Reducer, Action, Dispatch, Store, CaseReducer, PayloadAction } from "@reduxjs/toolkit";
|
|
3
|
+
/** Capitalize first letter of a string type */
|
|
4
|
+
type Capitalize<S extends string> = S extends `${infer F}${infer R}` ? `${Uppercase<F>}${R}` : S;
|
|
5
|
+
/** Return type for hooks - [value, setter, extras] */
|
|
6
|
+
type HookReturn<T> = [
|
|
7
|
+
T,
|
|
8
|
+
(value: T | ((prev: T) => T)) => void,
|
|
9
|
+
{
|
|
10
|
+
dispatch: Dispatch;
|
|
11
|
+
toggle?: T extends boolean ? () => void : never;
|
|
12
|
+
}
|
|
13
|
+
];
|
|
14
|
+
/** A hook with static methods for non-component usage */
|
|
15
|
+
interface SliceHook<T> {
|
|
16
|
+
(setterCb?: (value: T) => T): [T, (value: T | ((prev: T) => T)) => void];
|
|
17
|
+
select: (state: any) => T;
|
|
18
|
+
update: (value: T | ((prev: T) => T)) => Action;
|
|
19
|
+
}
|
|
20
|
+
/** Generate hook types from initial state - creates useFieldName for each field */
|
|
21
|
+
type GeneratedHooks<S> = {
|
|
22
|
+
[K in keyof S as `use${Capitalize<string & K>}`]: SliceHook<S[K]>;
|
|
5
23
|
};
|
|
6
|
-
|
|
7
|
-
|
|
24
|
+
/** Domain hook for the entire slice state */
|
|
25
|
+
interface SliceDomainHook<S> {
|
|
26
|
+
(): [S, (value: Partial<S> | ((prev: S) => Partial<S>)) => void, (value: S) => void];
|
|
27
|
+
select: (state: any) => S;
|
|
28
|
+
update: (value: Partial<S> | ((prev: S) => Partial<S>)) => Action;
|
|
29
|
+
}
|
|
30
|
+
/** Generate selector types from initial state - creates selectFieldName for each field */
|
|
31
|
+
type GeneratedSelectors<S> = {
|
|
32
|
+
[K in keyof S as `select${Capitalize<string & K>}`]: (state: any) => S[K];
|
|
33
|
+
} & {
|
|
34
|
+
selectDomain: (state: any) => S;
|
|
35
|
+
};
|
|
36
|
+
/** Generate setter action types from initial state - creates setFieldName for each field */
|
|
37
|
+
type GeneratedSetterActions<S> = {
|
|
38
|
+
[K in keyof S as `set${Capitalize<string & K>}`]: (payload: S[K]) => PayloadAction<S[K]>;
|
|
39
|
+
};
|
|
40
|
+
/** Slice-level setter action */
|
|
41
|
+
type SliceSetterAction<S> = (payload: Partial<S>) => PayloadAction<Partial<S>>;
|
|
42
|
+
/** Extract action types from custom reducers */
|
|
43
|
+
type CustomReducerActions<R> = {
|
|
44
|
+
[K in keyof R]: R[K] extends CaseReducer<any, infer A> ? A extends PayloadAction<infer P> ? (payload: P) => PayloadAction<P> : () => Action<string> : never;
|
|
45
|
+
};
|
|
46
|
+
/** Extended slice with hooks, selectors, and properly typed actions */
|
|
47
|
+
interface ExtendedSlice<S extends Record<string, any> = Record<string, any>, CustomReducers extends Record<string, CaseReducer<S, any>> = {}> extends Omit<Slice<S>, 'actions'> {
|
|
48
|
+
name: string;
|
|
49
|
+
reducer: Reducer<S>;
|
|
50
|
+
actions: GeneratedSetterActions<S> & CustomReducerActions<CustomReducers> & {
|
|
51
|
+
setSlice: SliceSetterAction<S>;
|
|
52
|
+
__override__slice__caution: (payload: S) => PayloadAction<S>;
|
|
53
|
+
};
|
|
54
|
+
selectors: GeneratedSelectors<S>;
|
|
55
|
+
hooks: GeneratedHooks<S> & {
|
|
56
|
+
useSlice: SliceDomainHook<S>;
|
|
57
|
+
};
|
|
58
|
+
getInitialState: () => S;
|
|
59
|
+
}
|
|
60
|
+
/** Configuration options for the store - reducer is NOT required */
|
|
61
|
+
interface AstroglideConfigureOptions {
|
|
62
|
+
middleware?: any;
|
|
63
|
+
devTools?: boolean;
|
|
64
|
+
preloadedState?: any;
|
|
65
|
+
enhancers?: any;
|
|
66
|
+
[key: string]: any;
|
|
67
|
+
}
|
|
68
|
+
/** RTK-compatible configuration for custom reducers */
|
|
69
|
+
interface RtkConfig<S, R extends Record<string, CaseReducer<S, any>> = {}> {
|
|
70
|
+
reducers?: R;
|
|
71
|
+
extraReducers?: any;
|
|
72
|
+
selectors?: Record<string, (state: S) => any>;
|
|
73
|
+
}
|
|
74
|
+
/** Astroglide-specific configuration overrides */
|
|
75
|
+
interface AstroglideConfig {
|
|
76
|
+
}
|
|
77
|
+
/** Result returned from configure() */
|
|
78
|
+
interface ConfigureResult {
|
|
79
|
+
store: Store;
|
|
80
|
+
/** Create a slice with simple form: createSlice("name", initialState) */
|
|
81
|
+
createSlice<S extends Record<string, any>>(name: string, initialState: S): ExtendedSlice<S>;
|
|
82
|
+
/** Create a slice with RTK config: createSlice("name", initialState, { reducers }) */
|
|
83
|
+
createSlice<S extends Record<string, any>, R extends Record<string, CaseReducer<S, any>>>(name: string, initialState: S, rtkConfig: RtkConfig<S, R>): ExtendedSlice<S, R>;
|
|
84
|
+
/** Create a slice with RTK-compatible object form: createSlice({ name, initialState }) */
|
|
85
|
+
createSlice<S extends Record<string, any>>(config: {
|
|
8
86
|
name: string;
|
|
9
|
-
initialState:
|
|
10
|
-
}
|
|
11
|
-
|
|
87
|
+
initialState: S;
|
|
88
|
+
}): ExtendedSlice<S>;
|
|
89
|
+
/** Create a slice with RTK-compatible object form and reducers: createSlice({ name, initialState }, {}, { reducers }) */
|
|
90
|
+
createSlice<S extends Record<string, any>, R extends Record<string, CaseReducer<S, any>>>(config: {
|
|
12
91
|
name: string;
|
|
13
|
-
initialState:
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
92
|
+
initialState: S;
|
|
93
|
+
}, _unused: any, rtkConfig: RtkConfig<S, R>): ExtendedSlice<S, R>;
|
|
94
|
+
/** Alias for createSlice */
|
|
95
|
+
astroglide: ConfigureResult['createSlice'];
|
|
96
|
+
injectReducer: (key: string, reducer: Reducer) => void;
|
|
97
|
+
injectSlice: (slice: Slice | ExtendedSlice<any>) => void;
|
|
98
|
+
injectMiddleware: typeof injectMiddleware;
|
|
99
|
+
}
|
|
100
|
+
export declare const configure: ({ middleware, devTools, preloadedState, enhancers, ...staticReducers }?: AstroglideConfigureOptions) => ConfigureResult;
|
|
101
|
+
export type { ExtendedSlice, ConfigureResult, AstroglideConfigureOptions, RtkConfig, AstroglideConfig, SliceHook, SliceDomainHook, GeneratedHooks, GeneratedSelectors, GeneratedSetterActions, HookReturn, };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ import { configure } from "./astroglide";
|
|
|
2
2
|
export { createSelectorHook, createSelectorUpdateHook } from "./selectors";
|
|
3
3
|
export { configure };
|
|
4
4
|
export { plugins, addPlugin, addPlugins } from "./plugins/service";
|
|
5
|
+
export type { ExtendedSlice, ConfigureResult, AstroglideConfigureOptions, RtkConfig, AstroglideConfig, SliceHook, SliceDomainHook, GeneratedHooks, GeneratedSelectors, GeneratedSetterActions, HookReturn, } from "./astroglide";
|
|
5
6
|
export default configure;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "redux-astroglide",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.24",
|
|
4
4
|
"description": "Taking the pain out of redux state management",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"redux",
|
|
@@ -19,23 +19,61 @@
|
|
|
19
19
|
},
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"author": "Dustin Schultz <dmanke@gmail.com>",
|
|
22
|
+
"type": "commonjs",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/types/index.d.ts",
|
|
26
|
+
"import": "./dist/index.mjs",
|
|
27
|
+
"require": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./plugins": {
|
|
30
|
+
"types": "./dist/types/plugins/index.d.ts",
|
|
31
|
+
"import": "./dist/plugins/index.mjs",
|
|
32
|
+
"require": "./dist/plugins/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./plugins/set": {
|
|
35
|
+
"types": "./dist/types/plugins/set/index.d.ts",
|
|
36
|
+
"import": "./dist/plugins/set/index.mjs",
|
|
37
|
+
"require": "./dist/plugins/set/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./plugins/type": {
|
|
40
|
+
"types": "./dist/types/plugins/type/index.d.ts",
|
|
41
|
+
"import": "./dist/plugins/type/index.mjs",
|
|
42
|
+
"require": "./dist/plugins/type/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./plugins/persist": {
|
|
45
|
+
"types": "./dist/types/plugins/persist/index.d.ts",
|
|
46
|
+
"import": "./dist/plugins/persist/index.mjs",
|
|
47
|
+
"require": "./dist/plugins/persist/index.js"
|
|
48
|
+
},
|
|
49
|
+
"./selectors": {
|
|
50
|
+
"types": "./dist/types/selectors/index.d.ts",
|
|
51
|
+
"import": "./dist/selectors/index.mjs",
|
|
52
|
+
"require": "./dist/selectors/index.js"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
22
55
|
"main": "./dist/index.js",
|
|
23
|
-
"module": "./dist/index.
|
|
56
|
+
"module": "./dist/index.mjs",
|
|
24
57
|
"browser": "./dist/index.umd.js",
|
|
25
|
-
"types": "./dist/types",
|
|
58
|
+
"types": "./dist/types/index.d.ts",
|
|
26
59
|
"files": [
|
|
27
|
-
"dist
|
|
28
|
-
"plugins/*"
|
|
60
|
+
"dist"
|
|
29
61
|
],
|
|
30
62
|
"scripts": {
|
|
31
63
|
"start": "BUILD_ENV=dev npm run build:js -- --watch",
|
|
32
|
-
"build": "rimraf dist &&
|
|
64
|
+
"build": "rimraf dist && npm run build:js && npm run build:types",
|
|
33
65
|
"build:js": "rollup -c",
|
|
34
66
|
"build:types": "tsc --emitDeclarationOnly",
|
|
35
67
|
"prepare": "husky install",
|
|
36
68
|
"test": "jest",
|
|
37
69
|
"test:watch": "jest --watch",
|
|
38
|
-
"test:coverage": "jest --coverage"
|
|
70
|
+
"test:coverage": "jest --coverage",
|
|
71
|
+
"sync:exports": "node scripts/sync-exports.js",
|
|
72
|
+
"validate:exports": "node scripts/validate-exports.js",
|
|
73
|
+
"test:exports": "node scripts/test-exports.js",
|
|
74
|
+
"lint:package": "publint",
|
|
75
|
+
"prepack": "npm run validate:exports && npm run lint:package",
|
|
76
|
+
"prepublishOnly": "npm run build && npm run test:exports"
|
|
39
77
|
},
|
|
40
78
|
"lint-staged": {
|
|
41
79
|
"*.{js,jsx,ts,tsx}": [
|
|
@@ -81,6 +119,7 @@
|
|
|
81
119
|
"lint-staged": "^12.4.2",
|
|
82
120
|
"prettier": "^2.6.2",
|
|
83
121
|
"prop-types": "^15.8.1",
|
|
122
|
+
"publint": "^0.2.0",
|
|
84
123
|
"rimraf": "^3.0.2",
|
|
85
124
|
"rollup": "^2.74.1",
|
|
86
125
|
"rollup-plugin-terser": "^7.0.2",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|