@lowentry/react-redux 0.2.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/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # @lowentry/react-redux
2
+
3
+ Simplifies the use of Redux in your React project.
4
+
5
+ ## Description
6
+
7
+ This plugin will add utility functions to make it easier to use Redux in your React project.
8
+
9
+ For example, some of the things it does is:
10
+
11
+ - it combines React, Redux, ReactRedux, RTK, etc, functions into a single object, so you won't have to figure out where it is located anymore, you simply call LeRed.functionName.
12
+ - it provides improvements to the regular Redux functions, such as `createSlice` (allowing you to call those actions directly), and `useEffect` (solving the comparison of the given dependencies' values using `fast-deep-equal/react`, rather than doing a shallow compare).
13
+ - it provides lots of helper functions, such as `useEffectInterval` (which is a combination of `useEffect` and `setInterval`).
14
+ - it automatically adds support for Redux-Saga to your Redux code, allowing you to call other Redux actions from within a Redux action (as well as the host of other things that Redux-Saga can do, such as obtain the data from selectors, run delays, etc).
15
+
16
+ All of this basically just:
17
+ 1. cleans up your code
18
+ 2. provides more powerful features to React and Redux
19
+ 3. improves consistency
20
+ 4. and makes it easier to work with React and Redux in your projects.
21
+
22
+ ### Example
23
+
24
+ ```javascript
25
+ // ./src/pages/index.js
26
+ import {LeRed} from '@lowentry/react-redux';
27
+ import {stateTimer} from '../state/stateTimer.js';
28
+ import {App} from '../components/App.jsx';
29
+
30
+ export const Head = () => (
31
+ <title>Home Page</title>
32
+ );
33
+
34
+ export default LeRed.memo(({}) =>
35
+ {
36
+ const store = LeRed.useConfigureStore({slices:{stateTimer}});
37
+ return (
38
+ <LeRed.Root store={store}>
39
+ <App/>
40
+ </LeRed.Root>
41
+ );
42
+ });
43
+ ```
44
+
45
+ ```javascript
46
+ // ./src/state/stateTimer.js
47
+ import {LeRed} from '@lowentry/react-redux';
48
+
49
+ export const stateTimer = LeRed.createSlice
50
+ ({
51
+ state:
52
+ {
53
+ counter:0,
54
+ },
55
+ actions:
56
+ {
57
+ reset:
58
+ (state) =>
59
+ {
60
+ state.counter = 0;
61
+ },
62
+
63
+ increase:
64
+ (state, data) =>
65
+ {
66
+ state.counter += (data ?? 1);
67
+ },
68
+
69
+ decrease:
70
+ (state, data) =>
71
+ {
72
+ state.counter -= (data ?? 1);
73
+ },
74
+
75
+ waitAndIncrease:
76
+ function* (data)
77
+ {
78
+ const seconds = (data ?? 1);
79
+ yield LeRed.effects.delay(seconds * 1000);
80
+ yield LeRed.effects.put(stateTimer.actions.increase(seconds));
81
+ },
82
+ },
83
+ selectors:
84
+ {
85
+ counter:
86
+ state => state.counter,
87
+ },
88
+ });
89
+ ```
90
+
91
+ ```javascript
92
+ // ./src/components/App.jsx
93
+ import {LeRed} from '@lowentry/react-redux';
94
+ import {Button} from '@mui/material';
95
+ import {stateTimer} from '../state/stateTimer.js';
96
+
97
+ export const App = LeRed.memo(({}) =>
98
+ {
99
+ const dispatch = LeRed.useDispatch();
100
+ const counter = LeRed.useSelector(stateTimer.selectors.counter);
101
+ const previousCounter = LeRed.usePrevious(counter);
102
+
103
+ LeRed.useEffectInterval(() =>
104
+ {
105
+ dispatch(stateTimer.actions.increase(1));
106
+ }, [], 1000);
107
+
108
+ return (
109
+ <div>
110
+ Seconds: {counter}<br/>
111
+ {(typeof previousCounter !== 'undefined') && (<>Previously: {previousCounter}<br/></>)}
112
+ <br/>
113
+ <Button color="primary" variant="contained" size="small" onClick={() => dispatch(stateTimer.actions.reset())}>Reset</Button><br/>
114
+ </div>
115
+ );
116
+ });
117
+ ```
118
+
119
+ ## Final words
120
+
121
+ I hope this plugin will be useful to you. If you have any questions or suggestions, feel free to contact me at [LowEntry.com](https://lowentry.com/).
@@ -0,0 +1,19 @@
1
+ image: node:lts
2
+
3
+ pipelines:
4
+ default:
5
+ - step:
6
+ name: Build and Test
7
+ script:
8
+ - npm install
9
+ - npm test
10
+ - step:
11
+ name: Publish
12
+ deployment: production
13
+ script:
14
+ - npm version patch -m "Upgrade to %s [skip ci]"
15
+ - git push && git push --tags
16
+ - pipe: atlassian/npm-publish:1.1.0
17
+ variables:
18
+ NPM_TOKEN: $NPM_TOKEN
19
+ EXTRA_ARGS: "--access public"
package/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import {LeRed} from './LeRed.js';
2
+ import {LeUtils} from './LeUtils.js';
3
+ import {ISSET, IS_ARRAY, ARRAY, IS_OBJECT, OBJECT, STRING, STRING_ANY, INT, INT_ANY, FLOAT, FLOAT_ANY, INT_LAX, INT_LAX_ANY, FLOAT_LAX, FLOAT_LAX_ANY} from './LeTypes.js';
4
+
5
+ export {LeRed, LeUtils, ISSET, IS_ARRAY, ARRAY, IS_OBJECT, OBJECT, STRING, STRING_ANY, INT, INT_ANY, FLOAT, FLOAT_ANY, INT_LAX, INT_LAX_ANY, FLOAT_LAX, FLOAT_LAX_ANY};
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@lowentry/react-redux",
3
+ "version": "0.2.2",
4
+ "private": false,
5
+ "type": "module",
6
+ "description": "A plugin for React and Redux, to make it easier to create new components and state code.",
7
+ "author": "Low Entry",
8
+ "license": "MIT",
9
+ "keywords": [
10
+ "react",
11
+ "redux",
12
+ "saga",
13
+ "plugin",
14
+ "utility",
15
+ "states",
16
+ "slices"
17
+ ],
18
+ "homepage": "https://bitbucket.org/lowentry/plugin_javascript_lered/src",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://bitbucket.org/lowentry/plugin_javascript_lered/src"
22
+ },
23
+ "scripts": {
24
+ "test": "node --check index.js"
25
+ },
26
+ "dependencies": {
27
+ "@reduxjs/toolkit": "*",
28
+ "fast-deep-equal": "^3",
29
+ "react": "^18",
30
+ "react-dom": "*",
31
+ "react-redux": "*",
32
+ "redux": "^5",
33
+ "redux-saga": "*"
34
+ }
35
+ }