@kashcode/reduxish 0.3.0 → 0.5.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.d.ts +16 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +2 -6
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -8
- package/dist/types/core.d.ts +17 -0
- package/dist/types/core.d.ts.map +1 -0
- package/dist/types/core.js +1 -2
- package/dist/types/helpers.d.ts +6 -0
- package/dist/types/helpers.d.ts.map +1 -0
- package/dist/types/helpers.js +1 -2
- package/package.json +2 -2
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Reducer } from "./types/core";
|
|
2
|
+
import type { StoreEnhancer, Middleware, InferDispatchExtensionsFromMiddlewareArray } from "./types/helpers";
|
|
3
|
+
/**
|
|
4
|
+
* Combine multiple reducers into a single root reducer.
|
|
5
|
+
*
|
|
6
|
+
* @template S - The type of the global state
|
|
7
|
+
* @param reducerMap - A map of reducers, where each key corresponds to a key in the global state and each value is the corresponding reducer.
|
|
8
|
+
* @returns A single root reducer that will manage the global state.
|
|
9
|
+
*/
|
|
10
|
+
export declare function combineReducers<S extends Record<string, unknown>>(reducerMap: {
|
|
11
|
+
[K in keyof S]: Reducer<S[K]>;
|
|
12
|
+
}): Reducer<S>;
|
|
13
|
+
export declare function applyMiddleware<S, A extends ReadonlyArray<Middleware>>(middlewares: A): StoreEnhancer<S, {
|
|
14
|
+
dispatch: InferDispatchExtensionsFromMiddlewareArray<A>;
|
|
15
|
+
}>;
|
|
16
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAS,MAAM,cAAc,CAAA;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,0CAA0C,EAAE,MAAM,iBAAiB,CAAA;AAE5G;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7D,UAAU,EAAE;KACH,CAAC,IAAI,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAChC,GACN,OAAO,CAAC,CAAC,CAAC,CAKZ;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,CAAC,SAAS,aAAa,CAAC,UAAU,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,EAAE;IACtG,QAAQ,EAAE,0CAA0C,CAAC,CAAC,CAAC,CAAA;CAC1D,CAAC,CAYD"}
|
package/dist/helpers.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.combineReducers = combineReducers;
|
|
4
|
-
exports.applyMiddleware = applyMiddleware;
|
|
5
1
|
/**
|
|
6
2
|
* Combine multiple reducers into a single root reducer.
|
|
7
3
|
*
|
|
@@ -9,14 +5,14 @@ exports.applyMiddleware = applyMiddleware;
|
|
|
9
5
|
* @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
6
|
* @returns A single root reducer that will manage the global state.
|
|
11
7
|
*/
|
|
12
|
-
function combineReducers(reducerMap) {
|
|
8
|
+
export function combineReducers(reducerMap) {
|
|
13
9
|
return function (state, action) { return (Object.entries(reducerMap)).reduce(function (partialState, _a) {
|
|
14
10
|
var key = _a[0], reducer = _a[1];
|
|
15
11
|
partialState[key] = reducer(state === null || state === void 0 ? void 0 : state[key], action);
|
|
16
12
|
return partialState;
|
|
17
13
|
}, {}); };
|
|
18
14
|
}
|
|
19
|
-
function applyMiddleware(middlewares) {
|
|
15
|
+
export function applyMiddleware(middlewares) {
|
|
20
16
|
return function (storeCreator) { return function (reducer, intialState) {
|
|
21
17
|
var store = storeCreator(reducer, intialState);
|
|
22
18
|
middlewares.concat().reverse().forEach(function (middleware) {
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Reducer, Store, UnknownAction } from "./types/core";
|
|
2
|
+
import type { StoreEnhancer } from "./types/helpers";
|
|
3
|
+
declare function createStore<S, Ext = {}, A extends UnknownAction = UnknownAction>(reducer: Reducer<S, A>, intialState?: S, storeEnhancer?: StoreEnhancer<S, Ext>): Store<S> & Ext;
|
|
4
|
+
export { createStore };
|
|
5
|
+
export type StoreCreator<S, Ext = {}> = typeof createStore<S, Ext>;
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAmB,aAAa,EAAE,MAAM,cAAc,CAAC;AAEnF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,iBAAS,WAAW,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,EAAE,CAAC,SAAS,aAAa,GAAG,aAAa,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,WAAW,CAAC,EAAE,CAAC,EAAE,aAAa,CAAC,EAAE,aAAa,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,GAAG,CAoBzK;AAED,OAAO,EAAC,WAAW,EAAC,CAAA;AACpB,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,IAAI,OAAO,WAAW,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
|
|
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"));
|
|
1
|
+
import deepFreeze from "deep-freeze";
|
|
8
2
|
function createStore(reducer, intialState, storeEnhancer) {
|
|
9
3
|
var state = intialState;
|
|
10
4
|
var subscribers = [];
|
|
11
5
|
var storeCreator = {
|
|
12
6
|
dispatch: function (action) {
|
|
13
|
-
state = reducer(typeof state === 'object' ? (
|
|
7
|
+
state = reducer(typeof state === 'object' ? deepFreeze(state) : state, action);
|
|
14
8
|
subscribers.forEach(function (sub) { return sub(); });
|
|
15
9
|
return action;
|
|
16
10
|
},
|
|
@@ -30,3 +24,4 @@ function createStore(reducer, intialState, storeEnhancer) {
|
|
|
30
24
|
};
|
|
31
25
|
return storeEnhancer ? storeEnhancer(createStore)(reducer, intialState) : storeCreator;
|
|
32
26
|
}
|
|
27
|
+
export { createStore };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type Action = {
|
|
2
|
+
type: string;
|
|
3
|
+
};
|
|
4
|
+
export type UnknownAction = Record<string, unknown> & Action;
|
|
5
|
+
export interface Dispatch<A extends UnknownAction = UnknownAction> {
|
|
6
|
+
(action: A): A;
|
|
7
|
+
}
|
|
8
|
+
export type StoreSubscriber = Function;
|
|
9
|
+
export interface Store<S> {
|
|
10
|
+
dispatch<A extends UnknownAction = UnknownAction>(action: A): ReturnType<Dispatch<A>>;
|
|
11
|
+
getState: () => S;
|
|
12
|
+
subscribe: (...subscribtionRequests: StoreSubscriber[]) => () => void;
|
|
13
|
+
}
|
|
14
|
+
export interface Reducer<S, A extends UnknownAction = UnknownAction> {
|
|
15
|
+
(state: S | undefined, action?: A): S;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/types/core.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG;IACjB,IAAI,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAA;AAE5D,MAAM,WAAW,QAAQ,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa;IAC7D,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAA;CACjB;AAED,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAA;AAEtC,MAAM,WAAW,KAAK,CAAC,CAAC;IACpB,QAAQ,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,EAAE,MAAM,EAAE,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;IACrF,QAAQ,EAAE,MAAM,CAAC,CAAA;IACjB,SAAS,EAAE,CAAC,GAAG,oBAAoB,EAAE,eAAe,EAAE,KAAK,MAAM,IAAI,CAAA;CACxE;AAGD,MAAM,WAAW,OAAO,CAAC,CAAC,EAAE,CAAC,SAAS,aAAa,GAAG,aAAa;IAC/D,CAAC,KAAK,EAAE,CAAC,GAAG,SAAS,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,CAAA;CACxC"}
|
package/dist/types/core.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { StoreCreator } from "..";
|
|
2
|
+
import { Store } from "./core";
|
|
3
|
+
export type Middleware<DispatchExt = any> = (store: Store<any>) => (next: (action: any) => any) => DispatchExt;
|
|
4
|
+
export type StoreEnhancer<S = unknown, Ext = {}> = (next: StoreCreator<S, unknown>) => StoreCreator<S, Ext>;
|
|
5
|
+
export type InferDispatchExtensionsFromMiddlewareArray<A extends readonly any[], Acc = {}> = [...A] extends [infer First, ...infer Rest] ? InferDispatchExtensionsFromMiddlewareArray<[...Rest], Acc & (First extends Middleware<infer M> ? M extends never ? {} : M : {})> : Acc;
|
|
6
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/types/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE/B,MAAM,MAAM,UAAU,CAAC,WAAW,GAAG,GAAG,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,KAAK,WAAW,CAAA;AAC9G,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,OAAO,EAAC,GAAG,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,YAAY,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;AAC1G,MAAM,MAAM,0CAA0C,CAAC,CAAC,SAAS,SAAS,GAAG,EAAE,EAAE,GAAG,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,MAAM,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,0CAA0C,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,KAAK,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,KAAK,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,GAAG,CAAA"}
|
package/dist/types/helpers.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kashcode/reduxish",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
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",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"test": "jest --coverage",
|
|
17
17
|
"test:watch": "jest --watch",
|
|
18
18
|
"prepublishOnly": "npm run test && npm run build",
|
|
19
|
-
"
|
|
19
|
+
"push": "npm run prepublishOnly && npm publish"
|
|
20
20
|
},
|
|
21
21
|
"author": "Kasope <kasopej@gmail.com>",
|
|
22
22
|
"license": "MIT",
|