redux-astroglide 0.1.11 → 0.1.13
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/README.md +41 -11
- package/dist/index.es.js +106 -94
- package/dist/index.js +105 -92
- package/dist/index.umd.js +104 -91
- package/dist/plugins/index.es.js +2 -3
- package/dist/plugins/index.js +2 -3
- package/dist/plugins/index.umd.js +2 -3
- package/dist/plugins/persist/index.es.js +0 -1
- package/dist/plugins/persist/index.js +0 -1
- package/dist/plugins/persist/index.umd.js +0 -1
- package/dist/plugins/set/index.es.js +2 -2
- package/dist/plugins/set/index.js +2 -2
- package/dist/plugins/set/index.umd.js +2 -2
- package/dist/selectors/index.es.js +1666 -0
- package/dist/selectors/index.js +1676 -0
- package/dist/selectors/index.umd.js +2535 -0
- package/dist/types/astroglide.d.ts +2 -2
- package/dist/types/createSelectorHook/index.d.ts +3 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/plugins/persist/index.d.ts +1 -1
- package/dist/types/{selectors.d.ts → selectors/index.d.ts} +1 -0
- package/package.json +7 -3
- package/dist/createSelectorHook/index.es.js +0 -17
- package/dist/createSelectorHook/index.js +0 -22
- package/dist/createSelectorHook/index.umd.js +0 -779
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Redux-Astroglide
|
|
2
2
|
|
|
3
|
-
####
|
|
3
|
+
#### Redux doesn't need to be such a pain the butt!
|
|
4
4
|
|
|
5
|
-
Astroglide is a set of configuration and automation tools built on top of Redux Toolkit in order to provide the most succinct API with the least boilerplate possible. It's the easiest way to get up and running with redux state, and has the lowest mental overhead of any state management tool for React.
|
|
5
|
+
Redux-Astroglide is a set of configuration and automation tools built on top of Redux Toolkit in order to provide the most succinct API with the least boilerplate possible. It's the easiest way to get up and running with redux state, and has the lowest mental overhead of any state management tool for React.
|
|
6
6
|
|
|
7
7
|
We stay DRY so you don't have to.
|
|
8
8
|
|
|
@@ -13,10 +13,14 @@ We stay DRY so you don't have to.
|
|
|
13
13
|
```bash
|
|
14
14
|
# NPM
|
|
15
15
|
npm install @reduxjs/toolkit redux-astroglide
|
|
16
|
+
```
|
|
16
17
|
|
|
18
|
+
```bash
|
|
17
19
|
# Yarn
|
|
18
20
|
yarn add @reduxjs/toolkit redux-astroglide
|
|
21
|
+
```
|
|
19
22
|
|
|
23
|
+
```bash
|
|
20
24
|
# PNPM
|
|
21
25
|
pnpm add @reduxjs/toolkit redux-astroglide
|
|
22
26
|
|
|
@@ -54,10 +58,11 @@ const slice = createSlice(
|
|
|
54
58
|
// initial state
|
|
55
59
|
username: "",
|
|
56
60
|
password: "",
|
|
61
|
+
count: 0,
|
|
57
62
|
}
|
|
58
63
|
);
|
|
59
64
|
|
|
60
|
-
export const {
|
|
65
|
+
export const { setUsername, setPassword } = slice.actions;
|
|
61
66
|
export const { selectUsername, selectPassword } = slice.selectors;
|
|
62
67
|
export const { useUsername, usePassword } = slice.hooks;
|
|
63
68
|
```
|
|
@@ -72,6 +77,7 @@ const slice = createSlice({
|
|
|
72
77
|
initialState: {
|
|
73
78
|
username: "",
|
|
74
79
|
password: "",
|
|
80
|
+
count: 0,
|
|
75
81
|
},
|
|
76
82
|
reducers: {
|
|
77
83
|
// custom reducers are the most likely reason to use this syntax
|
|
@@ -109,12 +115,25 @@ export const UsernameField = (props) => {
|
|
|
109
115
|
name="username"
|
|
110
116
|
type="text"
|
|
111
117
|
value={username}
|
|
112
|
-
onChange={
|
|
118
|
+
onChange={
|
|
119
|
+
(e) => setUsername(e.target.value) // dispatch a redux action named "LoginForm/setUsername"
|
|
120
|
+
}
|
|
113
121
|
/>
|
|
114
122
|
);
|
|
115
123
|
};
|
|
116
124
|
```
|
|
117
125
|
|
|
126
|
+
You can pass a function to the hook to assign a custom value setter for that instance of the hook:
|
|
127
|
+
|
|
128
|
+
```jsx
|
|
129
|
+
// component.js
|
|
130
|
+
function Component() {
|
|
131
|
+
const [count, increment] = useCount((currentCount) => currentCount + 1);
|
|
132
|
+
|
|
133
|
+
// ...
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
118
137
|
|
|
119
138
|
|
|
120
139
|
The setter actions can be passed a function to receive a copy of the latest state value, just like with React's setState:
|
|
@@ -209,7 +228,7 @@ function* loginSaga(action) {
|
|
|
209
228
|
|
|
210
229
|
|
|
211
230
|
|
|
212
|
-
Astroglide also provides some of its internal helper functions
|
|
231
|
+
Astroglide also provides some of its internal helper functions:
|
|
213
232
|
|
|
214
233
|
```jsx
|
|
215
234
|
const configure = "redux-astroglide";
|
|
@@ -217,6 +236,7 @@ const configure = "redux-astroglide";
|
|
|
217
236
|
export const {
|
|
218
237
|
store,
|
|
219
238
|
createSlice,
|
|
239
|
+
|
|
220
240
|
injectReducer, // injectReducer(key: string, state => state: reducer fn, optionally async)
|
|
221
241
|
injectSlice, // injectSlice(slice: result from createSlice())
|
|
222
242
|
injectMiddleware, // injectMiddleware(middleware: redux middleware)
|
|
@@ -227,7 +247,7 @@ export const {
|
|
|
227
247
|
|
|
228
248
|
## Plugins
|
|
229
249
|
|
|
230
|
-
Astroglide
|
|
250
|
+
Astroglide comes with plugins you can use for typechecking, data persistence and custom value and state setters:
|
|
231
251
|
|
|
232
252
|
```jsx
|
|
233
253
|
// Login/slice.js
|
|
@@ -238,10 +258,14 @@ const slice = createSlice("Login", {
|
|
|
238
258
|
|
|
239
259
|
// Nav/slice.js
|
|
240
260
|
const slice = createSlice("Nav", {
|
|
241
|
-
|
|
242
|
-
storageType: localStorage, // default localStorage, must provide { getItem(key):any, setItem(key, value):void } API (async not allowed)
|
|
261
|
+
token: persist("", {
|
|
262
|
+
storageType: localStorage, // default localStorage, or API passed to setup fn, must provide { getItem(key):any, setItem(key, value):void } API (async not allowed)
|
|
243
263
|
}),
|
|
244
264
|
clickCount: set((value) => value + 1),
|
|
265
|
+
instanceCount: set((value, { draft }) => {
|
|
266
|
+
draft.clickCount = 0;
|
|
267
|
+
return value + 1;
|
|
268
|
+
}),
|
|
245
269
|
});
|
|
246
270
|
```
|
|
247
271
|
|
|
@@ -255,13 +279,18 @@ import configure, { addPlugins } from "redux-astroglide";
|
|
|
255
279
|
import setPlugin from "redux-astroglide/plugins/set";
|
|
256
280
|
import typePlugin from "redux-astroglide/plugins/type";
|
|
257
281
|
import persistPlugin from "redux-astroglide/plugins/persist";
|
|
258
|
-
// these can also be imported
|
|
282
|
+
// these can also be imported like:
|
|
259
283
|
// import { set, type, persist } = "redux-astroglide/plugins";
|
|
260
284
|
|
|
261
285
|
export const [set, type, persist] = addPlugins(
|
|
262
286
|
setPlugin(),
|
|
263
287
|
typePlugin({ shouldPreventUpdate: false }),
|
|
264
|
-
persistPlugin(
|
|
288
|
+
persistPlugin({
|
|
289
|
+
storageType: { // defaults to localStorage (async storage not allowed)
|
|
290
|
+
getItem(key: string),
|
|
291
|
+
setItem(key: string, value: string)}
|
|
292
|
+
}
|
|
293
|
+
)
|
|
265
294
|
);
|
|
266
295
|
|
|
267
296
|
export const { store, createSlice } = configure();
|
|
@@ -278,7 +307,8 @@ import {
|
|
|
278
307
|
const currentValue = getPersistedValue(
|
|
279
308
|
"isOpen",
|
|
280
309
|
"Nav"
|
|
281
|
-
// storageType: localStorage | sessionStorage |
|
|
310
|
+
// storageType: localStorage | sessionStorage |
|
|
311
|
+
// { getItem(key: string), setItem(key: string, value:string) }
|
|
282
312
|
);
|
|
283
313
|
|
|
284
314
|
storePersistedValue(
|
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { bindActionCreators, combineReducers, createDraftSafeSelector, configureStore, createSlice } from '@reduxjs/toolkit';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { useDispatch, useSelector, shallowEqual } from 'react-redux';
|
|
3
|
+
import { injectableMiddleware, injectMiddleware } from 'redux-injectable-middleware';
|
|
4
4
|
import { useMemo } from 'react';
|
|
5
5
|
|
|
6
6
|
function ownKeys(object, enumerableOnly) {
|
|
@@ -3591,11 +3591,102 @@ var makeSetterReducersFromInitialState = function makeSetterReducersFromInitialS
|
|
|
3591
3591
|
|
|
3592
3592
|
/* eslint-enable react/forbid-foreign-prop-types */
|
|
3593
3593
|
|
|
3594
|
+
var plugin = function plugin(_ref) {
|
|
3595
|
+
var constructorFn = _ref.constructor,
|
|
3596
|
+
setup = _ref.setup,
|
|
3597
|
+
getInitialValue = _ref.getInitialValue,
|
|
3598
|
+
update = _ref.update,
|
|
3599
|
+
_ref$config = _ref.config,
|
|
3600
|
+
config = _ref$config === void 0 ? {} : _ref$config;
|
|
3601
|
+
return /*#__PURE__*/function () {
|
|
3602
|
+
function _class(value) {
|
|
3603
|
+
_classCallCheck(this, _class);
|
|
3604
|
+
this.value = value;
|
|
3605
|
+
this.setup = setup || this.setup;
|
|
3606
|
+
this.getInitialValue = getInitialValue || this.getInitialValue;
|
|
3607
|
+
this.update = update || this.update;
|
|
3608
|
+
this.config = config;
|
|
3609
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
3610
|
+
args[_key - 1] = arguments[_key];
|
|
3611
|
+
}
|
|
3612
|
+
constructorFn === null || constructorFn === void 0 ? void 0 : constructorFn.call.apply(constructorFn, [this, value].concat(args));
|
|
3613
|
+
}
|
|
3614
|
+
|
|
3615
|
+
// either the initial state value or the next plugin
|
|
3616
|
+
_createClass(_class, [{
|
|
3617
|
+
key: "getValue",
|
|
3618
|
+
value: function getValue() {
|
|
3619
|
+
return this.value;
|
|
3620
|
+
}
|
|
3621
|
+
}, {
|
|
3622
|
+
key: "setValue",
|
|
3623
|
+
value: function setValue(value) {
|
|
3624
|
+
this.value = value;
|
|
3625
|
+
}
|
|
3626
|
+
}, {
|
|
3627
|
+
key: "setConfig",
|
|
3628
|
+
value: function setConfig(config) {
|
|
3629
|
+
this.config = _objectSpread2(_objectSpread2({}, this.config), config);
|
|
3630
|
+
}
|
|
3631
|
+
}, {
|
|
3632
|
+
key: "setup",
|
|
3633
|
+
value: function setup(item, _ref2) {
|
|
3634
|
+
_objectDestructuringEmpty(_ref2);
|
|
3635
|
+
return {
|
|
3636
|
+
plugin: item
|
|
3637
|
+
};
|
|
3638
|
+
}
|
|
3639
|
+
}, {
|
|
3640
|
+
key: "getInitialValue",
|
|
3641
|
+
value: function getInitialValue(value, _ref3) {
|
|
3642
|
+
_objectDestructuringEmpty(_ref3);
|
|
3643
|
+
return value;
|
|
3644
|
+
}
|
|
3645
|
+
}, {
|
|
3646
|
+
key: "update",
|
|
3647
|
+
value: function update(value, _ref4) {
|
|
3648
|
+
_objectDestructuringEmpty(_ref4);
|
|
3649
|
+
return value;
|
|
3650
|
+
}
|
|
3651
|
+
}]);
|
|
3652
|
+
return _class;
|
|
3653
|
+
}();
|
|
3654
|
+
};
|
|
3655
|
+
var addPlugin = function addPlugin(config) {
|
|
3656
|
+
var Class = plugin(config);
|
|
3657
|
+
plugins.push(Class);
|
|
3658
|
+
return function () {
|
|
3659
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
3660
|
+
args[_key2] = arguments[_key2];
|
|
3661
|
+
}
|
|
3662
|
+
return _construct(Class, args);
|
|
3663
|
+
};
|
|
3664
|
+
};
|
|
3665
|
+
var addPlugins = function addPlugins() {
|
|
3666
|
+
for (var _len3 = arguments.length, configs = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
3667
|
+
configs[_key3] = arguments[_key3];
|
|
3668
|
+
}
|
|
3669
|
+
return configs.map(addPlugin);
|
|
3670
|
+
};
|
|
3671
|
+
var plugins = [];
|
|
3672
|
+
|
|
3673
|
+
var makeSelectorHook = function makeSelectorHook(selector) {
|
|
3674
|
+
return function () {
|
|
3675
|
+
return useSelector(selector, shallowEqual);
|
|
3676
|
+
};
|
|
3677
|
+
};
|
|
3594
3678
|
var createSelectorUpdateHook = function createSelectorUpdateHook(selector, action) {
|
|
3595
3679
|
return function () {
|
|
3596
3680
|
return [useSelector(selector), useAction(action, undefined)];
|
|
3597
3681
|
};
|
|
3598
3682
|
};
|
|
3683
|
+
var createSelectorHook = function createSelectorHook() {
|
|
3684
|
+
// creates a redux selector and a react hook that produce identical results
|
|
3685
|
+
var selector = createDraftSafeSelector.apply(void 0, arguments);
|
|
3686
|
+
var hook = makeSelectorHook(selector);
|
|
3687
|
+
hook.select = selector;
|
|
3688
|
+
return hook;
|
|
3689
|
+
};
|
|
3599
3690
|
var configure$1 = function configure(store) {
|
|
3600
3691
|
var makeDomainSelector = function makeDomainSelector(name, initialState) {
|
|
3601
3692
|
return function (state) {
|
|
@@ -3651,7 +3742,12 @@ var configure$1 = function configure(store) {
|
|
|
3651
3742
|
throw Error("Action ".concat(slice.name, "/").concat(actionName, " not defined"));
|
|
3652
3743
|
}
|
|
3653
3744
|
var useState = function useState() {
|
|
3654
|
-
|
|
3745
|
+
var setterCb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function (value) {
|
|
3746
|
+
return value;
|
|
3747
|
+
};
|
|
3748
|
+
return [useSelector(selector), useAction(function (value) {
|
|
3749
|
+
return updateAction(setterCb(value));
|
|
3750
|
+
}, undefined)];
|
|
3655
3751
|
};
|
|
3656
3752
|
useState.select = selector;
|
|
3657
3753
|
useState.update = updateAction;
|
|
@@ -3679,108 +3775,24 @@ var configure$1 = function configure(store) {
|
|
|
3679
3775
|
};
|
|
3680
3776
|
};
|
|
3681
3777
|
|
|
3682
|
-
var
|
|
3683
|
-
var constructorFn = _ref.constructor,
|
|
3684
|
-
setup = _ref.setup,
|
|
3685
|
-
getInitialValue = _ref.getInitialValue,
|
|
3686
|
-
update = _ref.update,
|
|
3687
|
-
_ref$config = _ref.config,
|
|
3688
|
-
config = _ref$config === void 0 ? {} : _ref$config;
|
|
3689
|
-
return /*#__PURE__*/function () {
|
|
3690
|
-
function _class(value) {
|
|
3691
|
-
_classCallCheck(this, _class);
|
|
3692
|
-
this.value = value;
|
|
3693
|
-
this.setup = setup || this.setup;
|
|
3694
|
-
this.getInitialValue = getInitialValue || this.getInitialValue;
|
|
3695
|
-
this.update = update || this.update;
|
|
3696
|
-
this.config = config;
|
|
3697
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
3698
|
-
args[_key - 1] = arguments[_key];
|
|
3699
|
-
}
|
|
3700
|
-
constructorFn === null || constructorFn === void 0 ? void 0 : constructorFn.call.apply(constructorFn, [this, value].concat(args));
|
|
3701
|
-
}
|
|
3702
|
-
|
|
3703
|
-
// either the initial state value or the next plugin
|
|
3704
|
-
_createClass(_class, [{
|
|
3705
|
-
key: "getValue",
|
|
3706
|
-
value: function getValue() {
|
|
3707
|
-
return this.value;
|
|
3708
|
-
}
|
|
3709
|
-
}, {
|
|
3710
|
-
key: "setValue",
|
|
3711
|
-
value: function setValue(value) {
|
|
3712
|
-
this.value = value;
|
|
3713
|
-
}
|
|
3714
|
-
}, {
|
|
3715
|
-
key: "setConfig",
|
|
3716
|
-
value: function setConfig(config) {
|
|
3717
|
-
this.config = _objectSpread2(_objectSpread2({}, this.config), config);
|
|
3718
|
-
}
|
|
3719
|
-
}, {
|
|
3720
|
-
key: "setup",
|
|
3721
|
-
value: function setup(item, _ref2) {
|
|
3722
|
-
_objectDestructuringEmpty(_ref2);
|
|
3723
|
-
return {
|
|
3724
|
-
plugin: item
|
|
3725
|
-
};
|
|
3726
|
-
}
|
|
3727
|
-
}, {
|
|
3728
|
-
key: "getInitialValue",
|
|
3729
|
-
value: function getInitialValue(value, _ref3) {
|
|
3730
|
-
_objectDestructuringEmpty(_ref3);
|
|
3731
|
-
return value;
|
|
3732
|
-
}
|
|
3733
|
-
}, {
|
|
3734
|
-
key: "update",
|
|
3735
|
-
value: function update(value, _ref4) {
|
|
3736
|
-
_objectDestructuringEmpty(_ref4);
|
|
3737
|
-
return value;
|
|
3738
|
-
}
|
|
3739
|
-
}]);
|
|
3740
|
-
return _class;
|
|
3741
|
-
}();
|
|
3742
|
-
};
|
|
3743
|
-
var addPlugin = function addPlugin(config) {
|
|
3744
|
-
var Class = plugin(config);
|
|
3745
|
-
plugins.push(Class);
|
|
3746
|
-
return function () {
|
|
3747
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
3748
|
-
args[_key2] = arguments[_key2];
|
|
3749
|
-
}
|
|
3750
|
-
return _construct(Class, args);
|
|
3751
|
-
};
|
|
3752
|
-
};
|
|
3753
|
-
var addPlugins = function addPlugins() {
|
|
3754
|
-
for (var _len3 = arguments.length, configs = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
3755
|
-
configs[_key3] = arguments[_key3];
|
|
3756
|
-
}
|
|
3757
|
-
return configs.map(addPlugin);
|
|
3758
|
-
};
|
|
3759
|
-
var plugins = [];
|
|
3760
|
-
|
|
3761
|
-
var _excluded = ["middleware", "reducer", "devTools", "preloadedState", "enhancers"],
|
|
3778
|
+
var _excluded = ["middleware", "devTools", "preloadedState", "enhancers"],
|
|
3762
3779
|
_excluded2 = ["selectDomain"];
|
|
3763
3780
|
var configure = function configure(_ref) {
|
|
3764
3781
|
var _middleware = _ref.middleware,
|
|
3765
|
-
reducer = _ref.reducer,
|
|
3766
3782
|
devTools = _ref.devTools,
|
|
3767
3783
|
preloadedState = _ref.preloadedState,
|
|
3768
3784
|
enhancers = _ref.enhancers,
|
|
3769
3785
|
staticReducers = _objectWithoutProperties(_ref, _excluded);
|
|
3770
|
-
var store = configureStore(
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
return state;
|
|
3774
|
-
}
|
|
3775
|
-
}), {}, {
|
|
3776
|
-
// @ts-ignore
|
|
3786
|
+
var store = configureStore({
|
|
3787
|
+
// @ts-ignore-next-line
|
|
3788
|
+
reducer: combineReducers(staticReducers),
|
|
3777
3789
|
middleware: function middleware(getDefaultMiddleware) {
|
|
3778
3790
|
return [].concat(_toConsumableArray(typeof _middleware === "function" ? _middleware(getDefaultMiddleware) : _middleware || []), [injectableMiddleware]);
|
|
3779
3791
|
},
|
|
3780
3792
|
devTools: devTools,
|
|
3781
3793
|
preloadedState: preloadedState,
|
|
3782
3794
|
enhancers: enhancers
|
|
3783
|
-
})
|
|
3795
|
+
});
|
|
3784
3796
|
var _configureSelectors = configure$1(store),
|
|
3785
3797
|
makePropertySelectorsFromSlice = _configureSelectors.makePropertySelectorsFromSlice;
|
|
3786
3798
|
var injectSlice$1 = function injectSlice$1(slice) {
|
|
@@ -3889,7 +3901,7 @@ var configure = function configure(_ref) {
|
|
|
3889
3901
|
|
|
3890
3902
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
3891
3903
|
hooks[domainHookKey] = function () {
|
|
3892
|
-
return [useAction(slice.actions[sliceSetterKey], undefined).apply(void 0, _toConsumableArray(getParams())),
|
|
3904
|
+
return [useSelector(selectDomain), useAction(slice.actions[sliceSetterKey], undefined).apply(void 0, _toConsumableArray(getParams())),
|
|
3893
3905
|
// prop updater
|
|
3894
3906
|
useAction(slice.actions.__override__slice__caution, undefined) // state overwriter
|
|
3895
3907
|
];
|
|
@@ -3930,4 +3942,4 @@ var configure = function configure(_ref) {
|
|
|
3930
3942
|
};
|
|
3931
3943
|
};
|
|
3932
3944
|
|
|
3933
|
-
export { addPlugin, addPlugins, configure, createSelectorUpdateHook, configure as default, plugins };
|
|
3945
|
+
export { addPlugin, addPlugins, configure, createSelectorHook, createSelectorUpdateHook, configure as default, plugins };
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var toolkit = require('@reduxjs/toolkit');
|
|
6
|
-
var reduxInjectableMiddleware = require('redux-injectable-middleware');
|
|
7
6
|
var reactRedux = require('react-redux');
|
|
7
|
+
var reduxInjectableMiddleware = require('redux-injectable-middleware');
|
|
8
8
|
var react = require('react');
|
|
9
9
|
|
|
10
10
|
function ownKeys(object, enumerableOnly) {
|
|
@@ -3595,11 +3595,102 @@ var makeSetterReducersFromInitialState = function makeSetterReducersFromInitialS
|
|
|
3595
3595
|
|
|
3596
3596
|
/* eslint-enable react/forbid-foreign-prop-types */
|
|
3597
3597
|
|
|
3598
|
+
var plugin = function plugin(_ref) {
|
|
3599
|
+
var constructorFn = _ref.constructor,
|
|
3600
|
+
setup = _ref.setup,
|
|
3601
|
+
getInitialValue = _ref.getInitialValue,
|
|
3602
|
+
update = _ref.update,
|
|
3603
|
+
_ref$config = _ref.config,
|
|
3604
|
+
config = _ref$config === void 0 ? {} : _ref$config;
|
|
3605
|
+
return /*#__PURE__*/function () {
|
|
3606
|
+
function _class(value) {
|
|
3607
|
+
_classCallCheck(this, _class);
|
|
3608
|
+
this.value = value;
|
|
3609
|
+
this.setup = setup || this.setup;
|
|
3610
|
+
this.getInitialValue = getInitialValue || this.getInitialValue;
|
|
3611
|
+
this.update = update || this.update;
|
|
3612
|
+
this.config = config;
|
|
3613
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
3614
|
+
args[_key - 1] = arguments[_key];
|
|
3615
|
+
}
|
|
3616
|
+
constructorFn === null || constructorFn === void 0 ? void 0 : constructorFn.call.apply(constructorFn, [this, value].concat(args));
|
|
3617
|
+
}
|
|
3618
|
+
|
|
3619
|
+
// either the initial state value or the next plugin
|
|
3620
|
+
_createClass(_class, [{
|
|
3621
|
+
key: "getValue",
|
|
3622
|
+
value: function getValue() {
|
|
3623
|
+
return this.value;
|
|
3624
|
+
}
|
|
3625
|
+
}, {
|
|
3626
|
+
key: "setValue",
|
|
3627
|
+
value: function setValue(value) {
|
|
3628
|
+
this.value = value;
|
|
3629
|
+
}
|
|
3630
|
+
}, {
|
|
3631
|
+
key: "setConfig",
|
|
3632
|
+
value: function setConfig(config) {
|
|
3633
|
+
this.config = _objectSpread2(_objectSpread2({}, this.config), config);
|
|
3634
|
+
}
|
|
3635
|
+
}, {
|
|
3636
|
+
key: "setup",
|
|
3637
|
+
value: function setup(item, _ref2) {
|
|
3638
|
+
_objectDestructuringEmpty(_ref2);
|
|
3639
|
+
return {
|
|
3640
|
+
plugin: item
|
|
3641
|
+
};
|
|
3642
|
+
}
|
|
3643
|
+
}, {
|
|
3644
|
+
key: "getInitialValue",
|
|
3645
|
+
value: function getInitialValue(value, _ref3) {
|
|
3646
|
+
_objectDestructuringEmpty(_ref3);
|
|
3647
|
+
return value;
|
|
3648
|
+
}
|
|
3649
|
+
}, {
|
|
3650
|
+
key: "update",
|
|
3651
|
+
value: function update(value, _ref4) {
|
|
3652
|
+
_objectDestructuringEmpty(_ref4);
|
|
3653
|
+
return value;
|
|
3654
|
+
}
|
|
3655
|
+
}]);
|
|
3656
|
+
return _class;
|
|
3657
|
+
}();
|
|
3658
|
+
};
|
|
3659
|
+
var addPlugin = function addPlugin(config) {
|
|
3660
|
+
var Class = plugin(config);
|
|
3661
|
+
plugins.push(Class);
|
|
3662
|
+
return function () {
|
|
3663
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
3664
|
+
args[_key2] = arguments[_key2];
|
|
3665
|
+
}
|
|
3666
|
+
return _construct(Class, args);
|
|
3667
|
+
};
|
|
3668
|
+
};
|
|
3669
|
+
var addPlugins = function addPlugins() {
|
|
3670
|
+
for (var _len3 = arguments.length, configs = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
3671
|
+
configs[_key3] = arguments[_key3];
|
|
3672
|
+
}
|
|
3673
|
+
return configs.map(addPlugin);
|
|
3674
|
+
};
|
|
3675
|
+
var plugins = [];
|
|
3676
|
+
|
|
3677
|
+
var makeSelectorHook = function makeSelectorHook(selector) {
|
|
3678
|
+
return function () {
|
|
3679
|
+
return reactRedux.useSelector(selector, reactRedux.shallowEqual);
|
|
3680
|
+
};
|
|
3681
|
+
};
|
|
3598
3682
|
var createSelectorUpdateHook = function createSelectorUpdateHook(selector, action) {
|
|
3599
3683
|
return function () {
|
|
3600
3684
|
return [reactRedux.useSelector(selector), useAction(action, undefined)];
|
|
3601
3685
|
};
|
|
3602
3686
|
};
|
|
3687
|
+
var createSelectorHook = function createSelectorHook() {
|
|
3688
|
+
// creates a redux selector and a react hook that produce identical results
|
|
3689
|
+
var selector = toolkit.createDraftSafeSelector.apply(void 0, arguments);
|
|
3690
|
+
var hook = makeSelectorHook(selector);
|
|
3691
|
+
hook.select = selector;
|
|
3692
|
+
return hook;
|
|
3693
|
+
};
|
|
3603
3694
|
var configure$1 = function configure(store) {
|
|
3604
3695
|
var makeDomainSelector = function makeDomainSelector(name, initialState) {
|
|
3605
3696
|
return function (state) {
|
|
@@ -3655,7 +3746,12 @@ var configure$1 = function configure(store) {
|
|
|
3655
3746
|
throw Error("Action ".concat(slice.name, "/").concat(actionName, " not defined"));
|
|
3656
3747
|
}
|
|
3657
3748
|
var useState = function useState() {
|
|
3658
|
-
|
|
3749
|
+
var setterCb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function (value) {
|
|
3750
|
+
return value;
|
|
3751
|
+
};
|
|
3752
|
+
return [reactRedux.useSelector(selector), useAction(function (value) {
|
|
3753
|
+
return updateAction(setterCb(value));
|
|
3754
|
+
}, undefined)];
|
|
3659
3755
|
};
|
|
3660
3756
|
useState.select = selector;
|
|
3661
3757
|
useState.update = updateAction;
|
|
@@ -3683,108 +3779,24 @@ var configure$1 = function configure(store) {
|
|
|
3683
3779
|
};
|
|
3684
3780
|
};
|
|
3685
3781
|
|
|
3686
|
-
var
|
|
3687
|
-
var constructorFn = _ref.constructor,
|
|
3688
|
-
setup = _ref.setup,
|
|
3689
|
-
getInitialValue = _ref.getInitialValue,
|
|
3690
|
-
update = _ref.update,
|
|
3691
|
-
_ref$config = _ref.config,
|
|
3692
|
-
config = _ref$config === void 0 ? {} : _ref$config;
|
|
3693
|
-
return /*#__PURE__*/function () {
|
|
3694
|
-
function _class(value) {
|
|
3695
|
-
_classCallCheck(this, _class);
|
|
3696
|
-
this.value = value;
|
|
3697
|
-
this.setup = setup || this.setup;
|
|
3698
|
-
this.getInitialValue = getInitialValue || this.getInitialValue;
|
|
3699
|
-
this.update = update || this.update;
|
|
3700
|
-
this.config = config;
|
|
3701
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
3702
|
-
args[_key - 1] = arguments[_key];
|
|
3703
|
-
}
|
|
3704
|
-
constructorFn === null || constructorFn === void 0 ? void 0 : constructorFn.call.apply(constructorFn, [this, value].concat(args));
|
|
3705
|
-
}
|
|
3706
|
-
|
|
3707
|
-
// either the initial state value or the next plugin
|
|
3708
|
-
_createClass(_class, [{
|
|
3709
|
-
key: "getValue",
|
|
3710
|
-
value: function getValue() {
|
|
3711
|
-
return this.value;
|
|
3712
|
-
}
|
|
3713
|
-
}, {
|
|
3714
|
-
key: "setValue",
|
|
3715
|
-
value: function setValue(value) {
|
|
3716
|
-
this.value = value;
|
|
3717
|
-
}
|
|
3718
|
-
}, {
|
|
3719
|
-
key: "setConfig",
|
|
3720
|
-
value: function setConfig(config) {
|
|
3721
|
-
this.config = _objectSpread2(_objectSpread2({}, this.config), config);
|
|
3722
|
-
}
|
|
3723
|
-
}, {
|
|
3724
|
-
key: "setup",
|
|
3725
|
-
value: function setup(item, _ref2) {
|
|
3726
|
-
_objectDestructuringEmpty(_ref2);
|
|
3727
|
-
return {
|
|
3728
|
-
plugin: item
|
|
3729
|
-
};
|
|
3730
|
-
}
|
|
3731
|
-
}, {
|
|
3732
|
-
key: "getInitialValue",
|
|
3733
|
-
value: function getInitialValue(value, _ref3) {
|
|
3734
|
-
_objectDestructuringEmpty(_ref3);
|
|
3735
|
-
return value;
|
|
3736
|
-
}
|
|
3737
|
-
}, {
|
|
3738
|
-
key: "update",
|
|
3739
|
-
value: function update(value, _ref4) {
|
|
3740
|
-
_objectDestructuringEmpty(_ref4);
|
|
3741
|
-
return value;
|
|
3742
|
-
}
|
|
3743
|
-
}]);
|
|
3744
|
-
return _class;
|
|
3745
|
-
}();
|
|
3746
|
-
};
|
|
3747
|
-
var addPlugin = function addPlugin(config) {
|
|
3748
|
-
var Class = plugin(config);
|
|
3749
|
-
plugins.push(Class);
|
|
3750
|
-
return function () {
|
|
3751
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
3752
|
-
args[_key2] = arguments[_key2];
|
|
3753
|
-
}
|
|
3754
|
-
return _construct(Class, args);
|
|
3755
|
-
};
|
|
3756
|
-
};
|
|
3757
|
-
var addPlugins = function addPlugins() {
|
|
3758
|
-
for (var _len3 = arguments.length, configs = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
3759
|
-
configs[_key3] = arguments[_key3];
|
|
3760
|
-
}
|
|
3761
|
-
return configs.map(addPlugin);
|
|
3762
|
-
};
|
|
3763
|
-
var plugins = [];
|
|
3764
|
-
|
|
3765
|
-
var _excluded = ["middleware", "reducer", "devTools", "preloadedState", "enhancers"],
|
|
3782
|
+
var _excluded = ["middleware", "devTools", "preloadedState", "enhancers"],
|
|
3766
3783
|
_excluded2 = ["selectDomain"];
|
|
3767
3784
|
var configure = function configure(_ref) {
|
|
3768
3785
|
var _middleware = _ref.middleware,
|
|
3769
|
-
reducer = _ref.reducer,
|
|
3770
3786
|
devTools = _ref.devTools,
|
|
3771
3787
|
preloadedState = _ref.preloadedState,
|
|
3772
3788
|
enhancers = _ref.enhancers,
|
|
3773
3789
|
staticReducers = _objectWithoutProperties(_ref, _excluded);
|
|
3774
|
-
var store = toolkit.configureStore(
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
return state;
|
|
3778
|
-
}
|
|
3779
|
-
}), {}, {
|
|
3780
|
-
// @ts-ignore
|
|
3790
|
+
var store = toolkit.configureStore({
|
|
3791
|
+
// @ts-ignore-next-line
|
|
3792
|
+
reducer: toolkit.combineReducers(staticReducers),
|
|
3781
3793
|
middleware: function middleware(getDefaultMiddleware) {
|
|
3782
3794
|
return [].concat(_toConsumableArray(typeof _middleware === "function" ? _middleware(getDefaultMiddleware) : _middleware || []), [reduxInjectableMiddleware.injectableMiddleware]);
|
|
3783
3795
|
},
|
|
3784
3796
|
devTools: devTools,
|
|
3785
3797
|
preloadedState: preloadedState,
|
|
3786
3798
|
enhancers: enhancers
|
|
3787
|
-
})
|
|
3799
|
+
});
|
|
3788
3800
|
var _configureSelectors = configure$1(store),
|
|
3789
3801
|
makePropertySelectorsFromSlice = _configureSelectors.makePropertySelectorsFromSlice;
|
|
3790
3802
|
var injectSlice$1 = function injectSlice$1(slice) {
|
|
@@ -3893,7 +3905,7 @@ var configure = function configure(_ref) {
|
|
|
3893
3905
|
|
|
3894
3906
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
3895
3907
|
hooks[domainHookKey] = function () {
|
|
3896
|
-
return [useAction(slice.actions[sliceSetterKey], undefined).apply(void 0, _toConsumableArray(getParams())),
|
|
3908
|
+
return [reactRedux.useSelector(selectDomain), useAction(slice.actions[sliceSetterKey], undefined).apply(void 0, _toConsumableArray(getParams())),
|
|
3897
3909
|
// prop updater
|
|
3898
3910
|
useAction(slice.actions.__override__slice__caution, undefined) // state overwriter
|
|
3899
3911
|
];
|
|
@@ -3937,6 +3949,7 @@ var configure = function configure(_ref) {
|
|
|
3937
3949
|
exports.addPlugin = addPlugin;
|
|
3938
3950
|
exports.addPlugins = addPlugins;
|
|
3939
3951
|
exports.configure = configure;
|
|
3952
|
+
exports.createSelectorHook = createSelectorHook;
|
|
3940
3953
|
exports.createSelectorUpdateHook = createSelectorUpdateHook;
|
|
3941
3954
|
exports["default"] = configure;
|
|
3942
3955
|
exports.plugins = plugins;
|