Merge branch 'actionFor'

This commit is contained in:
Yanick Champoux 2020-02-07 11:24:38 -05:00
commit e3c5aad399
88 changed files with 91 additions and 4005 deletions

3
.gitignore vendored
View File

@ -1,3 +1,6 @@
node_modules/ node_modules/
tsconfig.tsbuildinfo tsconfig.tsbuildinfo
**/*.orig **/*.orig
dist
package-lock.json
yarn.lock

View File

@ -1,2 +0,0 @@
export {};
//# sourceMappingURL=actions.test.d.ts.map

View File

@ -1 +0,0 @@
{"version":3,"file":"actions.test.d.ts","sourceRoot":"","sources":["../src/actions.test.ts"],"names":[],"mappings":""}

37
dist/actions.test.js vendored
View File

@ -1,37 +0,0 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = __importDefault(require("."));
const noopEffect = () => () => () => { };
test('actions defined in effects and mutations, multi-level', () => {
const { actions } = new _1.default({
effects: {
foo: noopEffect,
},
mutations: { bar: () => () => null },
subduxes: {
mysub: {
effects: { baz: noopEffect },
mutations: { quux: () => () => null },
actions: {
foo: (limit) => ({ limit }),
},
},
myothersub: {
effects: {
foo: noopEffect,
},
},
},
});
const types = Object.keys(actions);
types.sort();
expect(types).toEqual(['bar', 'baz', 'foo', 'quux']);
expect(actions.bar()).toEqual({ type: 'bar' });
expect(actions.bar('xxx')).toEqual({ type: 'bar', payload: 'xxx' });
expect(actions.bar(undefined, 'yyy')).toEqual({ type: 'bar', meta: 'yyy' });
expect(actions.foo(12)).toEqual({ type: 'foo', payload: { limit: 12 } });
});
//# sourceMappingURL=actions.test.js.map

View File

@ -1 +0,0 @@
{"version":3,"file":"actions.test.js","sourceRoot":"","sources":["../src/actions.test.ts"],"names":[],"mappings":";;;;;AAAA,yCAAsB;AAGtB,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;AAExC,IAAI,CAAC,uDAAuD,EAAE,GAAG,EA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EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,EAAC,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,EAAC,KAAK,EAAE,EAAE,EAAC,EAAC,CAAC,CAAC;AACvE,CAAC,CAAC,CAAC"}

View File

@ -1,2 +0,0 @@
export {};
//# sourceMappingURL=addMutations.test.d.ts.map

View File

@ -1 +0,0 @@
{"version":3,"file":"addMutations.test.d.ts","sourceRoot":"","sources":["../src/addMutations.test.ts"],"names":[],"mappings":""}

View File

@ -1,22 +0,0 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const updux_1 = __importStar(require("./updux"));
test('added mutation is present', () => {
const updux = new updux_1.default({
initial: { sum: 0 },
});
const add = updux_1.actionCreator('add', (n) => ({ n }));
updux.addMutation(add, ({ n }, action) => ({ sum }) => ({ sum: sum + n }));
updux.mutations;
const store = updux.createStore();
store.dispatch.add(3);
expect(store.getState()).toEqual({ sum: 3 });
});
//# sourceMappingURL=addMutations.test.js.map

View File

@ -1 +0,0 @@
{"version":3,"file":"addMutations.test.js","sourceRoot":"","sources":["../src/addMutations.test.ts"],"names":[],"mappings":";;;;;;;;;AAAA,iDAA+C;AAM/C,IAAI,CAAE,2BAA2B,EAAE,GAAG,EAAE;IACpC,MAAM,KAAK,GAAG,IAAI,eAAK,CAAU;QAC7B,OAAO,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE;KACtB,CAAC,CAAC;IAEH,MAAM,GAAG,GAAG,qBAAa,CAAC,KAAK,EAAE,CAAC,CAAU,EAAE,EAAE,CAAC,CAAC,EAAC,CAAC,EAAC,CAAC,CAAE,CAAA;IAGxD,KAAK,CAAC,WAAW,CACb,GAAG,EAAE,CAAC,EAAC,CAAC,EAAC,EAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAC,GAAG,EAAC,EAAE,EAAE,CAAC,CAAC,EAAC,GAAG,EAAE,GAAG,GAAG,CAAC,EAAC,CAAC,CACnD,CAAC;IACF,KAAK,CAAC,SAAS,CAAC;IAChB,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;IAClC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAEtB,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;AACjD,CAAC,CAAC,CAAC"}

View File

@ -1,8 +0,0 @@
import { ActionCreator, ActionPayloadGenerator, Dictionary } from '../types';
export declare function actionCreator<T extends string, P extends any>(type: T, transform: (...args: any[]) => P): ActionCreator<T, P>;
export declare function actionCreator<T extends string>(type: T, transform: never): ActionCreator<T, undefined>;
export declare function actionCreator<T extends string>(type: T, transform: null): ActionCreator<T, null>;
declare type ActionPair = [string, ActionCreator];
declare function buildActions(generators?: Dictionary<ActionPayloadGenerator>, actionNames?: string[], subActions?: ActionPair[]): Dictionary<ActionCreator>;
export default buildActions;
//# sourceMappingURL=index.d.ts.map

View File

@ -1 +0,0 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/buildActions/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,aAAa,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAErF,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAC,CAAC,SAAS,GAAG,EAAG,IAAI,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GAAI,aAAa,CAAC,CAAC,EAAC,CAAC,CAAC,CAAA;AAC9H,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAG,IAAI,EAAE,CAAC,EAAE,SAAS,EAAE,KAAK,GAAI,aAAa,CAAC,CAAC,EAAC,SAAS,CAAC,CAAA;AACxG,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAG,IAAI,EAAE,CAAC,EAAE,SAAS,EAAE,IAAI,GAAI,aAAa,CAAC,CAAC,EAAC,IAAI,CAAC,CAAA;AA2BlG,aAAK,UAAU,GAAG,CAAE,MAAM,EAAE,aAAa,CAAE,CAAC;AAE5C,iBAAS,YAAY,CACnB,UAAU,GAAG,UAAU,CAAC,sBAAsB,CAAM,EACpD,WAAW,GAAE,MAAM,EAAO,EAC1B,UAAU,GAAG,UAAU,EAAO,GAC9B,UAAU,CAAC,aAAa,CAAC,CAkB1B;AAED,eAAe,YAAY,CAAC"}

View File

@ -1,35 +0,0 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fp_1 = __importDefault(require("lodash/fp"));
function actionCreator(type, transform) {
if (transform) {
return Object.assign((...args) => ({ type, payload: transform(...args) }), { type });
}
if (transform === null) {
return Object.assign(() => ({ type }), { type });
}
return Object.assign((payload) => ({ type, payload }));
}
exports.actionCreator = actionCreator;
function actionFor(type) {
const f = ((payload = undefined, meta = undefined) => fp_1.default.pickBy(v => v !== undefined)({ type, payload, meta }));
return Object.assign(f, {
_genericAction: true,
type
});
}
function buildActions(generators = {}, actionNames = [], subActions = []) {
const [crafted, generic] = fp_1.default.partition(([type, f]) => !f._genericAction)(subActions);
const actions = [
...(actionNames.map(type => [type, actionFor(type)])),
...generic,
...crafted,
...Object.entries(generators).map(([type, payload]) => [type, payload.type ? payload : (...args) => ({ type, payload: payload(...args) })]),
];
return fp_1.default.fromPairs(actions);
}
exports.default = buildActions;
//# sourceMappingURL=index.js.map

View File

@ -1 +0,0 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/buildActions/index.ts"],"names":[],"mappings":";;;;;AAAA,mDAA2B;AAM3B,SAAgB,aAAa,CAAC,IAAQ,EAAE,SAAa;IAEjD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AAE,CAAC,CAAE,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAE,CAAE,CAAC;QACzD,GAAG,OAAO;QACV,GAAG,OAAO;QACV,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,CAC7B,CAAC,CAAC,IAAI,EAAE,OAAO,CAAuB,EAAO,EAAE,CAAC,CAAC,IAAI,EAAG,OAAe,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,IAAS,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CACpJ;KACJ,CAAC;IAEF,OAAO,YAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAED,kBAAe,YAAY,CAAC"}

View File

@ -1,24 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = buildCreateStore;
var _redux = require("redux");
function buildCreateStore(reducer, initial, middleware, actions) {
return () => {
const store = (0, _redux.createStore)(reducer, initial, (0, _redux.applyMiddleware)(middleware));
for (let a in actions) {
store.dispatch[a] = (...args) => {
store.dispatch(actions[a](...args));
};
}
return store;
};
}
;

View File

