@kashcode/reduxish 0.1.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.
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.combineReducers = combineReducers;
4
+ exports.applyMiddleware = applyMiddleware;
5
+ /**
6
+ * Combine multiple reducers into a single root reducer.
7
+ *
8
+ * @template S - The type of the global state
9
+ * @param reducerMap - A map of reducers, where each key corresponds to a key in the global state and each value is the corresponding reducer.
10
+ * @returns A single root reducer that will manage the global state.
11
+ */
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
+ };
21
+ }
22
+ function applyMiddleware(middlewares) {
23
+ return function (storeCreator) { return function (reducer, intialState) {
24
+ var store = storeCreator(reducer, intialState);
25
+ middlewares.reverse().forEach(function (middleware) {
26
+ store.dispatch = middleware(store)(store.dispatch);
27
+ });
28
+ return store;
29
+ }; };
30
+ }
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createStore = createStore;
7
+ var deep_freeze_1 = __importDefault(require("deep-freeze"));
8
+ function createStore(reducer, intialState, storeEnhancer) {
9
+ var state = intialState;
10
+ var subscribers = [];
11
+ var storeCreator = {
12
+ dispatch: function (action) {
13
+ state = reducer(typeof state === 'object' ? (0, deep_freeze_1.default)(state) : state, action);
14
+ subscribers.forEach(function (sub) { return sub(); });
15
+ return action;
16
+ },
17
+ getState: function () {
18
+ return state;
19
+ },
20
+ subscribe: function () {
21
+ var subscribtionRequests = [];
22
+ for (var _i = 0; _i < arguments.length; _i++) {
23
+ subscribtionRequests[_i] = arguments[_i];
24
+ }
25
+ subscribers.push.apply(subscribers, subscribtionRequests);
26
+ return function () {
27
+ subscribers.filter(function (sub) { return subscribtionRequests.every(function (subRequest) { return subRequest !== sub; }); });
28
+ };
29
+ },
30
+ };
31
+ return storeEnhancer ? storeEnhancer(createStore)(reducer, intialState) : storeCreator;
32
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
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.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "exports": {
8
+ ".": "./dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "scripts": {
14
+ "build": "tsc",
15
+ "start": "node dist/index.js"
16
+ },
17
+ "author": "Kasope <kasopej@gmail.com>",
18
+ "license": "MIT",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/kasopej/reduxish.git"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/kasopej/reduxish/issues"
25
+ },
26
+ "homepage": "https://github.com/kasopej/reduxish#readme",
27
+ "keywords": [
28
+ "redux",
29
+ "state-management",
30
+ "typescript",
31
+ "frontend",
32
+ "store",
33
+ "middleware"
34
+ ],
35
+ "dependencies": {
36
+ "deep-freeze": "^0.0.1",
37
+ "expect": "^22.4.3"
38
+ },
39
+ "devDependencies": {
40
+ "@types/deep-freeze": "^0.1.5",
41
+ "@types/node": "^25.2.0",
42
+ "ajv": "^8.17.1",
43
+ "cross-env": "^10.1.0"
44
+ }
45
+ }
package/readme.md ADDED
@@ -0,0 +1,86 @@
1
+ # 🧃 Tiny State, Big Vibes
2
+
3
+ A **custom, fully‑typed, 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
11
+
12
+ ---
13
+
14
+ ## ✨ Features
15
+
16
+ ### 🏪 Store Creation
17
+
18
+ Create a store with a **strongly‑typed state**, a **typed dispatch**, and a **simple subscription model**.
19
+
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
+
30
+ Split your state into logical slices and merge them into a single root reducer.
31
+
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
+
38
+ ---
39
+
40
+ ### 🧠 Middleware Support
41
+
42
+ Intercept actions before they hit your reducers.
43
+
44
+ Perfect for:
45
+
46
+ - logging
47
+ - async flows
48
+ - side‑effects
49
+ - analytics
50
+ - chaos (controlled chaos)
51
+
52
+ Middlewares are:
53
+
54
+ - composable
55
+ - ordered
56
+ - fully typed from `dispatch` to `next`
57
+
58
+ ---
59
+
60
+ ### ⚛️ React Integration Utilities
61
+
62
+ Opt‑in React bindings for modern React apps.
63
+
64
+ Includes helpers for:
65
+
66
+ - subscribing components to store updates
67
+ - selecting slices of state efficiently
68
+ - avoiding unnecessary re‑renders
69
+
70
+ Works great with function components, hooks, and strict mode.
71
+
72
+ No class components were harmed in the making of this library.
73
+
74
+ ---
75
+
76
+ ## 📦 Installation
77
+
78
+ ```bash
79
+ npm install tiny-state-big-vibes
80
+ ```
81
+
82
+ or if you’re feeling spicy:
83
+
84
+ ```bash
85
+ pnpm add tiny-state-big-vibes
86
+ ```