@kashcode/reduxish 0.1.0 → 0.2.0
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/helpers.js +1 -1
- package/package.json +2 -2
- package/readme.md +33 -45
package/dist/helpers.js
CHANGED
|
@@ -22,7 +22,7 @@ function combineReducers(reducerMap) {
|
|
|
22
22
|
function applyMiddleware(middlewares) {
|
|
23
23
|
return function (storeCreator) { return function (reducer, intialState) {
|
|
24
24
|
var store = storeCreator(reducer, intialState);
|
|
25
|
-
middlewares.reverse().forEach(function (middleware) {
|
|
25
|
+
middlewares.concat().reverse().forEach(function (middleware) {
|
|
26
26
|
store.dispatch = middleware(store)(store.dispatch);
|
|
27
27
|
});
|
|
28
28
|
return store;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kashcode/reduxish",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A tiny, fully-typed Redux-inspired state management library with
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "A tiny, fully-typed Redux-inspired state management library with store enhancement/plugin support for functionality such as thunking, logging, etc with full type inference on the enhanced store. Complies with flux architecture and fully compatible with react-redux bindings.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"exports": {
|
package/readme.md
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
# 🧃
|
|
1
|
+
# 🧃 Reduxish
|
|
2
2
|
|
|
3
|
-
A
|
|
4
|
-
|
|
5
|
-
Think Redux, but:
|
|
6
|
-
|
|
7
|
-
- smaller
|
|
8
|
-
- friendlier
|
|
9
|
-
- aggressively typed
|
|
10
|
-
- and not afraid to smile
|
|
3
|
+
A tiny, fully-typed Redux-inspired state management library with **store enhancement/plugin support for functionality such as thunking, logging, etc with full type inference on the enhanced store.** Complies with flux architecture and fully compatible with react-redux bindings.
|
|
11
4
|
|
|
12
5
|
---
|
|
13
6
|
|
|
@@ -17,23 +10,10 @@ Think Redux, but:
|
|
|
17
10
|
|
|
18
11
|
Create a store with a **strongly‑typed state**, a **typed dispatch**, and a **simple subscription model**.
|
|
19
12
|
|
|
20
|
-
|
|
21
|
-
- `subscribe(listener)` – react to state changes
|
|
22
|
-
- `getState()` – read the current state safely
|
|
23
|
-
|
|
24
|
-
All fully inferred from your reducers. No `any`. No guessing.
|
|
25
|
-
|
|
26
|
-
---
|
|
27
|
-
|
|
28
|
-
### 🧩 Combine Reducers
|
|
29
|
-
|
|
13
|
+
#### 🧩 Combine Reducers
|
|
30
14
|
Split your state into logical slices and merge them into a single root reducer.
|
|
15
|
+
- Store root state shape is automatically inferred from slices
|
|
31
16
|
|
|
32
|
-
- Each reducer owns its slice
|
|
33
|
-
- State shape is automatically inferred
|
|
34
|
-
- Action unions flow through cleanly
|
|
35
|
-
|
|
36
|
-
Your root state type is built for you. Like magic, but TypeScript.
|
|
37
17
|
|
|
38
18
|
---
|
|
39
19
|
|
|
@@ -44,43 +24,51 @@ Intercept actions before they hit your reducers.
|
|
|
44
24
|
Perfect for:
|
|
45
25
|
|
|
46
26
|
- logging
|
|
47
|
-
- async flows
|
|
27
|
+
- thunking/async flows
|
|
48
28
|
- side‑effects
|
|
49
29
|
- analytics
|
|
50
|
-
- chaos (controlled chaos)
|
|
51
30
|
|
|
52
31
|
Middlewares are:
|
|
53
32
|
|
|
54
33
|
- composable
|
|
55
|
-
-
|
|
56
|
-
- fully typed from `dispatch` to `next`
|
|
34
|
+
- fully typed
|
|
57
35
|
|
|
58
|
-
|
|
36
|
+
Use ```applyMiddleware``` utility to compose middlewares. This utility also infers the dispatch extensions applied by the middleware via ```InferDispatchExtensionsFromMiddlewareArray``` recursive helper type (caveat: middlewares should be defined as a tuple for inference to work)
|
|
59
37
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
38
|
+
##### Create store example with sotre enhancment/middelware support:
|
|
39
|
+
```
|
|
40
|
+
const middlewares = [resolveMiddleware, loggerMiddleware] as const;
|
|
41
|
+
const store = createStore(
|
|
42
|
+
todoApp,
|
|
43
|
+
{
|
|
44
|
+
todos: []
|
|
45
|
+
},
|
|
46
|
+
applyMiddleware(middlewares),
|
|
47
|
+
);
|
|
48
|
+
```
|
|
65
49
|
|
|
66
|
-
|
|
67
|
-
- selecting slices of state efficiently
|
|
68
|
-
- avoiding unnecessary re‑renders
|
|
50
|
+
---
|
|
69
51
|
|
|
70
|
-
|
|
52
|
+
### ⚛️ Using with React?
|
|
71
53
|
|
|
72
|
-
|
|
54
|
+
Continue using your usual react-redux hook bindings, no changes required!
|
|
73
55
|
|
|
56
|
+
- useDispatch, useSelector all work out of the box
|
|
57
|
+
- use typed versions of hooks by using our inferred types with react-redux "withTypes" utility
|
|
58
|
+
- i.e
|
|
59
|
+
```
|
|
60
|
+
type AppDispatch = typeof store.dispatch
|
|
61
|
+
type RootState = ReturnType<typeof store.getState>
|
|
62
|
+
export const useAppDispatch = useDispatch.withTypes<AppDispatch>()
|
|
63
|
+
export const useAppSelector = useSelector.withTypes<RootState>()
|
|
64
|
+
```
|
|
74
65
|
---
|
|
75
66
|
|
|
76
67
|
## 📦 Installation
|
|
77
68
|
|
|
78
69
|
```bash
|
|
79
|
-
npm install
|
|
70
|
+
npm install @kashcode/reduxish
|
|
80
71
|
```
|
|
72
|
+
---
|
|
81
73
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
```bash
|
|
85
|
-
pnpm add tiny-state-big-vibes
|
|
86
|
-
```
|
|
74
|
+
#### 📦 Note: this is a hobby project (not for production use). It is primarily to illustrate the simplicity of building a "redux" implementation from scratch
|