@dxyl/utils 1.1.6 → 1.1.9
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/dist/index.es.js +13454 -8772
- package/dist/index.umd.js +47 -17
- package/lib/tapable/index.es.js +1283 -0
- package/lib/tapable/index.umd.js +1321 -0
- package/package.json +7 -2
- package/types/color/colord/src/index.d.ts +3 -3
- package/types/compose.d.ts +19 -0
- package/types/data/mobx.d.ts +2 -154
- package/types/data/redux/applyMiddleware.d.ts +40 -0
- package/types/data/redux/bindActionCreators.d.ts +27 -0
- package/types/data/redux/combineReducers.d.ts +20 -0
- package/types/data/redux/compose.d.ts +19 -0
- package/types/data/redux/createStore.d.ts +126 -0
- package/types/data/redux/index.d.ts +14 -0
- package/types/data/redux/types/actions.d.ts +64 -0
- package/types/data/redux/types/middleware.d.ts +23 -0
- package/types/data/redux/types/reducers.d.ts +71 -0
- package/types/data/redux/types/store.d.ts +190 -0
- package/types/data/redux/utils/actionTypes.d.ts +12 -0
- package/types/data/redux/utils/formatProdErrorMessage.d.ts +8 -0
- package/types/data/redux/utils/isAction.d.ts +2 -0
- package/types/data/redux/utils/isPlainObject.d.ts +5 -0
- package/types/data/redux/utils/kindOf.d.ts +2 -0
- package/types/data/redux/utils/symbol-observable.d.ts +7 -0
- package/types/data/redux/utils/warning.d.ts +6 -0
- package/types/events/Observable.d.ts +161 -28
- package/types/events/eventmitter.d.ts +3 -1
- package/types/index.d.ts +6 -0
- package/types/tapable/index.d.ts +125 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxyl/utils",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"description": "Collected many useful mathematical tools",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -14,7 +14,12 @@
|
|
|
14
14
|
"type": "module",
|
|
15
15
|
"types": "./types/index.d.ts",
|
|
16
16
|
"exports":{
|
|
17
|
-
|
|
17
|
+
".":{
|
|
18
|
+
"types":"./types/index.d.ts",
|
|
19
|
+
"import":"./dist/index.es.js",
|
|
20
|
+
"default":"./dist/index.umd.js"
|
|
21
|
+
},
|
|
22
|
+
"./lib/*":"./lib/*"
|
|
18
23
|
},
|
|
19
24
|
"files": [
|
|
20
25
|
"package.json",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { colord, Colord } from './colord';
|
|
2
|
-
export { extend, Plugin } from './extend';
|
|
1
|
+
export { colord, type Colord } from './colord';
|
|
2
|
+
export { extend, type Plugin } from './extend';
|
|
3
3
|
export { getFormat } from './parse';
|
|
4
4
|
export { random } from './random';
|
|
5
|
-
export { HslColor, HslaColor, HsvColor, HsvaColor, HwbColor, HwbaColor, LabColor, LabaColor, LchColor, LchaColor, RgbColor, RgbaColor, XyzColor, XyzaColor, AnyColor, } from './types';
|
|
5
|
+
export type { HslColor, HslaColor, HsvColor, HsvaColor, HwbColor, HwbaColor, LabColor, LabaColor, LchColor, LchaColor, RgbColor, RgbaColor, XyzColor, XyzaColor, AnyColor, } from './types';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type Func<T extends any[], R> = (...a: T) => R;
|
|
2
|
+
/**
|
|
3
|
+
* Composes single-argument functions from right to left. The rightmost
|
|
4
|
+
* function can take multiple arguments as it provides the signature for the
|
|
5
|
+
* resulting composite function.
|
|
6
|
+
*
|
|
7
|
+
* @param funcs The functions to compose.
|
|
8
|
+
* @returns A function obtained by composing the argument functions from right
|
|
9
|
+
* to left. For example, `compose(f, g, h)` is identical to doing
|
|
10
|
+
* `(...args) => f(g(h(...args)))`.
|
|
11
|
+
*/
|
|
12
|
+
export default function compose(): <R>(a: R) => R;
|
|
13
|
+
export default function compose<F extends Function>(f: F): F;
|
|
14
|
+
export default function compose<A, T extends any[], R>(f1: (a: A) => R, f2: Func<T, A>): Func<T, R>;
|
|
15
|
+
export default function compose<A, B, T extends any[], R>(f1: (b: B) => R, f2: (a: A) => B, f3: Func<T, A>): Func<T, R>;
|
|
16
|
+
export default function compose<A, B, C, T extends any[], R>(f1: (c: C) => R, f2: (b: B) => C, f3: (a: A) => B, f4: Func<T, A>): Func<T, R>;
|
|
17
|
+
export default function compose<R>(f1: (a: any) => R, ...funcs: Function[]): (...args: any[]) => R;
|
|
18
|
+
export default function compose<R>(...funcs: Function[]): (...args: any[]) => R;
|
|
19
|
+
export {};
|
package/types/data/mobx.d.ts
CHANGED
|
@@ -1,154 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
export class FlowCancellationError {
|
|
4
|
-
message: string;
|
|
5
|
-
}
|
|
6
|
-
export var ObservableMap: any;
|
|
7
|
-
export var ObservableSet: any;
|
|
8
|
-
export var Reaction: any;
|
|
9
|
-
declare function allowStateChanges(allowStateChanges: any, func: any): any;
|
|
10
|
-
export function runInAction(fn: any): any;
|
|
11
|
-
declare function allowStateReadsEnd(prev: any): void;
|
|
12
|
-
declare function allowStateReadsStart(allowStateReads: any): any;
|
|
13
|
-
declare function autoAction(arg1: any, arg2: any): any;
|
|
14
|
-
declare namespace autoAction {
|
|
15
|
-
let bound: any;
|
|
16
|
-
}
|
|
17
|
-
export function _endAction(runInfo: any): void;
|
|
18
|
-
declare function getAdministration(thing: any, property: any): any;
|
|
19
|
-
declare function getGlobalState(): any;
|
|
20
|
-
declare function interceptReads(thing: any, propOrHandler: any, handler: any): void | (() => void);
|
|
21
|
-
declare function isComputingDerivation(): boolean;
|
|
22
|
-
/**
|
|
23
|
-
* For testing purposes only; this will break the internal state of existing observables,
|
|
24
|
-
* but can be used to get back at a stable state after throwing errors
|
|
25
|
-
*/
|
|
26
|
-
declare function resetGlobalState(): void;
|
|
27
|
-
export function _startAction(actionName: any, canRunAsDerivation: any, scope: any, args: any): {
|
|
28
|
-
runAsAction_: boolean;
|
|
29
|
-
prevDerivation_: any;
|
|
30
|
-
prevAllowStateChanges_: any;
|
|
31
|
-
prevAllowStateReads_: any;
|
|
32
|
-
notifySpy_: boolean;
|
|
33
|
-
startTime_: number;
|
|
34
|
-
actionId_: number;
|
|
35
|
-
parentActionId_: number;
|
|
36
|
-
};
|
|
37
|
-
export function action(arg1: any, arg2: any): any;
|
|
38
|
-
export namespace action {
|
|
39
|
-
let bound_1: any;
|
|
40
|
-
export { bound_1 as bound };
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Creates a named reactive view and keeps it alive, so that the view is always
|
|
44
|
-
* updated if one of the dependencies changes, even when the view is not further used by something else.
|
|
45
|
-
* @param view The reactive view
|
|
46
|
-
* @returns disposer function, which can be used to stop the view from being updated in the future.
|
|
47
|
-
*/
|
|
48
|
-
export function autorun(view: any, opts: any): any;
|
|
49
|
-
export namespace comparer {
|
|
50
|
-
export { identityComparer as identity };
|
|
51
|
-
export { structuralComparer as structural };
|
|
52
|
-
export { defaultComparer as default };
|
|
53
|
-
export { shallowComparer as shallow };
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Decorator for class properties: @computed get value() { return expr; }.
|
|
57
|
-
* For legacy purposes also invokable as ES5 observable created: `computed(() => expr)`;
|
|
58
|
-
*/
|
|
59
|
-
export function computed(arg1: any, arg2: any): any;
|
|
60
|
-
export namespace computed {
|
|
61
|
-
let struct: any;
|
|
62
|
-
}
|
|
63
|
-
export function configure(options: any): void;
|
|
64
|
-
export function createAtom(name: any, onBecomeObservedHandler: any, onBecomeUnobservedHandler: any): any;
|
|
65
|
-
declare function apiDefineProperty(obj: any, key: any, descriptor: any): any;
|
|
66
|
-
export function entries(obj: any): any;
|
|
67
|
-
export function extendObservable(target: any, properties: any, annotations: any, options: any, ...args: any[]): any;
|
|
68
|
-
export var flow: ((arg1: any, arg2: any, ...args: any[]) => any) & {
|
|
69
|
-
annotationType_: any;
|
|
70
|
-
options_: any;
|
|
71
|
-
make_: typeof make_$2;
|
|
72
|
-
extend_: typeof extend_$2;
|
|
73
|
-
decorate_20223_: typeof decorate_20223_$2;
|
|
74
|
-
};
|
|
75
|
-
export function flowResult(result: any): any;
|
|
76
|
-
export function get(obj: any, key: any): any;
|
|
77
|
-
export function getAtom(thing: any, property: any): any;
|
|
78
|
-
export function getDebugName(thing: any, property: any): any;
|
|
79
|
-
export function getDependencyTree(thing: any, property: any): {
|
|
80
|
-
name: any;
|
|
81
|
-
};
|
|
82
|
-
export function getObserverTree(thing: any, property: any): {
|
|
83
|
-
name: any;
|
|
84
|
-
};
|
|
85
|
-
export function has(obj: any, key: any): any;
|
|
86
|
-
export function intercept(thing: any, propOrHandler: any, handler: any): any;
|
|
87
|
-
export function isAction(thing: any): boolean;
|
|
88
|
-
declare function isObservableValue(x: any): boolean;
|
|
89
|
-
export function isComputed(value: any, ...args: any[]): boolean | void;
|
|
90
|
-
export function isComputedProp(value: any, propName: any): boolean | void;
|
|
91
|
-
export function isFlow(fn: any): boolean;
|
|
92
|
-
export function isFlowCancellationError(error: any): error is FlowCancellationError;
|
|
93
|
-
export function isObservable(value: any, ...args: any[]): any;
|
|
94
|
-
export function isObservableArray(thing: any): boolean;
|
|
95
|
-
export function isObservableMap(x: any): boolean;
|
|
96
|
-
export function isObservableObject(thing: any): boolean;
|
|
97
|
-
export function isObservableProp(value: any, propName: any): any;
|
|
98
|
-
export function isObservableSet(x: any): boolean;
|
|
99
|
-
export function keys(obj: any): any;
|
|
100
|
-
export function makeAutoObservable(target: any, overrides: any, options: any): any;
|
|
101
|
-
export function makeObservable(target: any, annotations: any, options: any): any;
|
|
102
|
-
export var observable: typeof createObservable & {
|
|
103
|
-
box: (value: any, options: any) => any;
|
|
104
|
-
array: (initialValues: any, options: any) => any;
|
|
105
|
-
map: (initialValues: any, options: any) => any;
|
|
106
|
-
set: (initialValues: any, options: any) => any;
|
|
107
|
-
object: (props: any, decorators: any, options: any) => any;
|
|
108
|
-
ref: any;
|
|
109
|
-
shallow: any;
|
|
110
|
-
deep: any;
|
|
111
|
-
struct: any;
|
|
112
|
-
};
|
|
113
|
-
export function observe(thing: any, propOrCb: any, cbOrFire: any, fireImmediately: any): any;
|
|
114
|
-
export function onBecomeObserved(thing: any, arg2: any, arg3: any): () => void;
|
|
115
|
-
export function onBecomeUnobserved(thing: any, arg2: any, arg3: any): () => void;
|
|
116
|
-
export function onReactionError(handler: any): () => void;
|
|
117
|
-
export var override: any;
|
|
118
|
-
declare function apiOwnKeys(obj: any): any;
|
|
119
|
-
export function reaction(expression: any, effect: any, opts: any): any;
|
|
120
|
-
export function remove(obj: any, key: any): void;
|
|
121
|
-
export function set(obj: any, key: any, value: any, ...args: any[]): void;
|
|
122
|
-
export function spy(listener: any): (...args: any[]) => any;
|
|
123
|
-
/**
|
|
124
|
-
* Recursively converts an observable to it's non-observable native counterpart.
|
|
125
|
-
* It does NOT recurse into non-observables, these are left as they are, even if they contain observables.
|
|
126
|
-
* Computed and other non-enumerable properties are completely ignored.
|
|
127
|
-
* Complex scenarios require custom solution, eg implementing `toJSON` or using `serializr` lib.
|
|
128
|
-
*/
|
|
129
|
-
export function toJS(source: any, options: any): any;
|
|
130
|
-
export function trace(...args: any[]): void;
|
|
131
|
-
/**
|
|
132
|
-
* During a transaction no views are updated until the end of the transaction.
|
|
133
|
-
* The transaction will be run synchronously nonetheless.
|
|
134
|
-
*
|
|
135
|
-
* @param action a function that updates some reactive state
|
|
136
|
-
* @returns any value that was returned by the 'action' parameter.
|
|
137
|
-
*/
|
|
138
|
-
export function transaction(action: any, thisArg: any): any;
|
|
139
|
-
export function untracked(action: any): any;
|
|
140
|
-
export function values(obj: any): any;
|
|
141
|
-
export function when(predicate: any, arg1: any, arg2: any, ...args: any[]): any;
|
|
142
|
-
declare function identityComparer(a: any, b: any): boolean;
|
|
143
|
-
declare function structuralComparer(a: any, b: any): boolean;
|
|
144
|
-
declare function defaultComparer(a: any, b: any): boolean;
|
|
145
|
-
declare function shallowComparer(a: any, b: any): boolean;
|
|
146
|
-
declare function make_$2(adm: any, key: any, descriptor: any, source: any): 0 | 1 | 2;
|
|
147
|
-
declare function extend_$2(adm: any, key: any, descriptor: any, proxyTrap: any): any;
|
|
148
|
-
declare function decorate_20223_$2(mthd: any, context: any): any;
|
|
149
|
-
/**
|
|
150
|
-
* Turns an object, array or function into a reactive structure.
|
|
151
|
-
* @param v the value which should become observable.
|
|
152
|
-
*/
|
|
153
|
-
declare function createObservable(v: any, arg2: any, arg3: any): any;
|
|
154
|
-
export { allowStateChanges as _allowStateChanges, runInAction as _allowStateChangesInsideComputed, allowStateReadsEnd as _allowStateReadsEnd, allowStateReadsStart as _allowStateReadsStart, autoAction as _autoAction, getAdministration as _getAdministration, getGlobalState as _getGlobalState, interceptReads as _interceptReads, isComputingDerivation as _isComputingDerivation, resetGlobalState as _resetGlobalState, apiDefineProperty as defineProperty, isObservableValue as isBoxedObservable, apiOwnKeys as ownKeys };
|
|
1
|
+
export { IObservable, IDepTreeNode, Reaction, IReactionPublic, IReactionDisposer, untracked, IAtom, createAtom, spy, IComputedValue, IEqualsComparer, comparer, IEnhancer, IInterceptable, IInterceptor, IListenable, IObjectWillChange, IObjectDidChange, isObservableObject, IValueDidChange, IValueWillChange, IObservableValue, isObservableValue as isBoxedObservable, IObservableArray, IArrayWillChange, IArrayWillSplice, IArraySplice, IArrayUpdate, IArrayDidChange, isObservableArray, IKeyValueMap, ObservableMap, IMapEntries, IMapEntry, IMapWillChange, IMapDidChange, isObservableMap, IObservableMapInitialValues, ObservableSet, isObservableSet, ISetDidChange, ISetWillChange, IObservableSetInitialValues, transaction, observable, IObservableFactory, CreateObservableOptions, computed, IComputedFactory, isObservable, isObservableProp, isComputed, isComputedProp, extendObservable, observe, intercept, autorun, IAutorunOptions, reaction, IReactionOptions, when, IWhenOptions, action, isAction, runInAction, IActionFactory, keys, values, entries, set, remove, has, get, apiOwnKeys as ownKeys, apiDefineProperty as defineProperty, configure, onBecomeObserved, onBecomeUnobserved, flow, isFlow, flowResult, FlowCancellationError, isFlowCancellationError, toJS, trace, IObserverTree, IDependencyTree, getDependencyTree, getObserverTree, resetGlobalState as _resetGlobalState, getGlobalState as _getGlobalState, getDebugName, getAtom, getAdministration as _getAdministration, allowStateChanges as _allowStateChanges, runInAction as _allowStateChangesInsideComputed, // This has become the default behavior in Mobx 6
|
|
2
|
+
Lambda, $mobx, isComputingDerivation as _isComputingDerivation, onReactionError, interceptReads as _interceptReads, IComputedValueOptions, IActionRunInfo, _startAction, _endAction, allowStateReadsStart as _allowStateReadsStart, allowStateReadsEnd as _allowStateReadsEnd, makeObservable, makeAutoObservable, autoAction as _autoAction, AnnotationsMap, AnnotationMapEntry, override } from './mobx/internal';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Middleware } from './types/middleware';
|
|
2
|
+
import { StoreEnhancer } from './types/store';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a store enhancer that applies middleware to the dispatch method
|
|
5
|
+
* of the Redux store. This is handy for a variety of tasks, such as expressing
|
|
6
|
+
* asynchronous actions in a concise manner, or logging every action payload.
|
|
7
|
+
*
|
|
8
|
+
* See `redux-thunk` package as an example of the Redux middleware.
|
|
9
|
+
*
|
|
10
|
+
* Because middleware is potentially asynchronous, this should be the first
|
|
11
|
+
* store enhancer in the composition chain.
|
|
12
|
+
*
|
|
13
|
+
* Note that each middleware will be given the `dispatch` and `getState` functions
|
|
14
|
+
* as named arguments.
|
|
15
|
+
*
|
|
16
|
+
* @param middlewares The middleware chain to be applied.
|
|
17
|
+
* @returns A store enhancer applying the middleware.
|
|
18
|
+
*
|
|
19
|
+
* @template Ext Dispatch signature added by a middleware.
|
|
20
|
+
* @template S The type of the state supported by a middleware.
|
|
21
|
+
*/
|
|
22
|
+
export default function applyMiddleware(): StoreEnhancer;
|
|
23
|
+
export default function applyMiddleware<Ext1, S>(middleware1: Middleware<Ext1, S, any>): StoreEnhancer<{
|
|
24
|
+
dispatch: Ext1;
|
|
25
|
+
}>;
|
|
26
|
+
export default function applyMiddleware<Ext1, Ext2, S>(middleware1: Middleware<Ext1, S, any>, middleware2: Middleware<Ext2, S, any>): StoreEnhancer<{
|
|
27
|
+
dispatch: Ext1 & Ext2;
|
|
28
|
+
}>;
|
|
29
|
+
export default function applyMiddleware<Ext1, Ext2, Ext3, S>(middleware1: Middleware<Ext1, S, any>, middleware2: Middleware<Ext2, S, any>, middleware3: Middleware<Ext3, S, any>): StoreEnhancer<{
|
|
30
|
+
dispatch: Ext1 & Ext2 & Ext3;
|
|
31
|
+
}>;
|
|
32
|
+
export default function applyMiddleware<Ext1, Ext2, Ext3, Ext4, S>(middleware1: Middleware<Ext1, S, any>, middleware2: Middleware<Ext2, S, any>, middleware3: Middleware<Ext3, S, any>, middleware4: Middleware<Ext4, S, any>): StoreEnhancer<{
|
|
33
|
+
dispatch: Ext1 & Ext2 & Ext3 & Ext4;
|
|
34
|
+
}>;
|
|
35
|
+
export default function applyMiddleware<Ext1, Ext2, Ext3, Ext4, Ext5, S>(middleware1: Middleware<Ext1, S, any>, middleware2: Middleware<Ext2, S, any>, middleware3: Middleware<Ext3, S, any>, middleware4: Middleware<Ext4, S, any>, middleware5: Middleware<Ext5, S, any>): StoreEnhancer<{
|
|
36
|
+
dispatch: Ext1 & Ext2 & Ext3 & Ext4 & Ext5;
|
|
37
|
+
}>;
|
|
38
|
+
export default function applyMiddleware<Ext, S = any>(...middlewares: Middleware<any, S, any>[]): StoreEnhancer<{
|
|
39
|
+
dispatch: Ext;
|
|
40
|
+
}>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Dispatch } from './types/store';
|
|
2
|
+
import { ActionCreator, ActionCreatorsMapObject } from './types/actions';
|
|
3
|
+
/**
|
|
4
|
+
* Turns an object whose values are action creators, into an object with the
|
|
5
|
+
* same keys, but with every function wrapped into a `dispatch` call so they
|
|
6
|
+
* may be invoked directly. This is just a convenience method, as you can call
|
|
7
|
+
* `store.dispatch(MyActionCreators.doSomething())` yourself just fine.
|
|
8
|
+
*
|
|
9
|
+
* For convenience, you can also pass an action creator as the first argument,
|
|
10
|
+
* and get a dispatch wrapped function in return.
|
|
11
|
+
*
|
|
12
|
+
* @param actionCreators An object whose values are action
|
|
13
|
+
* creator functions. One handy way to obtain it is to use `import * as`
|
|
14
|
+
* syntax. You may also pass a single function.
|
|
15
|
+
*
|
|
16
|
+
* @param dispatch The `dispatch` function available on your Redux
|
|
17
|
+
* store.
|
|
18
|
+
*
|
|
19
|
+
* @returns The object mimicking the original object, but with
|
|
20
|
+
* every action creator wrapped into the `dispatch` call. If you passed a
|
|
21
|
+
* function as `actionCreators`, the return value will also be a single
|
|
22
|
+
* function.
|
|
23
|
+
*/
|
|
24
|
+
export default function bindActionCreators<A, C extends ActionCreator<A>>(actionCreator: C, dispatch: Dispatch): C;
|
|
25
|
+
export default function bindActionCreators<A extends ActionCreator<any>, B extends ActionCreator<any>>(actionCreator: A, dispatch: Dispatch): B;
|
|
26
|
+
export default function bindActionCreators<A, M extends ActionCreatorsMapObject<A>>(actionCreators: M, dispatch: Dispatch): M;
|
|
27
|
+
export default function bindActionCreators<M extends ActionCreatorsMapObject, N extends ActionCreatorsMapObject>(actionCreators: M, dispatch: Dispatch): N;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ActionFromReducersMapObject, PreloadedStateShapeFromReducersMapObject, Reducer, StateFromReducersMapObject } from './types/reducers';
|
|
2
|
+
/**
|
|
3
|
+
* Turns an object whose values are different reducer functions, into a single
|
|
4
|
+
* reducer function. It will call every child reducer, and gather their results
|
|
5
|
+
* into a single state object, whose keys correspond to the keys of the passed
|
|
6
|
+
* reducer functions.
|
|
7
|
+
*
|
|
8
|
+
* @template S Combined state object type.
|
|
9
|
+
*
|
|
10
|
+
* @param reducers An object whose values correspond to different reducer
|
|
11
|
+
* functions that need to be combined into one. One handy way to obtain it
|
|
12
|
+
* is to use `import * as reducers` syntax. The reducers may never
|
|
13
|
+
* return undefined for any action. Instead, they should return their
|
|
14
|
+
* initial state if the state passed to them was undefined, and the current
|
|
15
|
+
* state for any unrecognized action.
|
|
16
|
+
*
|
|
17
|
+
* @returns A reducer function that invokes every reducer inside the passed
|
|
18
|
+
* object, and builds a state object with the same shape.
|
|
19
|
+
*/
|
|
20
|
+
export default function combineReducers<M>(reducers: M): M[keyof M] extends Reducer<any, any, any> | undefined ? Reducer<StateFromReducersMapObject<M>, ActionFromReducersMapObject<M>, Partial<PreloadedStateShapeFromReducersMapObject<M>>> : never;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type Func<T extends any[], R> = (...a: T) => R;
|
|
2
|
+
/**
|
|
3
|
+
* Composes single-argument functions from right to left. The rightmost
|
|
4
|
+
* function can take multiple arguments as it provides the signature for the
|
|
5
|
+
* resulting composite function.
|
|
6
|
+
*
|
|
7
|
+
* @param funcs The functions to compose.
|
|
8
|
+
* @returns A function obtained by composing the argument functions from right
|
|
9
|
+
* to left. For example, `compose(f, g, h)` is identical to doing
|
|
10
|
+
* `(...args) => f(g(h(...args)))`.
|
|
11
|
+
*/
|
|
12
|
+
export default function compose(): <R>(a: R) => R;
|
|
13
|
+
export default function compose<F extends Function>(f: F): F;
|
|
14
|
+
export default function compose<A, T extends any[], R>(f1: (a: A) => R, f2: Func<T, A>): Func<T, R>;
|
|
15
|
+
export default function compose<A, B, T extends any[], R>(f1: (b: B) => R, f2: (a: A) => B, f3: Func<T, A>): Func<T, R>;
|
|
16
|
+
export default function compose<A, B, C, T extends any[], R>(f1: (c: C) => R, f2: (b: B) => C, f3: (a: A) => B, f4: Func<T, A>): Func<T, R>;
|
|
17
|
+
export default function compose<R>(f1: (a: any) => R, ...funcs: Function[]): (...args: any[]) => R;
|
|
18
|
+
export default function compose<R>(...funcs: Function[]): (...args: any[]) => R;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { Store, StoreEnhancer, UnknownIfNonSpecific } from './types/store';
|
|
2
|
+
import { Action } from './types/actions';
|
|
3
|
+
import { Reducer } from './types/reducers';
|
|
4
|
+
/**
|
|
5
|
+
* Prevents TypeScript from inferring a generic type parameter.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type to prevent inference for.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated
|
|
14
|
+
*
|
|
15
|
+
* **We recommend using the `configureStore` method
|
|
16
|
+
* of the `@reduxjs/toolkit` package**, which replaces `createStore`.
|
|
17
|
+
*
|
|
18
|
+
* Redux Toolkit is our recommended approach for writing Redux logic today,
|
|
19
|
+
* including store setup, reducers, data fetching, and more.
|
|
20
|
+
*
|
|
21
|
+
* **For more details, please read this Redux docs page:**
|
|
22
|
+
* **https://redux.js.org/introduction/why-rtk-is-redux-today**
|
|
23
|
+
*
|
|
24
|
+
* `configureStore` from Redux Toolkit is an improved version of `createStore` that
|
|
25
|
+
* simplifies setup and helps avoid common bugs.
|
|
26
|
+
*
|
|
27
|
+
* You should not be using the `redux` core package by itself today, except for learning purposes.
|
|
28
|
+
* The `createStore` method from the core `redux` package will not be removed, but we encourage
|
|
29
|
+
* all users to migrate to using Redux Toolkit for all Redux code.
|
|
30
|
+
*
|
|
31
|
+
* If you want to use `createStore` without this visual deprecation warning, use
|
|
32
|
+
* the `legacy_createStore` import instead:
|
|
33
|
+
*
|
|
34
|
+
* `import { legacy_createStore as createStore} from 'redux'`
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
export declare function createStore<S, A extends Action, Ext extends {} = {}, StateExt extends {} = {}>(reducer: Reducer<S, A>, enhancer?: StoreEnhancer<Ext, StateExt>): Store<S, A, UnknownIfNonSpecific<StateExt>> & NoInfer<Ext>;
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated
|
|
40
|
+
*
|
|
41
|
+
* **We recommend using the `configureStore` method
|
|
42
|
+
* of the `@reduxjs/toolkit` package**, which replaces `createStore`.
|
|
43
|
+
*
|
|
44
|
+
* Redux Toolkit is our recommended approach for writing Redux logic today,
|
|
45
|
+
* including store setup, reducers, data fetching, and more.
|
|
46
|
+
*
|
|
47
|
+
* **For more details, please read this Redux docs page:**
|
|
48
|
+
* **https://redux.js.org/introduction/why-rtk-is-redux-today**
|
|
49
|
+
*
|
|
50
|
+
* `configureStore` from Redux Toolkit is an improved version of `createStore` that
|
|
51
|
+
* simplifies setup and helps avoid common bugs.
|
|
52
|
+
*
|
|
53
|
+
* You should not be using the `redux` core package by itself today, except for learning purposes.
|
|
54
|
+
* The `createStore` method from the core `redux` package will not be removed, but we encourage
|
|
55
|
+
* all users to migrate to using Redux Toolkit for all Redux code.
|
|
56
|
+
*
|
|
57
|
+
* If you want to use `createStore` without this visual deprecation warning, use
|
|
58
|
+
* the `legacy_createStore` import instead:
|
|
59
|
+
*
|
|
60
|
+
* `import { legacy_createStore as createStore} from 'redux'`
|
|
61
|
+
*
|
|
62
|
+
*/
|
|
63
|
+
export declare function createStore<S, A extends Action, Ext extends {} = {}, StateExt extends {} = {}, PreloadedState = S>(reducer: Reducer<S, A, PreloadedState>, preloadedState?: PreloadedState | undefined, enhancer?: StoreEnhancer<Ext, StateExt>): Store<S, A, UnknownIfNonSpecific<StateExt>> & NoInfer<Ext>;
|
|
64
|
+
/**
|
|
65
|
+
* Creates a Redux store that holds the state tree.
|
|
66
|
+
*
|
|
67
|
+
* **We recommend using `configureStore` from the
|
|
68
|
+
* `@reduxjs/toolkit` package**, which replaces `createStore`:
|
|
69
|
+
* **https://redux.js.org/introduction/why-rtk-is-redux-today**
|
|
70
|
+
*
|
|
71
|
+
* The only way to change the data in the store is to call `dispatch()` on it.
|
|
72
|
+
*
|
|
73
|
+
* There should only be a single store in your app. To specify how different
|
|
74
|
+
* parts of the state tree respond to actions, you may combine several reducers
|
|
75
|
+
* into a single reducer function by using `combineReducers`.
|
|
76
|
+
*
|
|
77
|
+
* @param {Function} reducer A function that returns the next state tree, given
|
|
78
|
+
* the current state tree and the action to handle.
|
|
79
|
+
*
|
|
80
|
+
* @param {any} [preloadedState] The initial state. You may optionally specify it
|
|
81
|
+
* to hydrate the state from the server in universal apps, or to restore a
|
|
82
|
+
* previously serialized user session.
|
|
83
|
+
* If you use `combineReducers` to produce the root reducer function, this must be
|
|
84
|
+
* an object with the same shape as `combineReducers` keys.
|
|
85
|
+
*
|
|
86
|
+
* @param {Function} [enhancer] The store enhancer. You may optionally specify it
|
|
87
|
+
* to enhance the store with third-party capabilities such as middleware,
|
|
88
|
+
* time travel, persistence, etc. The only store enhancer that ships with Redux
|
|
89
|
+
* is `applyMiddleware()`.
|
|
90
|
+
*
|
|
91
|
+
* @returns {Store} A Redux store that lets you read the state, dispatch actions
|
|
92
|
+
* and subscribe to changes.
|
|
93
|
+
*/
|
|
94
|
+
export declare function legacy_createStore<S, A extends Action, Ext extends {} = {}, StateExt extends {} = {}>(reducer: Reducer<S, A>, enhancer?: StoreEnhancer<Ext, StateExt>): Store<S, A, UnknownIfNonSpecific<StateExt>> & Ext;
|
|
95
|
+
/**
|
|
96
|
+
* Creates a Redux store that holds the state tree.
|
|
97
|
+
*
|
|
98
|
+
* **We recommend using `configureStore` from the
|
|
99
|
+
* `@reduxjs/toolkit` package**, which replaces `createStore`:
|
|
100
|
+
* **https://redux.js.org/introduction/why-rtk-is-redux-today**
|
|
101
|
+
*
|
|
102
|
+
* The only way to change the data in the store is to call `dispatch()` on it.
|
|
103
|
+
*
|
|
104
|
+
* There should only be a single store in your app. To specify how different
|
|
105
|
+
* parts of the state tree respond to actions, you may combine several reducers
|
|
106
|
+
* into a single reducer function by using `combineReducers`.
|
|
107
|
+
*
|
|
108
|
+
* @param {Function} reducer A function that returns the next state tree, given
|
|
109
|
+
* the current state tree and the action to handle.
|
|
110
|
+
*
|
|
111
|
+
* @param {any} [preloadedState] The initial state. You may optionally specify it
|
|
112
|
+
* to hydrate the state from the server in universal apps, or to restore a
|
|
113
|
+
* previously serialized user session.
|
|
114
|
+
* If you use `combineReducers` to produce the root reducer function, this must be
|
|
115
|
+
* an object with the same shape as `combineReducers` keys.
|
|
116
|
+
*
|
|
117
|
+
* @param {Function} [enhancer] The store enhancer. You may optionally specify it
|
|
118
|
+
* to enhance the store with third-party capabilities such as middleware,
|
|
119
|
+
* time travel, persistence, etc. The only store enhancer that ships with Redux
|
|
120
|
+
* is `applyMiddleware()`.
|
|
121
|
+
*
|
|
122
|
+
* @returns {Store} A Redux store that lets you read the state, dispatch actions
|
|
123
|
+
* and subscribe to changes.
|
|
124
|
+
*/
|
|
125
|
+
export declare function legacy_createStore<S, A extends Action, Ext extends {} = {}, StateExt extends {} = {}, PreloadedState = S>(reducer: Reducer<S, A, PreloadedState>, preloadedState?: PreloadedState | undefined, enhancer?: StoreEnhancer<Ext, StateExt>): Store<S, A, UnknownIfNonSpecific<StateExt>> & Ext;
|
|
126
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createStore, legacy_createStore } from './createStore';
|
|
2
|
+
import { default as combineReducers } from './combineReducers';
|
|
3
|
+
import { default as bindActionCreators } from './bindActionCreators';
|
|
4
|
+
import { default as applyMiddleware } from './applyMiddleware';
|
|
5
|
+
import { default as compose } from './compose';
|
|
6
|
+
import { default as isAction } from './utils/isAction';
|
|
7
|
+
import { default as isPlainObject } from './utils/isPlainObject';
|
|
8
|
+
import { default as ___DO_NOT_USE__ActionTypes } from './utils/actionTypes';
|
|
9
|
+
export type { Dispatch, Unsubscribe, Observable, Observer, Store, StoreCreator, StoreEnhancer, StoreEnhancerStoreCreator } from './types/store';
|
|
10
|
+
export type { Reducer, ReducersMapObject, StateFromReducersMapObject, ReducerFromReducersMapObject, ActionFromReducer, ActionFromReducersMapObject, PreloadedStateShapeFromReducersMapObject } from './types/reducers';
|
|
11
|
+
export type { ActionCreator, ActionCreatorsMapObject } from './types/actions';
|
|
12
|
+
export type { MiddlewareAPI, Middleware } from './types/middleware';
|
|
13
|
+
export type { Action, UnknownAction, AnyAction } from './types/actions';
|
|
14
|
+
export { createStore, legacy_createStore, combineReducers, bindActionCreators, applyMiddleware, compose, isAction, isPlainObject, __DO_NOT_USE__ActionTypes };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An *action* is a plain object that represents an intention to change the
|
|
3
|
+
* state. Actions are the only way to get data into the store. Any data,
|
|
4
|
+
* whether from UI events, network callbacks, or other sources such as
|
|
5
|
+
* WebSockets needs to eventually be dispatched as actions.
|
|
6
|
+
*
|
|
7
|
+
* Actions must have a `type` field that indicates the type of action being
|
|
8
|
+
* performed. Types can be defined as constants and imported from another
|
|
9
|
+
* module. These must be strings, as strings are serializable.
|
|
10
|
+
*
|
|
11
|
+
* Other than `type`, the structure of an action object is really up to you.
|
|
12
|
+
* If you're interested, check out Flux Standard Action for recommendations on
|
|
13
|
+
* how actions should be constructed.
|
|
14
|
+
*
|
|
15
|
+
* @template T the type of the action's `type` tag.
|
|
16
|
+
*/
|
|
17
|
+
export type Action<T extends string = string> = {
|
|
18
|
+
type: T;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* An Action type which accepts any other properties.
|
|
22
|
+
* This is mainly for the use of the `Reducer` type.
|
|
23
|
+
* This is not part of `Action` itself to prevent types that extend `Action` from
|
|
24
|
+
* having an index signature.
|
|
25
|
+
*/
|
|
26
|
+
export interface UnknownAction extends Action {
|
|
27
|
+
[extraProps: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* An Action type which accepts any other properties.
|
|
31
|
+
* This is mainly for the use of the `Reducer` type.
|
|
32
|
+
* This is not part of `Action` itself to prevent types that extend `Action` from
|
|
33
|
+
* having an index signature.
|
|
34
|
+
* @deprecated use Action or UnknownAction instead
|
|
35
|
+
*/
|
|
36
|
+
export interface AnyAction extends Action {
|
|
37
|
+
[extraProps: string]: any;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* An *action creator* is, quite simply, a function that creates an action. Do
|
|
41
|
+
* not confuse the two terms—again, an action is a payload of information, and
|
|
42
|
+
* an action creator is a factory that creates an action.
|
|
43
|
+
*
|
|
44
|
+
* Calling an action creator only produces an action, but does not dispatch
|
|
45
|
+
* it. You need to call the store's `dispatch` function to actually cause the
|
|
46
|
+
* mutation. Sometimes we say *bound action creators* to mean functions that
|
|
47
|
+
* call an action creator and immediately dispatch its result to a specific
|
|
48
|
+
* store instance.
|
|
49
|
+
*
|
|
50
|
+
* If an action creator needs to read the current state, perform an API call,
|
|
51
|
+
* or cause a side effect, like a routing transition, it should return an
|
|
52
|
+
* async action instead of an action.
|
|
53
|
+
*
|
|
54
|
+
* @template A Returned action type.
|
|
55
|
+
*/
|
|
56
|
+
export interface ActionCreator<A, P extends any[] = any[]> {
|
|
57
|
+
(...args: P): A;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Object whose values are action creator functions.
|
|
61
|
+
*/
|
|
62
|
+
export interface ActionCreatorsMapObject<A = any, P extends any[] = any[]> {
|
|
63
|
+
[key: string]: ActionCreator<A, P>;
|
|
64
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Dispatch } from './store';
|
|
2
|
+
export interface MiddlewareAPI<D extends Dispatch = Dispatch, S = any> {
|
|
3
|
+
dispatch: D;
|
|
4
|
+
getState: () => S;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* A middleware is a higher-order function that composes a dispatch function
|
|
8
|
+
* to return a new dispatch function. It often turns async actions into
|
|
9
|
+
* actions.
|
|
10
|
+
*
|
|
11
|
+
* Middleware is composable using function composition. It is useful for
|
|
12
|
+
* logging actions, performing side effects like routing, or turning an
|
|
13
|
+
* asynchronous API call into a series of synchronous actions.
|
|
14
|
+
*
|
|
15
|
+
* @template DispatchExt Extra Dispatch signature added by this middleware.
|
|
16
|
+
* @template S The type of the state supported by this middleware.
|
|
17
|
+
* @template D The type of Dispatch of the store where this middleware is
|
|
18
|
+
* installed.
|
|
19
|
+
*/
|
|
20
|
+
export interface Middleware<_DispatchExt = {}, // TODO: see if this can be used in type definition somehow (can't be removed, as is used to get final dispatch type)
|
|
21
|
+
S = any, D extends Dispatch = Dispatch> {
|
|
22
|
+
(api: MiddlewareAPI<D, S>): (next: (action: unknown) => unknown) => (action: unknown) => unknown;
|
|
23
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Action, UnknownAction } from './actions';
|
|
2
|
+
/**
|
|
3
|
+
* A *reducer* is a function that accepts
|
|
4
|
+
* an accumulation and a value and returns a new accumulation. They are used
|
|
5
|
+
* to reduce a collection of values down to a single value
|
|
6
|
+
*
|
|
7
|
+
* Reducers are not unique to Redux—they are a fundamental concept in
|
|
8
|
+
* functional programming. Even most non-functional languages, like
|
|
9
|
+
* JavaScript, have a built-in API for reducing. In JavaScript, it's
|
|
10
|
+
* `Array.prototype.reduce()`.
|
|
11
|
+
*
|
|
12
|
+
* In Redux, the accumulated value is the state object, and the values being
|
|
13
|
+
* accumulated are actions. Reducers calculate a new state given the previous
|
|
14
|
+
* state and an action. They must be *pure functions*—functions that return
|
|
15
|
+
* the exact same output for given inputs. They should also be free of
|
|
16
|
+
* side-effects. This is what enables exciting features like hot reloading and
|
|
17
|
+
* time travel.
|
|
18
|
+
*
|
|
19
|
+
* Reducers are the most important concept in Redux.
|
|
20
|
+
*
|
|
21
|
+
* *Do not put API calls into reducers.*
|
|
22
|
+
*
|
|
23
|
+
* @template S The type of state consumed and produced by this reducer.
|
|
24
|
+
* @template A The type of actions the reducer can potentially respond to.
|
|
25
|
+
* @template PreloadedState The type of state consumed by this reducer the first time it's called.
|
|
26
|
+
*/
|
|
27
|
+
export type Reducer<S = any, A extends Action = UnknownAction, PreloadedState = S> = (state: S | PreloadedState | undefined, action: A) => S;
|
|
28
|
+
/**
|
|
29
|
+
* Object whose values correspond to different reducer functions.
|
|
30
|
+
*
|
|
31
|
+
* @template S The combined state of the reducers.
|
|
32
|
+
* @template A The type of actions the reducers can potentially respond to.
|
|
33
|
+
* @template PreloadedState The combined preloaded state of the reducers.
|
|
34
|
+
*/
|
|
35
|
+
export type ReducersMapObject<S = any, A extends Action = UnknownAction, PreloadedState = S> = keyof PreloadedState extends keyof S ? {
|
|
36
|
+
[K in keyof S]: Reducer<S[K], A, K extends keyof PreloadedState ? PreloadedState[K] : never>;
|
|
37
|
+
} : never;
|
|
38
|
+
/**
|
|
39
|
+
* Infer a combined state shape from a `ReducersMapObject`.
|
|
40
|
+
*
|
|
41
|
+
* @template M Object map of reducers as provided to `combineReducers(map: M)`.
|
|
42
|
+
*/
|
|
43
|
+
export type StateFromReducersMapObject<M> = M[keyof M] extends Reducer<any, any, any> | undefined ? {
|
|
44
|
+
[P in keyof M]: M[P] extends Reducer<infer S, any, any> ? S : never;
|
|
45
|
+
} : never;
|
|
46
|
+
/**
|
|
47
|
+
* Infer reducer union type from a `ReducersMapObject`.
|
|
48
|
+
*
|
|
49
|
+
* @template M Object map of reducers as provided to `combineReducers(map: M)`.
|
|
50
|
+
*/
|
|
51
|
+
export type ReducerFromReducersMapObject<M> = M[keyof M] extends Reducer<any, any, any> | undefined ? M[keyof M] : never;
|
|
52
|
+
/**
|
|
53
|
+
* Infer action type from a reducer function.
|
|
54
|
+
*
|
|
55
|
+
* @template R Type of reducer.
|
|
56
|
+
*/
|
|
57
|
+
export type ActionFromReducer<R> = R extends Reducer<any, infer A, any> ? A : never;
|
|
58
|
+
/**
|
|
59
|
+
* Infer action union type from a `ReducersMapObject`.
|
|
60
|
+
*
|
|
61
|
+
* @template M Object map of reducers as provided to `combineReducers(map: M)`.
|
|
62
|
+
*/
|
|
63
|
+
export type ActionFromReducersMapObject<M> = ActionFromReducer<ReducerFromReducersMapObject<M>>;
|
|
64
|
+
/**
|
|
65
|
+
* Infer a combined preloaded state shape from a `ReducersMapObject`.
|
|
66
|
+
*
|
|
67
|
+
* @template M Object map of reducers as provided to `combineReducers(map: M)`.
|
|
68
|
+
*/
|
|
69
|
+
export type PreloadedStateShapeFromReducersMapObject<M> = M[keyof M] extends Reducer<any, any, any> | undefined ? {
|
|
70
|
+
[P in keyof M]: M[P] extends (inputState: infer InputState, action: ActionFromReducersMapObject<M>) => any ? InputState : never;
|
|
71
|
+
} : never;
|