@ -1 +0,0 @@
{"version":3,"file":"buildCreateStore.js","sourceRoot":"","sources":["../src/buildCreateStore.js"],"names":[],"mappings":";;AAAA,iCAAyE;AAEzE,SAAwB,gBAAgB,CAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAC9B,OAAO;IAC3C,OAAO,GAAG,EAAE;QACV,MAAM,KAAK,GAAI,mBAAgB,CAAE,OAAO,EAAE,OAAO,EAC7C,uBAAe,CAAE,UAAU,CAAC,CAC7B,CAAC;QACJ,KAAM,IAAI,CAAC,IAAI,OAAO,EAAG;YACrB,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE;gBAC5B,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;YACvC,CAAC,CAAC;SACL;QAED,OAAO,KAAK,CAAC;IACjB,CAAC,CAAA;AACH,CAAC;AAdD,mCAcC;AAAA,CAAC"}

View File

@ -1,7 +0,0 @@
import { Middleware, Reducer } from 'redux';
import { ActionCreator, Dictionary } from '../types';
declare function buildCreateStore<S>(reducer: Reducer<S>, initial: S, middleware: Middleware, actions: Dictionary<ActionCreator>): () => import("redux").Store<S, import("redux").AnyAction> & {
dispatch: {};
};
export default buildCreateStore;
//# sourceMappingURL=index.d.ts.map

View File

@ -1 +0,0 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/buildCreateStore/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EACV,OAAO,EACR,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAErD,iBAAS,gBAAgB,CAAC,CAAC,EACzB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,OAAO,EAAE,CAAC,EACV,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,UAAU,CAAC,aAAa,CAAC;;EAgBnC;AAED,eAAe,gBAAgB,CAAC"}

View File

@ -1,16 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const redux_1 = require("redux");
function buildCreateStore(reducer, initial, middleware, actions) {
return () => {
const store = redux_1.createStore(reducer, initial, redux_1.applyMiddleware(middleware));
for (let a in actions) {
store.dispatch[a] = (...args) => {
store.dispatch(actions[a](...args));
};
}
return store;
};
}
exports.default = buildCreateStore;
//# sourceMappingURL=index.js.map

View File

@ -1 +0,0 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/buildCreateStore/index.ts"],"names":[],"mappings":";;AAAA,iCAKe;AAGf,SAAS,gBAAgB,CACvB,OAAmB,EACnB,OAAU,EACV,UAAsB,EACtB,OAAkC;IAElC,OAAO,GAAG,EAAE;QACV,MAAM,KAAK,GAAG,mBAAgB,CAC5B,OAAO,EACP,OAAO,EACP,uBAAe,CAAC,UAAU,CAAC,CAC5B,CAAC;QACF,KAAK,IAAI,CAAC,IAAI,OAAO,EAAE;YACnB,KAAK,CAAC,QAAgB,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAW,EAAE,EAAE;gBAC/C,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;YACtC,CAAC,CAAC;SACH;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AAED,kBAAe,gBAAgB,CAAC"}

View File

@ -1,5 +0,0 @@
import { Dictionary } from '../types';
declare function buildInitial<S extends number | string | boolean>(initial: S, subduxes?: Dictionary<undefined>): S;
declare function buildInitial<S extends object>(initial?: Partial<S>, subduxes?: Partial<S>): S extends object ? S : never;
export default buildInitial;
//# sourceMappingURL=index.d.ts.map

View File

@ -1 +0,0 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/buildInitial/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,iBAAS,YAAY,CAAC,CAAC,SAAS,MAAM,GAAC,MAAM,GAAC,OAAO,EAAG,OAAO,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,UAAU,CAAC,SAAS,CAAC,GAAI,CAAC,CAAC;AAC1G,iBAAS,YAAY,CAAC,CAAC,SAAS,MAAM,EAAG,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,GAAI,CAAC,SAAS,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC;AAQrH,eAAe,YAAY,CAAC"}

View File

@ -1,11 +0,0 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fp_1 = __importDefault(require("lodash/fp"));
function buildInitial(initial = {}, subduxes = {}) {
return fp_1.default.isPlainObject(initial) ? fp_1.default.mergeAll([subduxes, initial]) : initial;
}
exports.default = buildInitial;
//# sourceMappingURL=index.js.map

View File

@ -1 +0,0 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/buildInitial/index.ts"],"names":[],"mappings":";;;;;AAAA,mDAA2B;AAK3B,SAAS,YAAY,CACnB,UAAgB,EAAE,EAClB,WAAiB,EAAE;IAEnB,OAAO,YAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,YAAE,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;AAChF,CAAC;AAED,kBAAe,YAAY,CAAC"}

View File

@ -1 +0,0 @@
"use strict";

View File

@ -1 +0,0 @@
{"version":3,"file":"index.test-d.js","sourceRoot":"","sources":["../../src/buildInitial/index.test-d.js"],"names":[],"mappings":""}

View File

@ -1 +0,0 @@
"use strict";

View File

@ -1 +0,0 @@
{"version":3,"file":"test-d.js","sourceRoot":"","sources":["../../src/buildInitial/test-d.js"],"names":[],"mappings":""}

View File

