@tramvai/state 1.8.7 → 1.9.2
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/lib/index.js +26 -26
- package/lib/index_middleware.js +8 -8
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -169,7 +169,7 @@ class DispatcherContext extends SimpleEmitter {
|
|
|
169
169
|
subscribe: this.subscribe.bind(this),
|
|
170
170
|
dispatch: (...args) => dispatch(...args),
|
|
171
171
|
};
|
|
172
|
-
dispatch = compose__default[
|
|
172
|
+
dispatch = compose__default["default"](...middlewares.map((middleware) => middleware(api)))(this.applyDispatch);
|
|
173
173
|
return dispatch;
|
|
174
174
|
}
|
|
175
175
|
// eslint-disable-next-line max-statements
|
|
@@ -468,9 +468,9 @@ function createDispatcher(options) {
|
|
|
468
468
|
return new Dispatcher(options);
|
|
469
469
|
}
|
|
470
470
|
|
|
471
|
-
function createEvent(eventName, payloadCreator = identity__default[
|
|
471
|
+
function createEvent(eventName, payloadCreator = identity__default["default"]) {
|
|
472
472
|
if (process.env.NODE_ENV !== 'production') {
|
|
473
|
-
if (!isString__default[
|
|
473
|
+
if (!isString__default["default"](eventName) || !eventName.length) {
|
|
474
474
|
throw new Error(`eventName should be not empty string, got '${eventName}'`);
|
|
475
475
|
}
|
|
476
476
|
}
|
|
@@ -555,7 +555,7 @@ class BaseStore extends SimpleEmitter {
|
|
|
555
555
|
return this.state;
|
|
556
556
|
}
|
|
557
557
|
dehydrate() {
|
|
558
|
-
return pick__default[
|
|
558
|
+
return pick__default["default"](Object.keys(this.hydrateKeys), this.state);
|
|
559
559
|
}
|
|
560
560
|
rehydrate(state) {
|
|
561
561
|
this.setStateSilently(state);
|
|
@@ -637,7 +637,7 @@ function useActions(actions) {
|
|
|
637
637
|
const context = useConsumerContext();
|
|
638
638
|
const actionsRef = reactHooks.useShallowEqual(actions);
|
|
639
639
|
return React.useMemo(() => {
|
|
640
|
-
if (isArray__default[
|
|
640
|
+
if (isArray__default["default"](actionsRef)) {
|
|
641
641
|
return actionsRef.map((action) => context.executeAction.bind(context, action));
|
|
642
642
|
}
|
|
643
643
|
return context.executeAction.bind(context, actionsRef);
|
|
@@ -659,7 +659,7 @@ function useStore(reducer) {
|
|
|
659
659
|
const stateRef = React.useRef();
|
|
660
660
|
const reducerRef = React.useRef(reducer);
|
|
661
661
|
const addedReducerRef = React.useRef(null);
|
|
662
|
-
const unsubscribeRef = React.useRef(noop__default[
|
|
662
|
+
const unsubscribeRef = React.useRef(noop__default["default"]);
|
|
663
663
|
const [, forceRender] = React.useReducer((s) => s + 1, 0);
|
|
664
664
|
React.useMemo(() => {
|
|
665
665
|
// отписываемся от обновлений текущего редьюсера
|
|
@@ -713,13 +713,13 @@ function scheduling() {
|
|
|
713
713
|
}
|
|
714
714
|
|
|
715
715
|
const schedule = scheduling();
|
|
716
|
-
function useSelector(storesOrStore, selector, equalityFn = shallowEqual__default[
|
|
717
|
-
invariant__default[
|
|
716
|
+
function useSelector(storesOrStore, selector, equalityFn = shallowEqual__default["default"]) {
|
|
717
|
+
invariant__default["default"](selector, `You must pass a selector to useSelectors`);
|
|
718
718
|
const context = useConsumerContext();
|
|
719
719
|
const [, forceRender] = React.useReducer((s) => s + 1, 0);
|
|
720
720
|
const renderIsScheduled = React.useRef(false);
|
|
721
721
|
const storesRef = reactHooks.useShallowEqual(storesOrStore);
|
|
722
|
-
const subscription = React.useMemo(() => new Subscription(toArray__default[
|
|
722
|
+
const subscription = React.useMemo(() => new Subscription(toArray__default["default"](storesRef).map(context.getStore)), [storesRef, context]);
|
|
723
723
|
const latestSubscriptionCallbackError = React.useRef();
|
|
724
724
|
const latestSelector = React.useRef(selector);
|
|
725
725
|
const latestSelectedState = React.useRef();
|
|
@@ -845,7 +845,7 @@ pure = true,
|
|
|
845
845
|
...connectOptions } = {}) {
|
|
846
846
|
return function wrapWithConnect(WrappedComponent) {
|
|
847
847
|
if (process.env.NODE_ENV !== 'production') {
|
|
848
|
-
invariant__default[
|
|
848
|
+
invariant__default["default"](reactIs.isValidElementType(WrappedComponent), `You must pass a component to the function returned by ` +
|
|
849
849
|
`${methodName}. Instead received ${stringifyComponent(WrappedComponent)}`);
|
|
850
850
|
}
|
|
851
851
|
const wrappedComponentName = WrappedComponent.displayName || WrappedComponent.name || 'Component';
|
|
@@ -875,7 +875,7 @@ pure = true,
|
|
|
875
875
|
}, [props]);
|
|
876
876
|
// Retrieve the store and ancestor subscription via context, if available
|
|
877
877
|
const contextValue = useConsumerContext();
|
|
878
|
-
invariant__default[
|
|
878
|
+
invariant__default["default"](Boolean(contextValue), `Could not find context in ` +
|
|
879
879
|
`"${displayName}". Either wrap the root component in a <Provider>, ` +
|
|
880
880
|
`or pass a custom React context provider to <Provider> and the corresponding ` +
|
|
881
881
|
`React context consumer to ${displayName} in connect options.`);
|
|
@@ -1011,43 +1011,43 @@ pure = true,
|
|
|
1011
1011
|
// We memoize the elements for the rendered child component as an optimization.
|
|
1012
1012
|
const renderedWrappedComponent = React.useMemo(
|
|
1013
1013
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
1014
|
-
() => React__default[
|
|
1014
|
+
() => React__default["default"].createElement(WrappedComponent, Object.assign({}, actualChildProps, { ref: forwardedRef })), [forwardedRef, actualChildProps]);
|
|
1015
1015
|
return renderedWrappedComponent;
|
|
1016
1016
|
};
|
|
1017
1017
|
// If we're in "pure" mode, ensure our wrapper component only re-renders when incoming props have changed.
|
|
1018
|
-
const Connect = pure ? React__default[
|
|
1018
|
+
const Connect = pure ? React__default["default"].memo(ConnectFunction) : ConnectFunction;
|
|
1019
1019
|
Connect.WrappedComponent = WrappedComponent;
|
|
1020
1020
|
Connect.displayName = displayName;
|
|
1021
1021
|
if (forwardRef) {
|
|
1022
|
-
const forwarded = React__default[
|
|
1022
|
+
const forwarded = React__default["default"].forwardRef(function forwardConnectRef(props, ref) {
|
|
1023
1023
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
1024
|
-
return React__default[
|
|
1024
|
+
return React__default["default"].createElement(Connect, Object.assign({}, props, { forwardedRef: ref }));
|
|
1025
1025
|
});
|
|
1026
1026
|
forwarded.displayName = displayName;
|
|
1027
1027
|
forwarded.WrappedComponent = WrappedComponent;
|
|
1028
|
-
return hoistStatics__default[
|
|
1028
|
+
return hoistStatics__default["default"](forwarded, WrappedComponent);
|
|
1029
1029
|
}
|
|
1030
|
-
return hoistStatics__default[
|
|
1030
|
+
return hoistStatics__default["default"](Connect, WrappedComponent);
|
|
1031
1031
|
};
|
|
1032
1032
|
}
|
|
1033
1033
|
|
|
1034
1034
|
const getLogger = () => console;
|
|
1035
1035
|
|
|
1036
1036
|
function verifyPlainObject(value, displayName, methodName) {
|
|
1037
|
-
if (!isPlainObject__default[
|
|
1037
|
+
if (!isPlainObject__default["default"](value)) {
|
|
1038
1038
|
getLogger().debug(`${methodName}() in ${displayName} must return a plain object. Instead received ${value}.`);
|
|
1039
1039
|
}
|
|
1040
1040
|
}
|
|
1041
1041
|
|
|
1042
1042
|
function verifyFunction(value, displayName, methodName) {
|
|
1043
|
-
if (!isFunction__default[
|
|
1043
|
+
if (!isFunction__default["default"](value)) {
|
|
1044
1044
|
getLogger().debug(`${methodName}() in ${displayName} must be a function. Instead received ${JSON.stringify(value)}.`);
|
|
1045
1045
|
}
|
|
1046
1046
|
}
|
|
1047
1047
|
|
|
1048
1048
|
function wrapMapToPropsConstant(getConstant) {
|
|
1049
1049
|
return function initConstantSelector(context, options) {
|
|
1050
|
-
const constantSelector = always__default[
|
|
1050
|
+
const constantSelector = always__default["default"](getConstant(context, options));
|
|
1051
1051
|
constantSelector.dependsOnOwnProps = false;
|
|
1052
1052
|
return constantSelector;
|
|
1053
1053
|
};
|
|
@@ -1102,7 +1102,7 @@ function wrapMapToPropsFunc(mapToProps, methodName) {
|
|
|
1102
1102
|
}
|
|
1103
1103
|
function wrapMapToPropsObject(actionsObject) {
|
|
1104
1104
|
function getConstant({ executeAction }, { displayName }) {
|
|
1105
|
-
return mapObject__default[
|
|
1105
|
+
return mapObject__default["default"]((action, actionName) => {
|
|
1106
1106
|
if (process.env.NODE_ENV !== 'production') {
|
|
1107
1107
|
verifyFunction(action, displayName, actionName);
|
|
1108
1108
|
}
|
|
@@ -1118,7 +1118,7 @@ function whenMapContextToPropsIsFunction(mapContextToProps) {
|
|
|
1118
1118
|
: undefined;
|
|
1119
1119
|
}
|
|
1120
1120
|
function whenMapContextToPropsIsMissing(mapContextToProps) {
|
|
1121
|
-
return !mapContextToProps ? wrapMapToPropsConstant(always__default[
|
|
1121
|
+
return !mapContextToProps ? wrapMapToPropsConstant(always__default["default"]({})) : undefined;
|
|
1122
1122
|
}
|
|
1123
1123
|
function whenMapContextToPropsIsObject(mapContextToProps) {
|
|
1124
1124
|
return typeof mapContextToProps === 'object' && mapContextToProps !== null
|
|
@@ -1137,7 +1137,7 @@ function whenMapStateToPropsIsFunction(mapStateToProps) {
|
|
|
1137
1137
|
: undefined;
|
|
1138
1138
|
}
|
|
1139
1139
|
function whenMapStateToPropsIsMissing(mapStateToProps) {
|
|
1140
|
-
return !mapStateToProps ? wrapMapToPropsConstant(always__default[
|
|
1140
|
+
return !mapStateToProps ? wrapMapToPropsConstant(always__default["default"]({})) : undefined;
|
|
1141
1141
|
}
|
|
1142
1142
|
const mapStateToPropsFactories = [
|
|
1143
1143
|
whenMapStateToPropsIsFunction,
|
|
@@ -1181,7 +1181,7 @@ const verifyMapToProps = (mapStateToProps, name) => {
|
|
|
1181
1181
|
function verify(state, props) {
|
|
1182
1182
|
const firstStateProps = mapStateToProps(state, props);
|
|
1183
1183
|
const secondStateProps = mapStateToProps(state, props);
|
|
1184
|
-
if (!shallowEqual__default[
|
|
1184
|
+
if (!shallowEqual__default["default"](firstStateProps, secondStateProps)) {
|
|
1185
1185
|
getLogger().warn('Component "%s" recreate equal props %s', name, Object.keys(firstStateProps)
|
|
1186
1186
|
.filter((key) => firstStateProps[key] !== secondStateProps[key])
|
|
1187
1187
|
.map((key) => `"${key}"`)
|
|
@@ -1286,7 +1286,7 @@ function finalPropsSelectorFactory(context, { initMapStateToProps, initMapContex
|
|
|
1286
1286
|
}
|
|
1287
1287
|
|
|
1288
1288
|
const Provider = ({ context, children }) => {
|
|
1289
|
-
return React__default[
|
|
1289
|
+
return React__default["default"].createElement(ConnectContext.Provider, { value: context }, children);
|
|
1290
1290
|
};
|
|
1291
1291
|
|
|
1292
1292
|
/*
|
|
@@ -1316,7 +1316,7 @@ function match(arg, factories, name) {
|
|
|
1316
1316
|
// createConnect with default args builds the 'official' connect behavior. Calling it with
|
|
1317
1317
|
// different options opens up some testing and extensibility scenarios
|
|
1318
1318
|
function createConnect({ connectHOC = connectAdvanced, mapStateToPropsFactories: mapStateToPropsFactories$1 = mapStateToPropsFactories, mapContextToPropsFactories: mapContextToPropsFactories$1 = mapContextToPropsFactories, mergePropsFactories: mergePropsFactories$1 = mergePropsFactories, selectorFactory = finalPropsSelectorFactory, schedule = scheduling(), } = {}) {
|
|
1319
|
-
return (stores, mapStateToProps, mapContextToProps, mergeProps, { pure = true, areStatesEqual = strictEqual__default[
|
|
1319
|
+
return (stores, mapStateToProps, mapContextToProps, mergeProps, { pure = true, areStatesEqual = strictEqual__default["default"], areOwnPropsEqual = shallowEqual__default["default"], areStatePropsEqual = shallowEqual__default["default"], areMergedPropsEqual = shallowEqual__default["default"], ...extraOptions } = {}
|
|
1320
1320
|
// eslint-disable-next-line max-params
|
|
1321
1321
|
) => {
|
|
1322
1322
|
// @ts-ignore
|
package/lib/index_middleware.js
CHANGED
|
@@ -14,13 +14,13 @@ var noop__default = /*#__PURE__*/_interopDefaultLegacy(noop);
|
|
|
14
14
|
var startsWith__default = /*#__PURE__*/_interopDefaultLegacy(startsWith);
|
|
15
15
|
var isElement__default = /*#__PURE__*/_interopDefaultLegacy(isElement);
|
|
16
16
|
|
|
17
|
-
const elementReplacer = pick__default[
|
|
17
|
+
const elementReplacer = pick__default["default"](['tagName', 'id', 'className']);
|
|
18
18
|
// eslint-disable-next-line import/no-mutable-exports
|
|
19
19
|
let devTools = {
|
|
20
|
-
init: noop__default[
|
|
21
|
-
send: noop__default[
|
|
22
|
-
subscribe: noop__default[
|
|
23
|
-
error: noop__default[
|
|
20
|
+
init: noop__default["default"],
|
|
21
|
+
send: noop__default["default"],
|
|
22
|
+
subscribe: noop__default["default"],
|
|
23
|
+
error: noop__default["default"],
|
|
24
24
|
};
|
|
25
25
|
// eslint-disable-next-line no-underscore-dangle,@typescript-eslint/no-explicit-any
|
|
26
26
|
if (typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__) {
|
|
@@ -33,9 +33,9 @@ if (typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__) {
|
|
|
33
33
|
replacer: (key, value) => {
|
|
34
34
|
// eslint-disable-next-line default-case
|
|
35
35
|
switch (true) {
|
|
36
|
-
case isElement__default[
|
|
36
|
+
case isElement__default["default"](value):
|
|
37
37
|
return elementReplacer(value);
|
|
38
|
-
case startsWith__default[
|
|
38
|
+
case startsWith__default["default"]('_reactInternal', `${key}`):
|
|
39
39
|
return '_reactInternal';
|
|
40
40
|
}
|
|
41
41
|
return value;
|
|
@@ -47,7 +47,7 @@ if (typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__) {
|
|
|
47
47
|
const DISPATCH = 'DISPATCH';
|
|
48
48
|
|
|
49
49
|
const middleware = ({ pickState } = {}) => (api) => (next) => {
|
|
50
|
-
const getState = pickState && pickState.length ? () => pick__default[
|
|
50
|
+
const getState = pickState && pickState.length ? () => pick__default["default"](pickState, api.getState()) : api.getState;
|
|
51
51
|
// TODO: типизировать message
|
|
52
52
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
53
|
devTools.subscribe((message) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/state",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@tinkoff/react-hooks": "0.0.22",
|
|
22
22
|
"@tinkoff/utils": "^2.1.2",
|
|
23
|
-
"@tramvai/types-actions-state-context": "1.
|
|
23
|
+
"@tramvai/types-actions-state-context": "1.9.2",
|
|
24
24
|
"@types/hoist-non-react-statics": "^3.3.1",
|
|
25
25
|
"invariant": "^2.2.4",
|
|
26
26
|
"react-is": "^17.0.1",
|