@kashcode/reduxish 0.1.0 → 0.3.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 CHANGED
@@ -10,19 +10,16 @@ exports.applyMiddleware = applyMiddleware;
10
10
  * @returns A single root reducer that will manage the global state.
11
11
  */
12
12
  function combineReducers(reducerMap) {
13
- return function (state, action) {
14
- if (state === void 0) { state = {}; }
15
- return (Object.entries(reducerMap)).reduce(function (partialState, _a) {
16
- var key = _a[0], reducer = _a[1];
17
- partialState[key] = reducer(state[key], action);
18
- return partialState;
19
- }, {});
20
- };
13
+ return function (state, action) { return (Object.entries(reducerMap)).reduce(function (partialState, _a) {
14
+ var key = _a[0], reducer = _a[1];
15
+ partialState[key] = reducer(state === null || state === void 0 ? void 0 : state[key], action);
16
+ return partialState;
17
+ }, {}); };
21
18
  }
22
19
  function applyMiddleware(middlewares) {
23
20
  return function (storeCreator) { return function (reducer, intialState) {
24
21
  var store = storeCreator(reducer, intialState);
25
- middlewares.reverse().forEach(function (middleware) {
22
+ middlewares.concat().reverse().forEach(function (middleware) {
26
23
  store.dispatch = middleware(store)(store.dispatch);
27
24
  });
28
25
  return store;
package/dist/index.js CHANGED
@@ -24,7 +24,7 @@ function createStore(reducer, intialState, storeEnhancer) {
24
24
  }
25
25
  subscribers.push.apply(subscribers, subscribtionRequests);
26
26
  return function () {
27
- subscribers.filter(function (sub) { return subscribtionRequests.every(function (subRequest) { return subRequest !== sub; }); });
27
+ subscribers.splice(subscribers.length - subscribtionRequests.length, subscribtionRequests.length);
28
28
  };
29
29
  },
30
30
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kashcode/reduxish",
3
- "version": "0.1.0",
4
- "description": "A tiny, fully-typed Redux-inspired state management library with middleware and React bindings.",
3
+ "version": "0.3.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": {
@@ -12,7 +12,11 @@
12
12
  ],
13
13
  "scripts": {
14
14
  "build": "tsc",
15
- "start": "node dist/index.js"
15
+ "start": "node dist/index.js",
16
+ "test": "jest --coverage",
17
+ "test:watch": "jest --watch",
18
+ "prepublishOnly": "npm run test && npm run build",
19
+ "publish": "npm run prepublishOnly && npm publish"
16
20
  },
17
21
  "author": "Kasope <kasopej@gmail.com>",
18
22
  "license": "MIT",
@@ -33,13 +37,16 @@
33
37
  "middleware"
34
38
  ],
35
39
  "dependencies": {
36
- "deep-freeze": "^0.0.1",
37
- "expect": "^22.4.3"
40
+ "deep-freeze": "^0.0.1"
38
41
  },
39
42
  "devDependencies": {
40
43
  "@types/deep-freeze": "^0.1.5",
44
+ "@types/jest": "30.0.0",
41
45
  "@types/node": "^25.2.0",
42
46
  "ajv": "^8.17.1",
43
- "cross-env": "^10.1.0"
47
+ "cross-env": "^10.1.0",
48
+ "jest": "30.2.0",
49
+ "ts-jest": "29.4.6",
50
+ "ts-node": "10.9.2"
44
51
  }
45
52
  }
package/readme.md CHANGED
@@ -1,13 +1,6 @@
1
- # 🧃 Tiny State, Big Vibes
1
+ # 🧃 Reduxish
2
2
 
3
- A **custom, fullytyped, Redux‑ish state management library** for people who like their global state **predictable**, **type‑safe**, and **a little bit fun**.
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
- - `dispatch(action)` sends actions through reducers & middleware
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
- - ordered
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
- ### ⚛️ React Integration Utilities
61
-
62
- Opt‑in React bindings for modern React apps.
63
-
64
- Includes helpers for:
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
- - subscribing components to store updates
67
- - selecting slices of state efficiently
68
- - avoiding unnecessary re‑renders
50
+ ---
69
51
 
70
- Works great with function components, hooks, and strict mode.
52
+ ### ⚛️ Using with React?
71
53
 
72
- No class components were harmed in the making of this library.
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 tiny-state-big-vibes
70
+ npm install @kashcode/reduxish
80
71
  ```
72
+ ---
81
73
 
82
- or if you’re feeling spicy:
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