@ -1,27 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = buildMiddleware;
var _fp = _interopRequireDefault(require("lodash/fp"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const MiddlewareFor = (type, mw) => api => next => action => {
if (type !== '*' && action.type !== type) return next(action);
return mw(api)(next)(action);
};
function buildMiddleware(effects = {}, actions = {}, subduxes = {}) {
return api => {
for (let type in actions) {
api.dispatch[type] = (...args) => api.dispatch(actions[type](...args));
}
return original_next => {
return [..._fp.default.toPairs(effects).map(([type, effect]) => MiddlewareFor(type, effect)), ..._fp.default.map('middleware', subduxes)].filter(x => x).reduceRight((next, mw) => mw(api)(next), original_next);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aAAa,CAAC,CAAC;QAC7D,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AArBD,kCAqBC"}

View File

@ -1,4 +0,0 @@
import { Dictionary, ActionCreator, UpduxMiddleware } from '../types';
declare function buildMiddleware<S = any>(effects?: Dictionary<UpduxMiddleware<S>>, actions?: Dictionary<ActionCreator>, subduxes?: any): UpduxMiddleware<S>;
export default buildMiddleware;
//# sourceMappingURL=index.d.ts.map

View File

@ -1 +0,0 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/buildMiddleware/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAyB,eAAe,EAAsB,MAAM,UAAU,CAAC;AAkBjH,iBAAS,eAAe,CAAC,CAAC,GAAC,GAAG,EAC1B,OAAO,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC,CAAK,EAC5C,OAAO,GAAG,UAAU,CAAC,aAAa,CAAK,EACvC,QAAQ,GAAE,GAAQ,GACnB,eAAe,CAAC,CAAC,CAAC,CA4BpB;AAED,eAAe,eAAe,CAAC"}

View File

@ -1,37 +0,0 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fp_1 = __importDefault(require("lodash/fp"));
const MiddlewareFor = (type, mw) => api => next => action => {
if (type !== '*' && action.type !== type)
return next(action);
return mw(api)(next)(action);
};
function sliceMw(slice, mw) {
return (api) => {
const getSliceState = () => fp_1.default.get(slice, api.getState());
const getRootState = api.getRootState || api.getState;
return mw({ ...api, getState: getSliceState, getRootState });
};
}
function buildMiddleware(effects = {}, actions = {}, subduxes = {}) {
const subMiddlewares = fp_1.default.flow(fp_1.default.mapValues(fp_1.default.get('middleware')), fp_1.default.toPairs, fp_1.default.filter(x => x[1]), fp_1.default.map(([slice, mw]) => sliceMw(slice, mw)))(subduxes);
return (api) => {
for (let type in actions) {
const ac = actions[type];
api.dispatch[type] = (...args) => api.dispatch(ac(...args));
}
return (original_next) => {
return [
...fp_1.default.toPairs(effects).map(([type, effect]) => MiddlewareFor(type, effect)),
...subMiddlewares
]
.filter(x => x)
.reduceRight((next, mw) => mw(api)(next), original_next);
};
};
}
exports.default = buildMiddleware;
//# sourceMappingURL=index.js.map

View File

@ -1 +0,0 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/buildMiddleware/index.ts"],"names":[],"mappings":";;;;;AAAA,mDAA2B;AAK3B,MAAM,aAAa,GAAG,CAAC,IAAS,EAAE,EAAc,EAAe,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE;IACtF,IAAI,IAAI,KAAK,GAAG,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;IAE9D,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC,CAAC;AAIF,SAAS,OAAO,CAAE,KAAa,EAAE,EAAc;IAC3C,OAAO,CAAC,GAAG,EAAE,EAAE;QACX,MAAM,aAAa,GAAG,GAAG,EAAE,CAAC,YAAE,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAE,CAAC;QAC3D,MAAM,YAAY,GAAI,GAAW,CAAC,YAAY,IAAI,GAAG,CAAC,QAAQ,CAAC;QAC/D,OAAO,EAAE,CAAC,EAAC,GAAG,GAAG,EAAE,QAAQ,EAAE,aAAa,EAAE,YAAY,EAAQ,CAAE,CAAA;IACtE,CAAC,CAAC;AACN,CAAC;AAED,SAAS,eAAe,CACpB,UAA0C,EAAE,EAC5C,UAAqC,EAAE,EACvC,WAAgB,EAAE;IAIlB,MAAM,cAAc,GAAG,YAAE,CAAC,IAAI,CAC1B,YAAE,CAAC,SAAS,CAAE,YAAE,CAAC,GAAG,CAAC,YAAY,CAAC,CAAE,EACpC,YAAE,CAAC,OAAO,EACV,YAAE,CAAC,MAAM,CAAC,CAAC,CAAA,EAAE,CAAA,CAAC,CAAC,CAAC,CAAC,CAAC,EAClB,YAAE,CAAC,GAAG,CAAE,CAAC,CAAE,KAAK,EAAE,EAAE,CAAyB,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAC,EAAE,CAAC,CAAE,CACxE,CAAE,QAAQ,CAAE,CAAC;IAEhB,OAAO,CAAC,GAA0B,EAAE,EAAE;QAEpC,KAAK,IAAI,IAAI,IAAI,OAAO,EAAE;YACxB,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;YACzB,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAU,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;SACnE;QAED,OAAO,CAAC,aAAmB,EAAC,EAAE;YAC5B,OAAO;gBACL,GAAG,YAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,CAC1C,aAAa,CAAC,IAAI,EAAC,MAAoB,CAAC,CAC3C;gBACD,GAAG,cAAc;aAClB;iBACE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;iBACd,WAAW,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC,CAAC;QAC7D,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED,kBAAe,eAAe,CAAC"}

View File

@ -1,5 +0,0 @@
/// <reference types="lodash" />
import { Mutation, Action, Dictionary } from '../types';
declare function buildMutations(mutations?: Dictionary<Mutation | ([Mutation, boolean | undefined])>, subduxes?: {}): import("lodash").Dictionary<Mutation<any, Action<string, any>>>;
export default buildMutations;
//# sourceMappingURL=index.d.ts.map

View File

@ -1 +0,0 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/buildMutations/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAWtD,iBAAS,cAAc,CACnB,SAAS,GAAE,UAAU,CAAC,QAAQ,GAAC,CAAC,CAAC,QAAQ,EAAC,OAAO,GAAC,SAAS,CAAC,CAAC,CAAM,EACnE,QAAQ,KAAK,mEAyDhB;AAED,eAAe,cAAc,CAAC"}

View File

@ -1,45 +0,0 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fp_1 = __importDefault(require("lodash/fp"));
const updeep_1 = __importDefault(require("updeep"));
const composeMutations = (mutations) => mutations.reduce((m1, m2) => (payload = null, action) => state => m2(payload, action)(m1(payload, action)(state)));
function buildMutations(mutations = {}, subduxes = {}) {
const actions = fp_1.default.uniq(Object.keys(mutations).concat(...Object.values(subduxes).map(({ mutations = {} }) => Object.keys(mutations))));
let mergedMutations = {};
let [globby, nonGlobby] = fp_1.default.partition(([_, { mutations = {} }]) => mutations['*'], Object.entries(subduxes));
globby = fp_1.default.flow([
fp_1.default.fromPairs,
fp_1.default.mapValues(({ reducer }) => (_, action) => (state) => reducer(state, action)),
])(globby);
const globbyMutation = (payload, action) => updeep_1.default(fp_1.default.mapValues((mut) => mut(payload, action))(globby));
actions.forEach(action => {
mergedMutations[action] = [globbyMutation];
});
nonGlobby.forEach(([slice, { mutations = {}, reducer = {} }]) => {
Object.entries(mutations).forEach(([type, mutation]) => {
const localized = (payload = null, action) => {
return updeep_1.default.updateIn(slice)(mutation(payload, action));
};
mergedMutations[type].push(localized);
});
});
Object.entries(mutations).forEach(([type, mutation]) => {
if (Array.isArray(mutation)) {
if (mutation[1]) {
mergedMutations[type] = [
mutation[0]
];
}
else
mergedMutations[type].push(mutation[0]);
}
else
mergedMutations[type].push(mutation);
});
return fp_1.default.mapValues(composeMutations)(mergedMutations);
}
exports.default = buildMutations;
//# sourceMappingURL=index.js.map

View File

@ -1 +0,0 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/buildMutations/index.ts"],"names":[],"mappings":";;;;;AAAA,mDAA2B;AAC3B,oDAAuB;AAGvB,MAAM,gBAAgB,GAAG,CAAC,SAAqB,EAAE,EAAE,CACjD,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,UAAe,IAAI,EAAE,MAAc,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAC5E,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,CAChD,CAAC;AAMJ,SAAS,cAAc,CACnB,YAAiE,EAAE,EACnE,QAAQ,GAAG,EAAE;IAKf,MAAM,OAAO,GAAG,YAAE,CAAC,IAAI,CACrB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,CAC3B,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,EAAC,SAAS,GAAG,EAAE,EAAK,EAAE,EAAE,CACtD,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CACvB,CACF,CACF,CAAC;IAEF,IAAI,eAAe,GAA2B,EAAE,CAAC;IAEjD,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,YAAE,CAAC,SAAS,CACpC,CAAC,CAAC,CAAC,EAAE,EAAC,SAAS,GAAG,EAAE,EAAC,CAAK,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,EAC7C,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CACzB,CAAC;IAEF,MAAM,GAAG,YAAE,CAAC,IAAI,CAAC;QACf,YAAE,CAAC,SAAS;QACZ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AAC,OAAO,CAAC,QAAQ,CAAC,EAAG;YAC3B,IAAI,QAAQ,CAAC,CAAC,CAAC,EAAG;gBACd,eAAe,CAAC,IAAI,CAAC,GAAG;oBACpB,QAAQ,CAAC,CAAC,CAAC;iBACd,CAAA;aACJ;;gBACI,eAAe,CAAC,IAAI,CAAC,CAAC,IAAI,CAAE,QAAQ,CAAC,CAAC,CAAC,CAAE,CAAC;SAClD;;YACI,eAAe,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,OAAO,YAAE,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC,eAAe,CAAC,CAAC;AACzD,CAAC;AAED,kBAAe,cAAc,CAAC"}

View File

@ -1,2 +0,0 @@
export {};
//# sourceMappingURL=test.d.ts.map

View File

@ -1 +0,0 @@
{"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../src/buildMutations/test.ts"],"names":[],"mappings":""}

View File

@ -1,13 +0,0 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = __importDefault(require("."));
const actions = {
multiply: (factor) => ({ factor }),
};
const mutations = _1.default({
multiply: ({ factor }) => ({ counter }) => factor * counter,
});
//# sourceMappingURL=test.js.map

View File

@ -1 +0,0 @@
{"version":3,"file":"test.js","sourceRoot":"","sources":["../../src/buildMutations/test.ts"],"names":[],"mappings":";;;;;AAAA,yCAA+B;AAE/B,MAAM,OAAO,GAAG;IACZ,QAAQ,EAAE,CAAC,MAAc,EAAE,EAAE,CAAC,CAAC,EAAC,MAAM,EAAC,CAAC;CAC3C,CAAC;AAEF,MAAM,SAAS,GAAG,UAAc,CAC5B;IACI,QAAQ,EAAE,CAAC,EAAC,MAAM,EAAC,EAAE,EAAE,CAAC,CAAC,EAAC,OAAO,EAAC,EAAE,EAAE,CAAC,MAAM,GAAG,OAAO;CAC1D,CACJ,CAAC"}

View File

@ -1,4 +0,0 @@
import { Dictionary, Mutation, Upreducer } from '../types';
declare function buildUpreducer<S>(initial: S, mutations: Dictionary<Mutation<S>>): Upreducer<S>;
export default buildUpreducer;
//# sourceMappingURL=index.d.ts.map

View File

@ -1 +0,0 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/buildUpreducer/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAU,SAAS,EAAE,MAAM,UAAU,CAAC;AAEnE,iBAAS,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAI,SAAS,CAAC,CAAC,CAAC,CAYxF;AAED,eAAe,cAAc,CAAC"}

View File

@ -1,15 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function buildUpreducer(initial, mutations) {
return (action) => (state) => {
if (state === undefined)
state = initial;
const a = mutations[action.type] ||
mutations['*'];
if (!a)
return state;
return a(action.payload, action)(state);
};
}
exports.default = buildUpreducer;
//# sourceMappingURL=index.js.map

View File

@ -1 +0,0 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/buildUpreducer/index.ts"],"names":[],"mappings":";;AAIA,SAAS,cAAc,CAAI,OAAU,EAAE,SAAkC;IACvE,OAAO,CAAC,MAAc,EAAE,EAAE,CAAC,CAAC,KAAQ,EAAE,EAAE;QACtC,IAAI,KAAK,KAAK,SAAS;YAAE,KAAK,GAAG,OAAO,CAAC;QAEzC,MAAM,CAAC,GACL,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC;YACtB,SAAS,CAAC,GAAG,CAAC,CAAC;QAEjB,IAAG,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;QAEpB,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC,CAAC;AACJ,CAAC;AAED,kBAAe,cAAc,CAAC"}

5
dist/index.d.ts vendored
View File

@ -1,5 +0,0 @@
import Updux from './updux';
export { default as Updux } from './updux';
export { UpduxConfig } from './types';
export default Updux;
//# sourceMappingURL=index.d.ts.map

1
dist/index.d.ts.map vendored
View File

@ -1 +0,0 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAC;AAE5B,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EACH,WAAW,EACd,MAAM,SAAS,CAAC;AAEjB,eAAe,KAAK,CAAC"}

10
dist/index.js vendored
View File

@ -1,10 +0,0 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const updux_1 = __importDefault(require("./updux"));
var updux_2 = require("./updux");
exports.Updux = updux_2.default;
exports.default = updux_1.default;
//# sourceMappingURL=index.js.map

1
dist/index.js.map vendored
View File

@ -1 +0,0 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAE5B,iCAA2C;AAAlC,wBAAA,OAAO,CAAS;AAKzB,kBAAe,eAAK,CAAC"}

View File

@ -1,2 +0,0 @@
export {};
//# sourceMappingURL=mappedUpdux.test.d.ts.map

View File

@ -1 +0,0 @@
{"version":3,"file":"mappedUpdux.test.d.ts","sourceRoot":"","sources":["../src/mappedUpdux.test.ts"],"names":[],"mappings":""}

View File

@ -1,28 +0,0 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const updux_1 = __importDefault(require("./updux"));
const updeep_1 = __importDefault(require("updeep"));
const todo = new updux_1.default({
mutations: {
review: () => updeep_1.default({ reviewed: true }),
done: () => updeep_1.default({ done: true }),
},
});
const todos = new updux_1.default({
subduxes: { '*': todo },
});
todos.addMutation(todo.actions.done, (id, action) => updeep_1.default.map(updeep_1.default.if(updeep_1.default.is('id', id), todo.upreducer(action))), true);
test('* for mapping works', () => {
const reducer = todos.reducer;
let state = [{ id: 0 }, { id: 1 }];
state = reducer(state, todos.actions.review());
state = reducer(state, todos.actions.done(1));
expect(state).toEqual([
{ id: 0, reviewed: true },
{ id: 1, reviewed: true, done: true },
]);
});
//# sourceMappingURL=mappedUpdux.test.js.map

View File

@ -1 +0,0 @@
{"version":3,"file":"mappedUpdux.test.js","sourceRoot":"","sources":["../src/mappedUpdux.test.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAC5B,oDAAuB;AAEvB,MAAM,IAAI,GAAG,IAAI,eAAK,CAAC;IACnB,SAAS,EAAE;QACP,MAAM,EAAE,GAAG,EAAE,CAAC,gBAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAC,CAAC;QAClC,IAAI,EAAE,GAAG,EAAE,CAAC,gBAAC,CAAC,EAAC,IAAI,EAAE,IAAI,EAAC,CAAC;KAC9B;CACJ,CAAC,CAAC;AAEH,MAAM,KAAK,GAAG,IAAI,eAAK,CAAC;IACpB,QAAQ,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE;CAC1B,CAAC,CAAC;AAEH,KAAK,CAAC,WAAW,CACb,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,EAAC,MAAM,EAAE,EAAE,CAAC,gBAAC,CAAC,GAAG,CAAC,gBAAC,CAAC,EAAE,CAAC,gBAAC,CAAC,EAAE,CAAC,IAAI,EAAC,EAAE,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAC7F,CAAC;AAEF,IAAI,CAAE,qBAAqB,EAAE,GAAG,EAAE;IAC9B,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;IAC9B,IAAI,KAAK,GAAG,CAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAC,EAAE,EAAE,CAAC,EAAE,CAAE,CAAC;IACpC,KAAK,GAAG,OAAO,CAAE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,CAAE,CAAC;IACjD,KAAK,GAAG,OAAO,CAAE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,CAAC;IAEhD,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;QAClB,EAAE,EAAE,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE;QACzB,EAAE,EAAE,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE;KACxC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}

View File

@ -1,2 +0,0 @@
export {};
//# sourceMappingURL=middleware.test.d.ts.map

View File

@ -1 +0,0 @@
{"version":3,"file":"middleware.test.d.ts","sourceRoot":"","sources":["../src/middleware.test.ts"],"names":[],"mappings":""}

View File

@ -1,112 +0,0 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = __importDefault(require("."));
test('simple effect', () => {
const tracer = jest.fn();
const store = new _1.default({
effects: {
foo: (api) => (next) => (action) => {
tracer();
next(action);
},
},
}).createStore();
expect(tracer).not.toHaveBeenCalled();
store.dispatch({ type: 'bar' });
expect(tracer).not.toHaveBeenCalled();
store.dispatch.foo();
expect(tracer).toHaveBeenCalled();
});
test('effect and sub-effect', () => {
const tracer = jest.fn();
const tracerEffect = (signature) => (api) => (next) => (action) => {
tracer(signature);
next(action);
};
const store = new _1.default({
effects: {
foo: tracerEffect('root'),
},
subduxes: {
zzz: {
effects: {
foo: tracerEffect('child'),
},
},
},
}).createStore();
expect(tracer).not.toHaveBeenCalled();
store.dispatch({ type: 'bar' });
expect(tracer).not.toHaveBeenCalled();
store.dispatch.foo();
expect(tracer).toHaveBeenNthCalledWith(1, 'root');
expect(tracer).toHaveBeenNthCalledWith(2, 'child');
});
test('"*" effect', () => {
const tracer = jest.fn();
const store = new _1.default({
effects: {
'*': api => next => action => {
tracer();
next(action);
},
},
}).createStore();
expect(tracer).not.toHaveBeenCalled();
store.dispatch({ type: 'bar' });
expect(tracer).toHaveBeenCalled();
});
test('async effect', async () => {
function timeout(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
const tracer = jest.fn();
const store = new _1.default({
effects: {
foo: api => next => async (action) => {
next(action);
await timeout(1000);
tracer();
},
},
}).createStore();
expect(tracer).not.toHaveBeenCalled();
store.dispatch.foo();
expect(tracer).not.toHaveBeenCalled();
await timeout(1000);
expect(tracer).toHaveBeenCalled();
});
test('getState is local', () => {
let childState;
let rootState;
let rootFromChild;
const child = new _1.default({
initial: { alpha: 12 },
effects: {
doIt: ({ getState, getRootState }) => next => action => {
childState = getState();
rootFromChild = getRootState();
next(action);
},
},
});
const root = new _1.default({
initial: { beta: 24 },
subduxes: { child },
effects: {
doIt: ({ getState }) => next => action => {
rootState = getState();
next(action);
},
},
});
const store = root.createStore();
store.dispatch.doIt();
expect(rootState).toEqual({ beta: 24, child: { alpha: 12 } });
expect(rootFromChild).toEqual({ beta: 24, child: { alpha: 12 } });
expect(childState).toEqual({ alpha: 12 });
});
//# sourceMappingURL=middleware.test.js.map

View File

@ -1 +0,0 @@
{"version":3,"file":"middleware.test.js","sourceRoot":"","sources":["../src/middleware.test.ts"],"names":[],"mappings":";;;;;AAAA,yCAAsB;AAGtB,IAAI,CAAC,eAAe,EAAE,GAAG,EAAE;IACzB,MAAM,MAAM,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;IAEzB,MAAM,KAAK,GAAG,IAAI,UAAK,CAAC;QACtB,OAAO,EAAE;YACP,GAAG,EAAE,CAAC,GAAQ,EAAE,EAAE,CAAC,CAAC,IAAS,EAAE,EAAE,CAAC,CAAC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BACrC,SAAS,GAAG,QAAQ,EAAE,CAAC;gBACvB,IAAI,CAAC,MAAM,CAAC,CAAC;YACf,CAAC;SACF;KACF,CAAC,CAAC;IAEH,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IACjC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;IAEtB,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,EAAC,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,EAAC,KAAK,EAAE,EAAE,EAAC,EAAC,CAAC,CAAC;IAC1D,MAAM,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,EAAC,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,EAAC,KAAK,EAAE,EAAE,EAAC,EAAC,CAAC,CAAC;IAC9D,MAAM,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,EAAC,KAAK,EAAE,EAAE,EAAC,CAAC,CAAC;AAC1C,CAAC,CAAC,CAAC"}

2
dist/sink.test.d.ts vendored
View File

@ -1,2 +0,0 @@
export {};
//# sourceMappingURL=sink.test.d.ts.map

View File

@ -1 +0,0 @@
{"version":3,"file":"sink.test.d.ts","sourceRoot":"","sources":["../src/sink.test.ts"],"names":[],"mappings":""}

46
dist/sink.test.js vendored
View File

@ -1,46 +0,0 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const updux_1 = __importDefault(require("./updux"));
const foo = new updux_1.default({
initial: 0,
mutations: {
doIt: () => (state) => {
return state + 1;
},
doTheThing: () => (state) => {
return state + 3;
},
},
});
const bar = new updux_1.default({
subduxes: { foo },
});
bar.addMutation(foo.actions.doTheThing, (_, action) => state => {
return {
...state,
baz: bar.subduxUpreducer(action)(state),
};
}, true);
bar.addMutation(foo.actions.doIt, () => (state) => ({ ...state, bar: 'yay' }), true);
test('initial', () => {
expect(bar.initial).toEqual({ foo: 0 });
});
test('foo alone', () => {
expect(foo.reducer(undefined, foo.actions.doIt())).toEqual(1);
});
test('sink mutations', () => {
expect(bar.reducer(undefined, bar.actions.doIt())).toEqual({
foo: 0,
bar: 'yay',
});
});
test('sink mutation and subduxUpreducer', () => {
expect(bar.reducer(undefined, bar.actions.doTheThing())).toEqual({
foo: 0,
baz: { foo: 3 },
});
});
//# sourceMappingURL=sink.test.js.map

View File

@ -1 +0,0 @@
{"version":3,"file":"sink.test.js","sourceRoot":"","sources":["../src/sink.test.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAE5B,MAAM,GAAG,GAAG,IAAI,eAAK,CAAS;IAC5B,OAAO,EAAE,CAAC;IACV,SAAS,EAAE;QACT,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,KAAa,EAAE,EAAE;YAC5B,OAAO,KAAK,GAAG,CAAC,CAAC;QACnB,CAAC;QACD,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,KAAa,EAAE,EAAE;YAClC,OAAO,KAAK,GAAG,CAAC,CAAC;QACnB,CAAC;KACF;CACF,CAAC,CAAC;AAEH,MAAM,GAAG,GAAG,IAAI,eAAK,CAAgB;IACnC,QAAQ,EAAE,EAAC,GAAG,EAAC;CAChB,CAAC,CAAC;AAEH,GAAG,CAAC,WAAW,CACb,GAAG,CAAC,OAAO,CAAC,UAAU,EACtB,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE;IACrB,OAAO;QACL,GAAG,KAAK;QACR,GAAG,EAAE,GAAG,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC;KACxC,CAAC;AACJ,CAAC,EACD,IAAI,CACL,CAAC;AAEF,GAAG,CAAC,WAAW,CACb,GAAG,CAAC,OAAO,CAAC,IAAI,EAChB,GAAG,EAAE,CAAC,CAAC,KAAU,EAAE,EAAE,CAAC,CAAC,EAAC,GAAG,KAAK,EAAE,GAAG,EAAE,KAAK,EAAC,CAAC,EAC9C,IAAI,CACL,CAAC;AAEF,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE;IACnB,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,EAAC,GAAG,EAAE,CAAC,EAAC,CAAC,CAAC;AACxC,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE;IACrB,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAChE,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC1B,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QACzD,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,KAAK;KACX,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,mCAAmC,EAAE,GAAG,EAAE;IAC7C,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QAC/D,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,EAAC,GAAG,EAAE,CAAC,EAAC;KACd,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}

View File

@ -1,2 +0,0 @@
export {};
//# sourceMappingURL=splat.test.d.ts.map

View File

@ -1 +0,0 @@
{"version":3,"file":"splat.test.d.ts","sourceRoot":"","sources":["../src/splat.test.ts"],"names":[],"mappings":""}

55
dist/splat.test.js vendored
View File

@ -1,55 +0,0 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = __importDefault(require("."));
const updeep_1 = __importDefault(require("updeep"));
const tracer = (chr) => updeep_1.default({ tracer: (s = '') => s + chr });
test('mutations, simple', () => {
const dux = new _1.default({
mutations: {
foo: () => tracer('a'),
'*': () => tracer('b'),
},
});
const store = dux.createStore();
expect(store.getState()).toEqual({ tracer: 'b' });
store.dispatch.foo();
expect(store.getState()).toEqual({ tracer: 'ba', });
store.dispatch({ type: 'bar' });
expect(store.getState()).toEqual({ tracer: 'bab', });
});
test('with subduxes', () => {
const dux = new _1.default({
mutations: {
foo: () => tracer('a'),
'*': () => tracer('b'),
bar: () => ({ bar }) => ({ bar, tracer: bar.tracer })
},
subduxes: {
bar: {
mutations: {
foo: () => tracer('d'),
'*': () => tracer('e'),
},
},
},
});
const store = dux.createStore();
expect(store.getState()).toEqual({
tracer: 'b',
bar: { tracer: 'e' }
});
store.dispatch.foo();
expect(store.getState()).toEqual({
tracer: 'ba',
bar: { tracer: 'ed' }
});
store.dispatch({ type: 'bar' });
expect(store.getState()).toEqual({
tracer: 'ede',
bar: { tracer: 'ede' }
});
});
//# sourceMappingURL=splat.test.js.map

View File

@ -1 +0,0 @@
{"version":3,"file":"splat.test.js","sourceRoot":"","sources":["../src/splat.test.ts"],"names":[],"mappings":";;;;;AAAA,yCAAsB;AACtB,oDAAuB;AAEvB,MAAM,MAAM,GAAG,CAAC,GAAU,EAAE,EAAE,CAAC,gBAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,GAAC,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC;AAEhE,IAAI,CAAE,mBAAmB,EAAE,GAAG,EAAE;IAC5B,MAAM,GAAG,GAAG,IAAI,UAAK,CAAC;QAClB,SAAS,EAAE;YACP,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC;YACtB,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC;SACzB;KACJ,CAAC,CAAC;IAEJ,MAAM,KAAK,GAAG,GAAG,CAAC,WAAW,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GAAG,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE;KAAE,CAAC,CAAC;IAE5B,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;IAErB,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC;QAC7B,MAAM,EAAE,IAAI;QACZ,GAAG,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;KAAE,CAAC,CAAC;IAE7B,KAAK,CAAC,QAAQ,CAAC,EAAC,IAAI,EAAE,KAAK,EAAC,CAAC,CAAC;IAE9B,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC;QAC7B,MAAM,EAAE,KAAK;QACb,GAAG,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE;KAAE,CAAC,CAAC;AAGlC,CAAC,CAAC,CAAC"}

2
dist/test.d.ts vendored
View File

@ -1,2 +0,0 @@
export {};
//# sourceMappingURL=test.d.ts.map

1
dist/test.d.ts.map vendored
View File

@ -1 +0,0 @@
{"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":""}

153
dist/test.js vendored
View File

@ -1,153 +0,0 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = __importDefault(require("."));
test('actions from mutations', () => {
const { actions: { foo, bar }, } = new _1.default({
mutations: {
foo: () => (x) => x,
},
});
expect(foo()).toEqual({ type: 'foo' });
expect(foo(true)).toEqual({ type: 'foo', payload: true });
expect(foo({ bar: 2 }, { timestamp: 613 })).toEqual({
type: 'foo',
payload: { bar: 2 },
meta: { timestamp: 613 },
});
});
test('reducer', () => {
const { actions, reducer } = new _1.default({
initial: { counter: 1 },
mutations: {
inc: () => ({ counter }) => ({ counter: counter + 1 }),
},
});
let state = reducer(undefined, { type: 'noop' });
expect(state).toEqual({ counter: 1 });
state = reducer(state, actions.inc());
expect(state).toEqual({ counter: 2 });
});
test('sub reducers', () => {
const foo = new _1.default({
initial: 1,
mutations: {
doFoo: () => (x) => x + 1,
doAll: () => (x) => x + 10,
},
});
const bar = new _1.default({
initial: 'a',
mutations: {
doBar: () => (x) => x + 'a',
doAll: () => (x) => x + 'b',
}
});
const { initial, actions, reducer } = new _1.default({
subduxes: {
foo, bar
}
});
expect(initial).toEqual({ foo: 1, bar: 'a' });
expect(Object.keys(actions)).toHaveLength(3);
let state = reducer(undefined, { type: 'noop' });
expect(state).toEqual({ foo: 1, bar: 'a' });
state = reducer(state, actions.doFoo());
expect(state).toEqual({ foo: 2, bar: 'a' });
state = reducer(state, actions.doBar());
expect(state).toEqual({ foo: 2, bar: 'aa' });
state = reducer(state, actions.doAll());
expect(state).toEqual({ foo: 12, bar: 'aab' });
});
test('precedence between root and sub-reducers', () => {
const { initial, reducer, actions, } = new _1.default({
initial: {
foo: { bar: 4 },
},
mutations: {
inc: () => (state) => {
return {
...state,
surprise: state.foo.bar
};
}
},
subduxes: {
foo: {
initial: {
bar: 2,
quux: 3,
},
mutations: {
inc: () => (state) => ({ ...state, bar: state.bar + 1 })
},
},
}
});
expect(initial).toEqual({
foo: { bar: 4, quux: 3 }
});
expect(reducer(undefined, actions.inc())).toEqual({
foo: { bar: 5, quux: 3 }, surprise: 5
});
});
function timeout(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
test('middleware', async () => {
const { middleware, createStore } = new _1.default({
initial: "",
mutations: {
inc: (addition) => (state) => state + addition,
doEeet: () => (state) => {
return state + 'Z';
},
},
effects: {
doEeet: api => next => async (action) => {
api.dispatch.inc('a');
next(action);
await timeout(1000);
api.dispatch.inc('c');
}
},
subduxes: {
foo: {
effects: {
doEeet: (api) => (next) => (action) => {
api.dispatch({ type: 'inc', payload: 'b' });
next(action);
}
}
},
}
});
const store = createStore();
store.dispatch.doEeet();
expect(store.getState()).toEqual('abZ');
await timeout(1000);
expect(store.getState()).toEqual('abZc');
});
test("subduxes and mutations", () => {
const foo = new _1.default({ mutations: {
quux: () => () => 'x',
blart: () => () => 'a',
} });
const bar = new _1.default({ mutations: {
quux: () => () => 'y'
} });
const baz = new _1.default({
mutations: {
quux: () => (state) => ({ ...state, "baz": "z" })
}, subduxes: { foo, bar }
});
let state = baz.reducer(undefined, baz.actions.quux());
expect(state).toEqual({
foo: "x",
bar: "y",
baz: "z",
});
});
//# sourceMappingURL=test.js.map

1
dist/test.js.map vendored

File diff suppressed because one or more lines are too long

38
dist/types.d.ts vendored
View File

@ -1,38 +0,0 @@
import { Dispatch } from 'redux';
declare type MaybePayload<P> = P extends object | string | boolean | number ? {
payload: P;
} : {
payload?: P;
};
export declare type Action<T extends string = string, P = any> = {
type: T;
} & MaybePayload<P>;
export declare type Dictionary<T> = {
[key: string]: T;
};
export declare type Mutation<S = any, A extends Action = Action> = (payload: A['payload'], action: A) => (state: S) => S;
export declare type ActionPayloadGenerator = (...args: any[]) => any;
export declare type ActionCreator<T extends string = string, P = any> = {
type: T;
_genericAction?: boolean;
} & ((...args: any[]) => Action<T, P>);
export declare type UpduxDispatch = Dispatch & Dictionary<Function>;
export declare type UpduxConfig<S = any> = {
initial?: S;
subduxes?: {};
actions?: {
[type: string]: ActionCreator;
};
mutations?: any;
groomMutations?: (m: Mutation<S>) => Mutation<S>;
effects?: Dictionary<UpduxMiddleware<S>>;
};
export declare type Upreducer<S = any> = (action: Action) => (state: S) => S;
export interface UpduxMiddlewareAPI<S> {
dispatch: UpduxDispatch;
getState(): any;
getRootState(): S;
}
export declare type UpduxMiddleware<S = any> = (api: UpduxMiddlewareAPI<S>) => (next: UpduxDispatch) => (action: Action) => any;
export {};
//# sourceMappingURL=types.d.ts.map

1
dist/types.d.ts.map vendored
View File

@ -1 +0,0 @@
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAa,MAAM,OAAO,CAAC;AAE3C,aAAK,YAAY,CAAC,CAAC,IAAI,C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IAgEF,SAAS,CAAC,EAAE,GAAG,CAAC;IAEhB,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC;IAqBjD,OAAO,CAAC,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;CAC1C,CAAC;AAEF,oBAAY,SAAS,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;AAErE,MAAM,WAAW,kBAAkB,CAAC,CAAC;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,QAAQ,IAAI,GAAG,CAAC;IAChB,YAAY,IAAI,CAAC,CAAA;CAEpB;AACD,oBAAY,eAAe,CAAC,CAAC,GAAC,GAAG,IAAI,CAAC,GAAG,EAAE,kBAAkB,CAAC,CAAC,CAAC,KAAM,CAAE,IAAI,EAAE,aAAa,KAAM,CAAE,MAAM,EAAE,MAAM,KAAM,GAAG,CAAC"}

3
dist/types.js vendored
View File

@ -1,3 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map

1
dist/types.js.map vendored
View File

@ -1 +0,0 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}

31
dist/updux.d.ts vendored
View File

@ -1,31 +0,0 @@
import { UpduxConfig, Dictionary, Action, ActionCreator, Mutation, Upreducer, UpduxMiddleware } from './types';
import { Store } from 'redux';
export { actionCreator } from './buildActions';
declare type StoreWithDispatchActions<S = any, Actions = {
[action: string]: (...args: any) => Action;
}> = Store<S> & {
dispatch: {
[type in keyof Actions]: (...args: any) => void;
};
};
export declare type Dux<S> = Pick<Updux<S>, 'subduxes' | 'actions' | 'initial' | 'mutations' | 'reducer' | 'middleware' | 'createStore' | 'upreducer'>;
export declare class Updux<S = any> {
subduxes: Dictionary<Updux>;
initial: S;
groomMutations: (mutation: Mutation<S>) => Mutation<S>;
private localEffects;
private localActions;
private localMutations;
constructor(config?: UpduxConfig);
readonly middleware: UpduxMiddleware<S>;
readonly actions: Dictionary<ActionCreator>;
readonly upreducer: Upreducer<S>;
readonly reducer: (state: S | undefined, action: Action) => S;
readonly mutations: Dictionary<Mutation<S>>;
readonly subduxUpreducer: Upreducer<any>;
readonly createStore: () => StoreWithDispatchActions<S>;
readonly asDux: Dux<S>;
addMutation<A extends ActionCreator>(creator: A, mutation: Mutation<S, A extends (...args: any[]) => infer R ? R : never>, isSink?: boolean): void;
}
export default Updux;
//# sourceMappingURL=updux.d.ts.map

1
dist/updux.d.ts.map vendored
View File

@ -1 +0,0 @@
{"version":3,"file":"updux.d.ts","sourceRoot":"","sources":["../src/updux.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,WAAW,EACX,UAAU,EACV,MAAM,EACN,aAAa,EACb,QAAQ,EACR,SAAS,EAET,eAAe,EAChB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAa,KAAK,EAAC,MAAM,OAAO,CAAC;AACxC,OAAO,EAAC,aAAa,EAAC,MAAM,gBAAgB,CAAC;AAE7C,aAAK,wBAAwB,CAC3B,CAAC,GAAG,GAAG,EACP,OAAO,GAAG;IAAC,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,MAAM,CAAA;CAAC,IACpD,KAAK,CAAC,CAAC,CAAC,GAAG;IACb,QAAQ,EAAE;SAAE,IAAI,IAAI,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,IAAI;KAAC,CAAC;CAC7D,CAAC;AAEF,oBAAY,GAAG,CAAC,CAAC,IAAI,IAAI,CACvB,KAAK,CAAC,CAAC,CAAC,EACN,UAAU,GACV,SAAS,GACT,SAAS,GACT,WAAW,GACX,SAAS,GACT,YAAY,GACZ,aAAa,GACb,WAAW,CACd,CAAC;AASF,qBAAa,KAAK,CAAC,CAAC,GAAG,GAAG;IACxB,QAAQ,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;IAS5B,OAAO,EAAE,CAAC,CAAC;IAqCX,cAAc,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC;IAE3C,OAAO,CAAC,YAAY,CAE9B;IAEU,OAAO,CAAC,YAAY,CAA4B;IAEhD,OAAO,CAAC,cAAc,CAEhC;gBAEU,MAAM,GAAE,WAAgB;aA6BtB,UAAU,EAAI,eAAe,CAAC,CAAC,CAAC;aAsBhC,OAAO,EAAI,UAAU,CAAC,aAAa,CAAC;aAYpC,SAAS,EAAI,SAAS,CAAC,CAAC,CAAC;aAQzB,OAAO,EAAI,CAAC,KAAK,EAAE,CAAC,GAAG,SAAS,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;aAStD,SAAS,EAAI,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;aAqBpC,eAAe;aA6Bf,WAAW,EAAI,MAAM,wBAAwB,CAAC,CAAC,CAAC;aAiB1D,KAAK,EAAI,GAAG,CAAC,CAAC,CAAC;IAyBnB,WAAW,CAAC,CAAC,SAAS,aAAa,EACjC,OAAO,EAAE,CAAC,EACV,QAAQ,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,EACxE,MAAM,CAAC,EAAE,OAAO;CAQnB;AAED,eAAe,KAAK,CAAC"}

105
dist/updux.js vendored
View File

@ -1,105 +0,0 @@
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fp_1 = __importDefault(require("lodash/fp"));
const mobx_1 = require("mobx");
const buildActions_1 = __importDefault(require("./buildActions"));
const buildInitial_1 = __importDefault(require("./buildInitial"));
const buildMutations_1 = __importDefault(require("./buildMutations"));
const buildCreateStore_1 = __importDefault(require("./buildCreateStore"));
const buildMiddleware_1 = __importDefault(require("./buildMiddleware"));
const buildUpreducer_1 = __importDefault(require("./buildUpreducer"));
var buildActions_2 = require("./buildActions");
exports.actionCreator = buildActions_2.actionCreator;
class Updux {
constructor(config = {}) {
this.groomMutations = config.groomMutations || ((x) => x);
this.subduxes = fp_1.default.mapValues((value) => fp_1.default.isPlainObject(value) ? new Updux(value) : value)(fp_1.default.getOr({}, 'subduxes', config));
this.localActions = fp_1.default.getOr({}, 'actions', config);
this.localEffects = fp_1.default.getOr({}, 'effects', config);
this.initial = buildInitial_1.default(config.initial, fp_1.default.mapValues(({ initial }) => initial)(this.subduxes));
this.localMutations = fp_1.default.mapValues((m) => this.groomMutations(m))(fp_1.default.getOr({}, 'mutations', config));
}
get middleware() {
return buildMiddleware_1.default(this.localEffects, this.actions, this.subduxes);
}
get actions() {
return buildActions_1.default(this.localActions, [...Object.keys(this.localMutations), ...Object.keys(this.localEffects)], fp_1.default.flatten(Object.values(this.subduxes).map(({ actions }) => Object.entries(actions))));
}
get upreducer() {
return buildUpreducer_1.default(this.initial, this.mutations);
}
get reducer() {
return (state, action) => this.upreducer(action)(state);
}
get mutations() {
return buildMutations_1.default(this.localMutations, this.subduxes);
}
get subduxUpreducer() {
return buildUpreducer_1.default(this.initial, buildMutations_1.default({}, this.subduxes));
}
get createStore() {
const actions = this.actions;
return buildCreateStore_1.default(this.reducer, this.initial, this.middleware, this.actions);
}
get asDux() {
return {
createStore: this.createStore,
upreducer: this.upreducer,
subduxes: this.subduxes,
middleware: this.middleware,
actions: this.actions,
reducer: this.reducer,
mutations: this.mutations,
initial: this.initial,
};
}
addMutation(creator, mutation, isSink) {
this.localActions[creator.type] = creator;
this.localMutations[creator.type] = [
this.groomMutations(mutation),
isSink,
];
}
}
__decorate([
mobx_1.observable
], Updux.prototype, "localEffects", void 0);
__decorate([
mobx_1.observable
], Updux.prototype, "localActions", void 0);
__decorate([
mobx_1.observable
], Updux.prototype, "localMutations", void 0);
__decorate([
mobx_1.computed
], Updux.prototype, "middleware", null);
__decorate([
mobx_1.computed
], Updux.prototype, "actions", null);
__decorate([
mobx_1.computed
], Updux.prototype, "upreducer", null);
__decorate([
mobx_1.computed
], Updux.prototype, "reducer", null);
__decorate([
mobx_1.computed
], Updux.prototype, "mutations", null);
__decorate([
mobx_1.computed
], Updux.prototype, "subduxUpreducer", null);
__decorate([
mobx_1.computed
], Updux.prototype, "createStore", null);
exports.Updux = Updux;
exports.default = Updux;
//# sourceMappingURL=updux.js.map

1
dist/updux.js.map vendored
View File

@ -1 +0,0 @@
{"version":3,"file":"updux.js","sourceRoot":"","sources":["../src/updux.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,mDAA2B;AAE3B,+BAAgD;AAEhD,kEAA0C;AAC1C,kEAA0C;AAC1C,sEAA8C;AAE9C,0EAAkD;AAClD,wEAAgD;AAChD,sEAA8C;AAa9C,+CAA6C;AAArC,uCAAA,aAAa,CAAA;AA4BrB,MAAa,KAAK;IA2DhB,YAAY,SAAsB,EAAE;QAClC,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,IAAI,CAAC,CAAC,CAAc,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;QAEvE,IAAI,CAAC,QAAQ,GAAG,YAAE,CAAC,SAAS,CAAC,CAAC,KAA0B,EAAE,EAAE,CAC1D,YAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IA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QAC1C,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG;YAClC,IAAI,CAAC,cAAc,CAAC,QAAe,CAAgB;YACnD,MAAM;SACP,CAAC;IACJ,CAAC;CACF;AAjMa;IAAX,iBAAU;2CAET;AAEU;IAAX,iBAAU;2CAAiD;AAEhD;IAAX,iBAAU;6CAET;AA+BQ;IAAT,eAAQ;uCAMR;AAgBS;IAAT,eAAQ;oCAUR;AAES;IAAT,eAAQ;sCAER;AAMS;IAAT,eAAQ;oCAER;AAOS;IAAT,eAAQ;sCAER;AAmBS;IAAT,eAAQ;4CAER;AA2BS;IAAT,eAAQ;wCASR;AAtMH,sBAkPC;AAED,kBAAe,KAAK,CAAC"}

View File

@ -1,5 +1,20 @@
# Updux concepts # Updux concepts
## actions
Updux internally uses the package `ts-action` to create action creator
functions. Even if you don't use typescript, I recommend that you use it,
as it does what it does very well. But if you don't want to, no big deal.
Updux will recognize a function as an action creator if it has a `type`
property. So a homegrown creator could be as simple as:
```js
function action(type) {
return Object.assign( payload => ({type, payload}), { type } )
}
```
## effects ## effects
Updux effects are a superset of redux middleware. I kept that format, and the Updux effects are a superset of redux middleware. I kept that format, and the

2948
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,23 +1,23 @@
{ {
"dependencies": { "dependencies": {
"lodash": "^4.17.15", "lodash": "^4.17.15",
"mobx": "^5.14.2", "redux": "^4.0.4",
"redux": "^4.0.4" "ts-action": "^11.0.0",
"updeep": "^1.2.0"
}, },
"devDependencies": { "devDependencies": {
"docsify": "^4.10.2",
"docsify-cli": "^4.4.0",
"@babel/cli": "^7.6.4", "@babel/cli": "^7.6.4",
"@babel/core": "^7.6.4", "@babel/core": "^7.6.4",
"@babel/preset-env": "^7.6.3", "@babel/preset-env": "^7.6.3",
"@types/jest": "^24.0.19", "@types/jest": "^24.0.19",
"@types/lodash": "^4.14.144", "@types/lodash": "^4.14.144",
"babel-jest": "^24.9.0", "babel-jest": "^24.9.0",
"docsify": "^4.10.2",
"docsify-cli": "^4.4.0",
"jest": "^24.9.0", "jest": "^24.9.0",
"ts-jest": "^24.1.0", "ts-jest": "^24.1.0",
"tsd": "^0.10.0", "tsd": "^0.10.0",
"typescript": "^3.6.4", "typescript": "^3.6.4"
"updeep": "^1.2.0"
}, },
"license": "MIT", "license": "MIT",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -1,26 +1,27 @@
import Updux, {actionCreator} from '.'; import { action, payload } from 'ts-action';
import u from 'updeep'; import u from 'updeep';
import Updux from '.';
const noopEffect = () => () => () => {}; const noopEffect = () => () => () => {};
test('actions defined in effects and mutations, multi-level', () => { test('actions defined in effects and mutations, multi-level', () => {
const bar = action('bar',(payload,meta) => ({payload,meta}) );
const foo = action('foo',(limit:number) => ({payload:{ limit} }) );
const {actions} = new Updux({ const {actions} = new Updux({
effects: { effects: [ [ foo, noopEffect ] ],
foo: noopEffect, mutations: [ [ bar, () => () => null ] ],
},
mutations: {bar: () => () => null},
subduxes: { subduxes: {
mysub: { mysub: {
effects: {baz: noopEffect}, effects: {baz: noopEffect},
mutations: {quux: () => () => null}, mutations: {quux: () => () => null},
actions: { actions: {
foo: (limit: number) => ({limit}), foo
}, },
}, },
myothersub: { myothersub: {
effects: { effects: [ [foo, noopEffect] ],
foo: noopEffect,
},
}, },
}, },
}); });
@ -32,7 +33,7 @@ test('actions defined in effects and mutations, multi-level', () => {
expect(actions.bar()).toEqual({type: 'bar'}); expect(actions.bar()).toEqual({type: 'bar'});
expect(actions.bar('xxx')).toEqual({type: 'bar', payload: 'xxx'}); expect(actions.bar('xxx')).toEqual({type: 'bar', payload: 'xxx'});
expect(actions.bar(undefined, 'yyy')).toEqual({type: 'bar', meta: 'yyy'}); expect(actions.bar(undefined, 'yyy')).toEqual({type: 'bar', payload: undefined, meta: 'yyy'});
expect(actions.foo(12)).toEqual({type: 'foo', payload: {limit: 12}}); expect(actions.foo(12)).toEqual({type: 'foo', payload: {limit: 12}});
}); });
@ -41,23 +42,15 @@ describe('different calls to addAction', () => {
const updux = new Updux(); const updux = new Updux();
test('string', () => { test('string', () => {
updux.addAction('foo'); updux.addAction( action('foo', payload() ));
expect(updux.actions.foo('yo')).toMatchObject({ expect(updux.actions.foo('yo')).toMatchObject({
type: 'foo', type: 'foo',
payload: 'yo', payload: 'yo',
}); });
}); });
test('actionCreator', () => {
const bar = actionCreator('bar', null);
updux.addAction(bar);
expect(updux.actions.bar()).toMatchObject({
type: 'bar',
});
});
test('actionCreator inlined', () => { test('actionCreator inlined', () => {
updux.addAction('baz', (x) => ({x})); updux.addAction( 'baz', (x) => ({payload: {x}}));
expect(updux.actions.baz(3)).toMatchObject({ expect(updux.actions.baz(3)).toMatchObject({
type: 'baz', payload: { x: 3 } type: 'baz', payload: { x: 3 }
}); });

View File

@ -1,4 +1,6 @@
import Updux, { actionCreator } from "./updux"; import { action } from 'ts-action';
import Updux from "./updux";
type MyState = { type MyState = {
sum: number; sum: number;
@ -9,7 +11,7 @@ test("added mutation is present", () => {
initial: { sum: 0 } initial: { sum: 0 }
}); });
const add = actionCreator("add", (n: number) => ({ n })); const add = action("add", (n: number) => ({ payload: { n } }));
updux.addMutation(add, ({ n }, action) => ({ sum }) => ({ sum: sum + n })); updux.addMutation(add, ({ n }, action) => ({ sum }) => ({ sum: sum + n }));

View File

@ -1,47 +1,9 @@
import fp from 'lodash/fp'; import fp from 'lodash/fp';
import { import {
Action,
ActionCreator, ActionCreator,
ActionPayloadGenerator,
Dictionary, Dictionary,
} from '../types'; } from '../types';
export function actionCreator<T extends string, P extends any>(
type: T,
transform: (...args: any[]) => P
): ActionCreator<T, P>;
export function actionCreator<T extends string>(
type: T,
transform: null
): ActionCreator<T, null>;
export function actionCreator<T extends string>(
type: T
): ActionCreator<T, undefined>;
export function actionCreator(type: any, transform?: any) {
if (transform) {
return Object.assign(
(...args: any[]) => ({ type, payload: transform(...args) }),
{ type }
);
}
if (transform === null) {
return Object.assign(() => ({ type }), { type });
}
return Object.assign((payload: unknown) => ({ type, payload }), { type });
}
export function actionFor(type: string): ActionCreator {
const f = (payload = undefined, meta = undefined) =>
fp.pickBy(v => v !== undefined)({ type, payload, meta }) as Action;
return Object.assign(f, {
_genericAction: true,
type,
});
}
type ActionPair = [string, ActionCreator]; type ActionPair = [string, ActionCreator];
function buildActions(actions: ActionPair[] = []): Dictionary<ActionCreator> { function buildActions(actions: ActionPair[] = []): Dictionary<ActionCreator> {

View File

@ -3,6 +3,4 @@ import Updux from "./updux";
export { default as Updux } from "./updux"; export { default as Updux } from "./updux";
export { UpduxConfig } from "./types"; export { UpduxConfig } from "./types";
export { actionCreator } from "./buildActions";
export default Updux; export default Updux;

View File

@ -1,5 +1,7 @@
import Updux, { actionCreator } from '.';
import u from 'updeep'; import u from 'updeep';
import { action, payload } from 'ts-action';
import Updux from '.';
import mwUpdux from './middleware_aux'; import mwUpdux from './middleware_aux';
test('simple effect', () => { test('simple effect', () => {
@ -179,7 +181,7 @@ test('middleware as map', () => {
let rootState; let rootState;
let rootFromChild; let rootFromChild;
const doIt = actionCreator('doIt'); const doIt = action('doIt', () => ({payload: ''}));
const child = new Updux({ const child = new Updux({
initial: '', initial: '',

View File

@ -1,7 +1,9 @@
import Updux, { actionCreator } from "./updux"; import { action } from 'ts-action';
import Updux from "./updux";
describe("as array of arrays", () => { describe("as array of arrays", () => {
const doIt = actionCreator("doIt"); const doIt = action("doIt");
const updux = new Updux({ const updux = new Updux({
initial: "", initial: "",

View File

@ -13,11 +13,6 @@ test('actions from mutations', () => {
expect(foo(true)).toEqual({type: 'foo', payload: true}); expect(foo(true)).toEqual({type: 'foo', payload: true});
expect(foo({bar: 2}, {timestamp: 613})).toEqual({
type: 'foo',
payload: {bar: 2},
meta: {timestamp: 613},
});
}); });
test('reducer', () => { test('reducer', () => {

View File

@ -1,7 +1,8 @@
import fp from "lodash/fp"; import fp from "lodash/fp";
import u from "updeep"; import u from "updeep";
import { action, payload } from 'ts-action';
import buildActions, { actionFor, actionCreator } from "./buildActions"; import buildActions from "./buildActions";
import buildInitial from "./buildInitial"; import buildInitial from "./buildInitial";
import buildMutations from "./buildMutations"; import buildMutations from "./buildMutations";
@ -24,7 +25,6 @@ import {
import { Middleware, Store, PreloadedState } from "redux"; import { Middleware, Store, PreloadedState } from "redux";
import buildSelectors from "./buildSelectors"; import buildSelectors from "./buildSelectors";
export { actionCreator } from "./buildActions";
type StoreWithDispatchActions< type StoreWithDispatchActions<
S = any, S = any,
@ -76,9 +76,9 @@ export class Updux<S = any> {
); );
const actions = fp.getOr({}, "actions", config); const actions = fp.getOr({}, "actions", config);
Object.entries(actions).forEach(([type, payload]: [string, any]): any => Object.entries(actions).forEach(([type, p]: [string, any]): any =>
this.addAction( this.addAction(
(payload as any).type ? payload : actionCreator(type, payload as any) (p as any).type ? p : action(type, p)
) )
); );
@ -157,14 +157,23 @@ export class Updux<S = any> {
}; };
} }
addMutation<A extends ActionCreator>( addMutation<A extends ActionCreator=any>(
creator: A, creator: A,
mutation: Mutation<S, A extends (...args: any[]) => infer R ? R : never>, mutation: Mutation<S, A extends (...args: any[]) => infer R ? R : never>,
isSink?: boolean isSink?: boolean
) { )
let c = fp.isFunction(creator) ? creator : actionFor(creator); addMutation<A extends ActionCreator=any>(
creator: string,
this.addAction(c); mutation: Mutation<S, any>,
isSink?: boolean
)
addMutation<A extends ActionCreator=any>(
creator,
mutation,
isSink
)
{
let c = this.addAction(creator);
this.localMutations[c.type] = [ this.localMutations[c.type] = [
this.groomMutations(mutation as any) as Mutation<S>, this.groomMutations(mutation as any) as Mutation<S>,
@ -177,24 +186,34 @@ export class Updux<S = any> {
middleware: UpduxMiddleware<S>, middleware: UpduxMiddleware<S>,
isGenerator: boolean = false isGenerator: boolean = false
) { ) {
let c = fp.isFunction(creator) ? creator : actionFor(creator); const c = this.addAction(creator);
this.addAction(c);
this.localActions[c.type] = c;
this.localEffects.push([c.type, middleware, isGenerator]); this.localEffects.push([c.type, middleware, isGenerator]);
} }
addAction(action: string, transform?: any): ActionCreator<string,any> // can be
addAction(action: ActionCreator<any>, transform?: never): ActionCreator<string,any> //addAction( actionCreator )
addAction(action: any,transform:any) { // addAction( 'foo', transform )
if (typeof action === "string") { addAction(theaction: string, transform?: any): ActionCreator<string,any>
if (!this.localActions[action]) { addAction(theaction: string|ActionCreator<any>, transform?: never): ActionCreator<string,any>
this.localActions[action] = actionCreator(action,transform); addAction(theaction: any,transform:any) {
if (typeof theaction === "string") {
if(transform !== undefined ) {
theaction = action(theaction,transform);
}
else {
theaction = this.actions[theaction] || action(theaction,payload())
} }
return this.localActions[action];
} }
return this.localActions[action.type] = action; const already = this.actions[theaction.type];
if( already ) {
if ( already !== theaction ) {
throw new Error(`action ${theaction.type} already exists`)
}
return already;
}
return this.localActions[theaction.type] = theaction;
} }
get _middlewareEntries() { get _middlewareEntries() {