diff --git a/Changes b/Changes index 2567801..ff88353 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ # Revision history for Updux +0.2.0 2019-10-24 + - Converted everything to Typescript. + 0.1.0 2019-10-22 - Add 'actions' in the config. diff --git a/dist/actions.test.d.ts b/dist/actions.test.d.ts new file mode 100644 index 0000000..930d571 --- /dev/null +++ b/dist/actions.test.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=actions.test.d.ts.map \ No newline at end of file diff --git a/dist/actions.test.d.ts.map b/dist/actions.test.d.ts.map new file mode 100644 index 0000000..a2e7612 --- /dev/null +++ b/dist/actions.test.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"actions.test.d.ts","sourceRoot":"","sources":["../src/actions.test.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/actions.test.js b/dist/actions.test.js index 6107b20..e93beca 100644 --- a/dist/actions.test.js +++ b/dist/actions.test.js @@ -1,60 +1,37 @@ "use strict"; - -var _ = _interopRequireDefault(require(".")); - -var _updeep = _interopRequireDefault(require("updeep")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - +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 - } = (0, _.default)({ - effects: { - foo: api => next => action => {} - }, - mutations: { - bar: () => () => null - }, - subduxes: { - mysub: { + const { actions } = _1.default({ effects: { - baz: api => next => action => {} + foo: noopEffect, }, - mutations: { - quux: () => () => null + mutations: { bar: () => () => null }, + subduxes: { + mysub: { + effects: { baz: noopEffect }, + mutations: { quux: () => () => null }, + actions: { + foo: (limit) => ({ limit }), + }, + }, + myothersub: { + effects: { + foo: noopEffect, + }, + }, }, - actions: { - foo: limit => ({ - limit - }) - } - }, - myothersub: { - effects: { - foo: () => () => () => {} - } - } - } - }); - 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 - } - }); -}); \ No newline at end of file + }); + 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 \ No newline at end of file diff --git a/dist/actions.test.js.map b/dist/actions.test.js.map new file mode 100644 index 0000000..95b6610 --- /dev/null +++ b/dist/actions.test.js.map @@ -0,0 +1 @@ +{"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,EAAE;IACjE,MAAM,EAAC,OAAO,EAAC,GAAG,UAAK,CAAC;QACtB,OAAO,EAAE;YACP,GAAG,EAAE,UAAU;SAChB;QACD,SAAS,EAAE,EAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,EAAC;QAClC,QAAQ,EAAE;YACR,KAAK,EAAE;gBACL,OAAO,EAAE,EAAC,GAAG,EAAE,UAAU,EAAE;gBAC3B,SAAS,EAAE,EAAC,IAAI,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,EAAC;gBACnC,OAAO,EAAE;oBACP,GAAG,EAAE,CAAC,KAAY,EAAE,EAAE,CAAC,CAAC,EAAC,KAAK,EAAC,CAAC;iBACjC;aACF;YACD,UAAU,EAAE;gBACV,OAAO,EAAE;oBACP,GAAG,EAAE,UAAU;iBAChB;aACF;SACF;KACF,CAAC,CAAC;IAEH,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACnC,KAAK,CAAC,IAAI,EAAE,CAAC;IAEb,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IAErD,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,EAAC,IAAI,EAAE,KAAK,EAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,EAAC,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAC,CAAC,CAAC;IAClE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,EAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAC,CAAC,CAAC;IAE1E,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,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"} \ No newline at end of file diff --git a/dist/buildActions/index.d.ts b/dist/buildActions/index.d.ts new file mode 100644 index 0000000..8c3c0bc --- /dev/null +++ b/dist/buildActions/index.d.ts @@ -0,0 +1,9 @@ +import { Action, ActionPayloadGenerator, Dictionary } from '../types'; +interface ActionCreator { + (...args: any[]): Action; + _genericAction?: boolean; +} +declare type ActionPair = [string, ActionCreator]; +declare function buildActions(generators?: Dictionary, actionNames?: string[], subActions?: ActionPair[]): Dictionary; +export default buildActions; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/buildActions/index.d.ts.map b/dist/buildActions/index.d.ts.map new file mode 100644 index 0000000..9850162 --- /dev/null +++ b/dist/buildActions/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/buildActions/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtE,UAAU,aAAa;IACnB,CAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAI,MAAM,CAAC;IAC3B,cAAc,CAAC,EAAE,OAAO,CAAA;CAC3B;AAYD,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,CAmB1B;AAED,eAAe,YAAY,CAAC"} \ No newline at end of file diff --git a/dist/buildActions/index.js b/dist/buildActions/index.js index 28e627a..a2eeb3a 100644 --- a/dist/buildActions/index.js +++ b/dist/buildActions/index.js @@ -1,32 +1,23 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = buildActions; - -var _fp = _interopRequireDefault(require("lodash/fp")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - +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 actionFor(type) { - const creator = (payload = undefined, meta = undefined) => _fp.default.pickBy(v => v !== undefined)({ - type, - payload, - meta - }); - - creator._genericAction = true; - return creator; + const creator = ((payload = undefined, meta = undefined) => fp_1.default.pickBy(v => v !== undefined)({ type, payload, meta })); + creator._genericAction = true; + return creator; } - -function buildActions(creators = {}, mutations = {}, effects = {}, subActions = []) { - // priority => generics => generic subs => craft subs => creators - const [crafted, generic] = _fp.default.partition(([type, f]) => !f._genericAction)(_fp.default.flatten(subActions.map(x => Object.entries(x))).filter(([_, f]) => f)); - - const actions = [...[...Object.keys(mutations), ...Object.keys(effects)].map(type => [type, actionFor(type)]), ...generic, ...crafted, ...Object.entries(creators).map(([type, payload]) => [type, (...args) => ({ - type, - payload: payload(...args) - })])]; - return _fp.default.fromPairs(actions); -} \ No newline at end of file +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, (...args) => ({ type, payload: payload(...args) })]), + ]; + return fp_1.default.fromPairs(actions); +} +exports.default = buildActions; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/buildActions/index.js.map b/dist/buildActions/index.js.map new file mode 100644 index 0000000..1dce3b4 --- /dev/null +++ b/dist/buildActions/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/buildActions/index.ts"],"names":[],"mappings":";;;;;AAAA,mDAA2B;AAQ3B,SAAS,SAAS,CAAC,IAAW;IAC5B,MAAM,OAAO,GAAmB,CAAE,CAAC,OAAO,GAAG,SAAS,EAAE,IAAI,GAAG,SAAS,EAAE,EAAE,CAC1E,YAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAC,CAAW,CACjE,CAAC;IAEF,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAE9B,OAAO,OAAO,CAAC;AACjB,CAAC;AAID,SAAS,YAAY,CACnB,aAAkD,EAAE,EACpD,cAAwB,EAAE,EAC1B,aAA4B,EAAE;IAK9B,MAAM,CAAE,OAAO,EAAE,OAAO,CAAE,GAAG,YAAE,CAAC,SAAS,CACrC,CAAC,CAAC,IAAI,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,cAAc,CAClC,CAAE,UAAU,CAAE,CAAC;IAEd,MAAM,OAAO,GAAG;QACZ,GAAG,CAAC,WAAW,CAAC,GAAG,CAAE,IAAI,CAAC,EAAE,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,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,IAAS,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAC7G;KACJ,CAAC;IAEF,OAAO,YAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AAEjC,CAAC;AAED,kBAAe,YAAY,CAAC"} \ No newline at end of file diff --git a/dist/buildCreateStore.js.map b/dist/buildCreateStore.js.map new file mode 100644 index 0000000..cfb923e --- /dev/null +++ b/dist/buildCreateStore.js.map @@ -0,0 +1 @@ +{"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"} \ No newline at end of file diff --git a/dist/buildCreateStore/index.d.ts b/dist/buildCreateStore/index.d.ts new file mode 100644 index 0000000..d4e29e8 --- /dev/null +++ b/dist/buildCreateStore/index.d.ts @@ -0,0 +1,7 @@ +import { Middleware, Reducer } from 'redux'; +import { ActionCreator, Dictionary } from '../types'; +declare function buildCreateStore(reducer: Reducer, initial: S, middleware: Middleware, actions: Dictionary): () => import("redux").Store & { + dispatch: {}; +}; +export default buildCreateStore; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/buildCreateStore/index.d.ts.map b/dist/buildCreateStore/index.d.ts.map new file mode 100644 index 0000000..6ce5446 --- /dev/null +++ b/dist/buildCreateStore/index.d.ts.map @@ -0,0 +1 @@ +{"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"} \ No newline at end of file diff --git a/dist/buildCreateStore/index.js b/dist/buildCreateStore/index.js new file mode 100644 index 0000000..621840f --- /dev/null +++ b/dist/buildCreateStore/index.js @@ -0,0 +1,16 @@ +"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 \ No newline at end of file diff --git a/dist/buildCreateStore/index.js.map b/dist/buildCreateStore/index.js.map new file mode 100644 index 0000000..2ac1542 --- /dev/null +++ b/dist/buildCreateStore/index.js.map @@ -0,0 +1 @@ +{"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"} \ No newline at end of file diff --git a/dist/buildInitial/index.d.ts b/dist/buildInitial/index.d.ts new file mode 100644 index 0000000..ef97cfc --- /dev/null +++ b/dist/buildInitial/index.d.ts @@ -0,0 +1,5 @@ +import { Dictionary } from '../types'; +declare function buildInitial(initial: S, subduxes?: Dictionary): S; +declare function buildInitial(initial?: Partial, subduxes?: Partial): S extends object ? S : never; +export default buildInitial; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/buildInitial/index.d.ts.map b/dist/buildInitial/index.d.ts.map new file mode 100644 index 0000000..4f12b12 --- /dev/null +++ b/dist/buildInitial/index.d.ts.map @@ -0,0 +1 @@ +{"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"} \ No newline at end of file diff --git a/dist/buildInitial/index.js b/dist/buildInitial/index.js index 6492ffa..a06b96b 100644 --- a/dist/buildInitial/index.js +++ b/dist/buildInitial/index.js @@ -1,14 +1,11 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = buildInitial; - -var _fp = _interopRequireDefault(require("lodash/fp")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - +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.default.isPlainObject(initial) ? _fp.default.mergeAll([subduxes, initial]) : initial; -} \ No newline at end of file + return fp_1.default.isPlainObject(initial) ? fp_1.default.mergeAll([subduxes, initial]) : initial; +} +exports.default = buildInitial; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/buildInitial/index.js.map b/dist/buildInitial/index.js.map new file mode 100644 index 0000000..db19ab8 --- /dev/null +++ b/dist/buildInitial/index.js.map @@ -0,0 +1 @@ +{"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"} \ No newline at end of file diff --git a/dist/buildInitial/index.test-d.js.map b/dist/buildInitial/index.test-d.js.map new file mode 100644 index 0000000..867f532 --- /dev/null +++ b/dist/buildInitial/index.test-d.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.test-d.js","sourceRoot":"","sources":["../../src/buildInitial/index.test-d.js"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/buildInitial/test-d.js.map b/dist/buildInitial/test-d.js.map new file mode 100644 index 0000000..8b306ed --- /dev/null +++ b/dist/buildInitial/test-d.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-d.js","sourceRoot":"","sources":["../../src/buildInitial/test-d.js"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/buildMiddleware.js.map b/dist/buildMiddleware.js.map new file mode 100644 index 0000000..1b8f627 --- /dev/null +++ b/dist/buildMiddleware.js.map @@ -0,0 +1 @@ +{"version":3,"file":"buildMiddleware.js","sourceRoot":"","sources":["../src/buildMiddleware.js"],"names":[],"mappings":";;;;;AAAA,mDAA2B;AAE3B,MAAM,aAAa,GAAG,CAAC,IAAI,EAAC,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE;IACvD,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;AAEF,SAAwB,eAAe,CACnC,OAAO,GAAG,EAAE,EACZ,OAAO,GAAG,EAAE,EACZ,QAAQ,GAAG,EAAE;IAEf,OAAO,GAAG,CAAC,EAAE;QACX,KAAK,IAAI,IAAI,IAAI,OAAO,EAAE;YACxB,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;SACxE;QAED,OAAO,aAAa,CAAC,EAAE;YACrB,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,MAAM,CAAC,CAC7B;gBACD,GAAG,YAAE,CAAC,GAAG,CAAC,YAAY,EAAE,QAAQ,CAAC;aAClC;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;AArBD,kCAqBC"} \ No newline at end of file diff --git a/dist/buildMiddleware/index.d.ts b/dist/buildMiddleware/index.d.ts new file mode 100644 index 0000000..b8ca978 --- /dev/null +++ b/dist/buildMiddleware/index.d.ts @@ -0,0 +1,5 @@ +import { Middleware } from 'redux'; +import { Dictionary, ActionCreator, UpduxDispatch } from '../types'; +declare function buildMiddleware(effects?: Dictionary>, actions?: Dictionary, subMiddlewares?: Middleware<{}, S, UpduxDispatch>[]): Middleware<{}, S, UpduxDispatch>; +export default buildMiddleware; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/buildMiddleware/index.d.ts.map b/dist/buildMiddleware/index.d.ts.map new file mode 100644 index 0000000..0977585 --- /dev/null +++ b/dist/buildMiddleware/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/buildMiddleware/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAA2B,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,aAAa,EAAU,aAAa,EAAE,MAAM,UAAU,CAAC;AAU5E,iBAAS,eAAe,CAAC,CAAC,GAAC,GAAG,EAC1B,OAAO,GAAG,UAAU,CAAC,UAAU,CAAC,EAAE,EAAC,CAAC,EAAC,aAAa,CAAC,CAAK,EACxD,OAAO,GAAG,UAAU,CAAC,aAAa,CAAK,EACvC,cAAc,GAAE,UAAU,CAAC,EAAE,EAAC,CAAC,EAAC,aAAa,CAAC,EAAO,GACtD,UAAU,CAAC,EAAE,EAAC,CAAC,EAAC,aAAa,CAAC,CAkBhC;AAED,eAAe,eAAe,CAAC"} \ No newline at end of file diff --git a/dist/buildMiddleware/index.js b/dist/buildMiddleware/index.js new file mode 100644 index 0000000..0e73286 --- /dev/null +++ b/dist/buildMiddleware/index.js @@ -0,0 +1,28 @@ +"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 buildMiddleware(effects = {}, actions = {}, subMiddlewares = []) { + return (api) => { + for (let type in actions) { + api.dispatch[type] = (...args) => api.dispatch(actions[type](...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 \ No newline at end of file diff --git a/dist/buildMiddleware/index.js.map b/dist/buildMiddleware/index.js.map new file mode 100644 index 0000000..ae5f2fa --- /dev/null +++ b/dist/buildMiddleware/index.js.map @@ -0,0 +1 @@ +{"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,eAAe,CACpB,UAAsD,EAAE,EACxD,UAAqC,EAAE,EACvC,iBAAmD,EAAE;IAGvD,OAAO,CAAC,GAAmC,EAAE,EAAE;QAC7C,KAAK,IAAI,IAAI,IAAI,OAAO,EAAE;YACxB,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAU,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAG,OAAe,CAAC,IAAI,CAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;SAChG;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"} \ No newline at end of file diff --git a/dist/buildMutations/index.d.ts b/dist/buildMutations/index.d.ts new file mode 100644 index 0000000..ac5208d --- /dev/null +++ b/dist/buildMutations/index.d.ts @@ -0,0 +1,5 @@ +/// +import { Mutation, Dictionary } from '../types'; +declare function buildMutations(mutations?: Dictionary, subduxes?: {}): import("lodash").Dictionary>; +export default buildMutations; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/buildMutations/index.d.ts.map b/dist/buildMutations/index.d.ts.map new file mode 100644 index 0000000..9ff6399 --- /dev/null +++ b/dist/buildMutations/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/buildMutations/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAC,QAAQ,EAAU,UAAU,EAAC,MAAM,UAAU,CAAC;AAWtD,iBAAS,cAAc,CACnB,SAAS,GAAE,UAAU,CAAC,QAAQ,CAAM,EACpC,QAAQ,KAAK,8CAgDhB;AAED,eAAe,cAAc,CAAC"} \ No newline at end of file diff --git a/dist/buildMutations/index.js b/dist/buildMutations/index.js index 15e95bc..287235e 100644 --- a/dist/buildMutations/index.js +++ b/dist/buildMutations/index.js @@ -1,52 +1,33 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = buildMutations; - -var _fp = _interopRequireDefault(require("lodash/fp")); - -var _updeep = _interopRequireDefault(require("updeep")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -const composeMutations = mutations => mutations.reduce((m1, m2) => (payload = null, action = {}) => state => m2(payload, action)(m1(payload, action)(state))); - +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 = {}) { - // we have to differentiate the subduxes with '*' than those - // without, as the root '*' is not the same as any sub-'*' - const actions = _fp.default.uniq(Object.keys(mutations).concat(...Object.values(subduxes).map(({ - mutations = {} - }) => Object.keys(mutations)))); - - let mergedMutations = {}; - - let [globby, nonGlobby] = _fp.default.partition(([_, { - mutations = {} - }]) => mutations['*'], Object.entries(subduxes)); - - globby = _fp.default.flow([_fp.default.fromPairs, _fp.default.mapValues(({ - reducer - }) => (_, action = {}) => state => reducer(state, action))])(globby); - - const globbyMutation = (payload, action) => (0, _updeep.default)(_fp.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 = {}) => _updeep.default.updateIn(slice)(mutation(payload, action)); - - mergedMutations[type].push(localized); + 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]; }); - }); - Object.entries(mutations).forEach(([type, mutation]) => { - mergedMutations[type].push(mutation); - }); - return _fp.default.mapValues(composeMutations)(mergedMutations); -} \ No newline at end of file + nonGlobby.forEach(([slice, { mutations = {}, reducer = {} }]) => { + Object.entries(mutations).forEach(([type, mutation]) => { + const localized = (payload = null, action) => updeep_1.default.updateIn(slice)(mutation(payload, action)); + mergedMutations[type].push(localized); + }); + }); + Object.entries(mutations).forEach(([type, mutation]) => { + mergedMutations[type].push(mutation); + }); + return fp_1.default.mapValues(composeMutations)(mergedMutations); +} +exports.default = buildMutations; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/buildMutations/index.js.map b/dist/buildMutations/index.js.map new file mode 100644 index 0000000..9393ff4 --- /dev/null +++ b/dist/buildMutations/index.js.map @@ -0,0 +1 @@ +{"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,YAAkC,EAAE,EACpC,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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,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,EAAE;YACrD,MAAM,SAAS,GAAG,CAAC,OAAO,GAAG,IAAI,EAAE,MAAc,EAAE,EAAE,CACnD,gBAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAE,QAAqB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;YAE7D,eAAe,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,EAAE;QACrD,eAAe,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IAEH,OAAO,YAAE,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC,eAAe,CAAC,CAAC;AACzD,CAAC;AAED,kBAAe,cAAc,CAAC"} \ No newline at end of file diff --git a/dist/buildUpreducer/index.d.ts b/dist/buildUpreducer/index.d.ts new file mode 100644 index 0000000..68bb6f0 --- /dev/null +++ b/dist/buildUpreducer/index.d.ts @@ -0,0 +1,4 @@ +import { Dictionary, Mutation, Upreducer } from '../types'; +declare function buildUpreducer(initial: S, mutations: Dictionary>): Upreducer; +export default buildUpreducer; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/buildUpreducer/index.d.ts.map b/dist/buildUpreducer/index.d.ts.map new file mode 100644 index 0000000..321191c --- /dev/null +++ b/dist/buildUpreducer/index.d.ts.map @@ -0,0 +1 @@ +{"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"} \ No newline at end of file diff --git a/dist/buildUpreducer/index.js b/dist/buildUpreducer/index.js index 76fdc4e..efe1e37 100644 --- a/dist/buildUpreducer/index.js +++ b/dist/buildUpreducer/index.js @@ -1,19 +1,15 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = buildUpreducer; - -var _fp = _interopRequireDefault(require("lodash/fp")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - +Object.defineProperty(exports, "__esModule", { value: true }); function buildUpreducer(initial, mutations) { - return (action = {}) => state => { - if (state === null) state = initial; - const a = mutations[action.type] || mutations['*']; - if (!a) return state; - return a(action.payload, action)(state); - }; -} \ No newline at end of file + return (action) => (state) => { + if (state === null) + 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 \ No newline at end of file diff --git a/dist/buildUpreducer/index.js.map b/dist/buildUpreducer/index.js.map new file mode 100644 index 0000000..f1f9dc8 --- /dev/null +++ b/dist/buildUpreducer/index.js.map @@ -0,0 +1 @@ +{"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,IAAI;YAAE,KAAK,GAAG,OAAO,CAAC;QAEpC,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"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..bc88b6e --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,4 @@ +import Updux from './updux'; +import { UpduxConfig } from './types'; +export default function updux(config: UpduxConfig): Updux; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/index.d.ts.map b/dist/index.d.ts.map new file mode 100644 index 0000000..921c006 --- /dev/null +++ b/dist/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,SAAS,CAAC;AAE5B,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,MAAM,EAAE,WAAW,cAEhD"} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 1891074..7ea4d40 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,18 +1,11 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = updux; - -var _fp = _interopRequireDefault(require("lodash/fp")); - -var _updeep = _interopRequireDefault(require("updeep")); - -var _updux = _interopRequireDefault(require("./updux")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - +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")); function updux(config) { - return new _updux.default(config); -} \ No newline at end of file + return new updux_1.default(config); +} +exports.default = updux; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map new file mode 100644 index 0000000..bb586ca --- /dev/null +++ b/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAGA,oDAA4B;AAI5B,SAAwB,KAAK,CAAC,MAAmB;IAC/C,OAAO,IAAI,eAAK,CAAC,MAAM,CAAC,CAAC;AAC3B,CAAC;AAFD,wBAEC"} \ No newline at end of file diff --git a/dist/middleware.test.d.ts b/dist/middleware.test.d.ts new file mode 100644 index 0000000..f1d91d8 --- /dev/null +++ b/dist/middleware.test.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=middleware.test.d.ts.map \ No newline at end of file diff --git a/dist/middleware.test.d.ts.map b/dist/middleware.test.d.ts.map new file mode 100644 index 0000000..2fd2889 --- /dev/null +++ b/dist/middleware.test.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"middleware.test.d.ts","sourceRoot":"","sources":["../src/middleware.test.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/middleware.test.js b/dist/middleware.test.js index 97a1ff5..47bbc07 100644 --- a/dist/middleware.test.js +++ b/dist/middleware.test.js @@ -1,92 +1,80 @@ "use strict"; - -var _ = _interopRequireDefault(require(".")); - -var _updeep = _interopRequireDefault(require("updeep")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - +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 = (0, _.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(); + const tracer = jest.fn(); + const store = _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 = (0, _.default)({ - effects: { - foo: tracerEffect('root') - }, - subduxes: { - zzz: (0, _.default)({ + const tracer = jest.fn(); + const tracerEffect = (signature) => (api) => (next) => (action) => { + tracer(signature); + next(action); + }; + const store = _1.default({ 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'); + foo: tracerEffect('root'), + }, + subduxes: { + zzz: _1.default({ 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 = (0, _.default)({ - effects: { - '*': api => next => action => { - tracer(); - next(action); - } - } - }).createStore(); - expect(tracer).not.toHaveBeenCalled(); - store.dispatch({ - type: 'bar' - }); - expect(tracer).toHaveBeenCalled(); + const tracer = jest.fn(); + const store = _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 = (0, _.default)({ - effects: { - foo: api => next => async action => { - next(action); - await timeout(1000); - tracer(); - } + function timeout(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); } - }).createStore(); - expect(tracer).not.toHaveBeenCalled(); - store.dispatch.foo(); - expect(tracer).not.toHaveBeenCalled(); - await timeout(1000); - expect(tracer).toHaveBeenCalled(); -}); \ No newline at end of file + const tracer = jest.fn(); + const store = _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(); +}); +//# sourceMappingURL=middleware.test.js.map \ No newline at end of file diff --git a/dist/middleware.test.js.map b/dist/middleware.test.js.map new file mode 100644 index 0000000..3c21acf --- /dev/null +++ b/dist/middleware.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"middleware.test.js","sourceRoot":"","sources":["../src/middleware.test.ts"],"names":[],"mappings":";;;;;AAAA,yCAAsB;AAGtB,IAAI,CAAE,eAAe,EAAE,GAAG,EAAE;IAExB,MAAM,MAAM,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;IAEzB,MAAM,KAAK,GAAG,UAAK,CAAC;QAChB,OAAO,EAAE;YACL,GAAG,EAAE,CAAC,GAAO,EAAE,EAAE,CAAC,CAAC,IAAQ,EAAE,EAAE,CAAC,CAAC,MAAU,EAAE,EAAE;gBAC3C,MAAM,EAAE,CAAC;gBACT,IAAI,CAAC,MAAM,CAAC,CAAC;YACjB,CAAC;SACJ;KACJ,CAAC,CAAC,WAAW,EAAE,CAAC;IAEjB,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;IAEtC,KAAK,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAEhC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;IAEtC,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;IAErB,MAAM,CAAC,MAAM,C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CAAC,CAAC;IAEpB,MAAM,CAAC,MAAM,CAAC,CAAC,gBAAgB,EAAE,CAAC;AACtC,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/splat.test.d.ts b/dist/splat.test.d.ts new file mode 100644 index 0000000..911c4c6 --- /dev/null +++ b/dist/splat.test.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=splat.test.d.ts.map \ No newline at end of file diff --git a/dist/splat.test.d.ts.map b/dist/splat.test.d.ts.map new file mode 100644 index 0000000..d9ccff1 --- /dev/null +++ b/dist/splat.test.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"splat.test.d.ts","sourceRoot":"","sources":["../src/splat.test.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/splat.test.js b/dist/splat.test.js index 423552a..e1c0d08 100644 --- a/dist/splat.test.js +++ b/dist/splat.test.js @@ -1,79 +1,55 @@ "use strict"; - -var _ = _interopRequireDefault(require(".")); - -var _updeep = _interopRequireDefault(require("updeep")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -const tracer = chr => (0, _updeep.default)({ - tracer: s => (s || '') + chr -}); - +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 = (0, _.default)({ - mutations: { - foo: () => tracer('a'), - '*': (p, 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' - }); + const dux = _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 = (0, _.default)({ - mutations: { - foo: () => tracer('a'), - '*': (dummy, a) => tracer('b'), - bar: () => ({ - bar - }) => ({ - bar, - tracer: bar.tracer - }) - }, - subduxes: { - bar: (0, _.default)({ + const dux = _1.default({ mutations: { - foo: () => tracer('d'), - '*': (dummy, a) => 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' - } - }); -}); \ No newline at end of file + foo: () => tracer('a'), + '*': () => tracer('b'), + bar: () => ({ bar }) => ({ bar, tracer: bar.tracer }) + }, + subduxes: { + bar: _1.default({ + 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 \ No newline at end of file diff --git a/dist/splat.test.js.map b/dist/splat.test.js.map new file mode 100644 index 0000000..b46fd9d --- /dev/null +++ b/dist/splat.test.js.map @@ -0,0 +1 @@ +{"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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C;SAC1D;QACD,QAAQ,EAAE;YACN,GAAG,EAAE,UAAK,CAAC;gBACP,SAAS,EAAE;oBACP,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC;oBACtB,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC;iBACzB;aACJ,CAAC;SACL;KACJ,CAAC,CAAC;IAEJ,MAAM,KAAK,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;IAE/B,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC;QAC7B,MAAM,EAAE,GAAG;QACX,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"} \ No newline at end of file diff --git a/dist/test.d.ts b/dist/test.d.ts new file mode 100644 index 0000000..9bcc471 --- /dev/null +++ b/dist/test.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=test.d.ts.map \ No newline at end of file diff --git a/dist/test.d.ts.map b/dist/test.d.ts.map new file mode 100644 index 0000000..6ef44fc --- /dev/null +++ b/dist/test.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/test.js b/dist/test.js index 5aaa6df..c5ac448 100644 --- a/dist/test.js +++ b/dist/test.js @@ -1,205 +1,133 @@ "use strict"; - -var _ = _interopRequireDefault(require(".")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - +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 - } - } = (0, _.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 - } - }); + const { actions: { foo, bar }, } = _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 - } = (0, _.default)({ - initial: { - counter: 1 - }, - mutations: { - inc: () => ({ - counter - }) => ({ - counter: counter + 1 - }) - } - }); - let state = reducer(null, {}); - expect(state).toEqual({ - counter: 1 - }); - state = reducer(state, actions.inc()); - expect(state).toEqual({ - counter: 2 - }); + const { actions, reducer } = _1.default({ + initial: { counter: 1 }, + mutations: { + inc: () => ({ counter }) => ({ counter: counter + 1 }), + }, + }); + let state = reducer(null, { type: 'noop' }); + expect(state).toEqual({ counter: 1 }); + state = reducer(state, actions.inc()); + expect(state).toEqual({ counter: 2 }); }); test('sub reducers', () => { - const foo = (0, _.default)({ - initial: 1, - mutations: { - doFoo: () => x => x + 1, - doAll: () => x => x + 10 - } - }); - const bar = (0, _.default)({ - initial: 'a', - mutations: { - doBar: () => x => x + 'a', - doAll: () => x => x + 'b' - } - }); - const { - initial, - actions, - reducer - } = (0, _.default)({ - subduxes: { - foo, - bar - } - }); - expect(initial).toEqual({ - foo: 1, - bar: 'a' - }); - expect(Object.keys(actions)).toHaveLength(3); - let state = reducer(null, {}); - 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' - }); + const foo = _1.default({ + initial: 1, + mutations: { + doFoo: () => (x) => x + 1, + doAll: () => (x) => x + 10, + }, + }); + const bar = _1.default({ + initial: 'a', + mutations: { + doBar: () => (x) => x + 'a', + doAll: () => (x) => x + 'b', + } + }); + const { initial, actions, reducer } = _1.default({ + subduxes: { + foo, bar + } + }); + expect(initial).toEqual({ foo: 1, bar: 'a' }); + expect(Object.keys(actions)).toHaveLength(3); + let state = reducer(null, { 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 - } = (0, _.default)({ - initial: { - foo: { - bar: 4 - } - }, - mutations: { - inc: () => state => { - return { ...state, - surprise: state.foo.bar - }; - } - }, - subduxes: { - foo: (0, _.default)({ + const { initial, reducer, actions, } = _1.default({ initial: { - bar: 2, - quux: 3 + foo: { bar: 4 }, }, mutations: { - inc: () => state => ({ ...state, - bar: state.bar + 1 - }) + inc: () => (state) => { + return { + ...state, + surprise: state.foo.bar + }; + } + }, + subduxes: { + foo: _1.default({ + initial: { + bar: 2, + quux: 3, + }, + mutations: { + inc: () => (state) => ({ ...state, bar: state.bar + 1 }) + }, + }), } - }) - } - }); - expect(initial).toEqual({ - foo: { - bar: 4, - quux: 3 - } - }); - expect(reducer(null, actions.inc())).toEqual({ - foo: { - bar: 5, - quux: 3 - }, - surprise: 5 - }); + }); + expect(initial).toEqual({ + foo: { bar: 4, quux: 3 } + }); + expect(reducer(null, actions.inc())).toEqual({ + foo: { bar: 5, quux: 3 }, surprise: 5 + }); }); - function timeout(ms) { - return new Promise(resolve => setTimeout(resolve, ms)); + return new Promise(resolve => setTimeout(resolve, ms)); } - test('middleware', async () => { - const { - middleware, - createStore - } = (0, _.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: (0, _.default)({ + const { middleware, createStore } = _1.default({ + initial: "", + mutations: { + inc: (addition) => (state) => state + addition, + doEeet: () => (state) => { + return state + 'Z'; + }, + }, effects: { - doEeet: api => next => action => { - api.dispatch({ - type: 'inc', - payload: 'b' - }); - next(action); - } + doEeet: api => next => async (action) => { + api.dispatch.inc('a'); + next(action); + await timeout(1000); + api.dispatch.inc('c'); + } + }, + subduxes: { + foo: _1.default({ + 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'); -}); \ No newline at end of file + }); + const store = createStore(); + store.dispatch.doEeet(); + expect(store.getState()).toEqual('abZ'); + await timeout(1000); + expect(store.getState()).toEqual('abZc'); +}); +//# sourceMappingURL=test.js.map \ No newline at end of file diff --git a/dist/test.js.map b/dist/test.js.map new file mode 100644 index 0000000..f6fb1f9 --- /dev/null +++ b/dist/test.js.map @@ -0,0 +1 @@ +{"version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EAAE,CAAC,KAAK,EAAC,MAAM,EAAC,EAAE;gBAClC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBACtB,IAAI,CAAC,MAAM,CAAC,CAAC;gBACb,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;gBACpB,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC1B,CAAC;SACJ;QACD,QAAQ,EAAE;YACN,GAAG,EAAE,UAAK,CAAC;gBACP,OAAO,EAAE;oBACL,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE;wBAC9B,GAAG,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAC,CAAC,CAAC;wBAC3C,IAAI,CAAC,MAAM,CAAC,CAAC;oBACjB,CAAC;iBACJ;aACJ,CAAC;SACL;KACJ,CAAC,CAAC;IAEH,MAAM,KAAK,GAAG,WAAW,EAAE,CAAC;IAE5B,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAExB,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAE,KAAK,CAAE,CAAC;IAE1C,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpB,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAE,MAAM,CAAE,CAAC;AAE/C,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/types.d.ts b/dist/types.d.ts new file mode 100644 index 0000000..9c88ca8 --- /dev/null +++ b/dist/types.d.ts @@ -0,0 +1,24 @@ +import { Dispatch, Middleware } from 'redux'; +export declare type Action = { + type: string; + payload?: any; + meta?: any; +}; +export declare type Dictionary = { + [key: string]: T; +}; +export declare type Mutation = (payload: any, action: Action) => (state: S) => S; +export declare type ActionPayloadGenerator = (...args: any[]) => any; +export declare type ActionCreator = (...args: any[]) => Action; +export declare type UpduxDispatch = Dispatch & Dictionary; +export declare type UpduxConfig = Partial<{ + initial: S; + subduxes: {}; + actions: { + [type: string]: ActionPayloadGenerator; + }; + mutations: any; + effects: Dictionary>; +}>; +export declare type Upreducer = (action: Action) => (state: S) => S; +//# sourceMappingURL=types.d.ts.map \ No newline at end of file diff --git a/dist/types.d.ts.map b/dist/types.d.ts.map new file mode 100644 index 0000000..aa59497 --- /dev/null +++ b/dist/types.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAE7C,oBAAY,MAAM,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,IAAI,CAAC,EAAE,GAAG,CAAC;CACd,CAAA;AAED,oBAAY,UAAU,CAAC,CAAC,IAAI;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAA;CAAE,CAAC;AAEjD,oBAAY,QAAQ,CAAC,CAAC,GAAC,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAE;AAEjF,oBAAY,sBAAsB,GAAG,CAAC,GAAG,IAAI,EAAC,GAAG,EAAE,KAAK,GAAG,CAAC;AAE5D,oBAAY,aAAa,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAM,MAAM,CAAC;AAExD,oBAAY,aAAa,GAAG,QAAQ,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;AAEjE,oBAAY,WAAW,CAAC,CAAC,GAAC,GAAG,IAAI,OAAO,CAAC;IACrC,OAAO,EAAE,CAAC,CAAC;IACX,QAAQ,EAAE,EAAE,CAAC;IACb,OAAO,EAAE;QACL,CAAE,IAAI,EAAE,MAAM,GAAI,sBAAsB,CAAA;KAC3C,CAAC;IACF,SAAS,EAAE,GAAG,CAAC;IACf,OAAO,EAAE,UAAU,CAAC,UAAU,CAAC,EAAE,EAAC,CAAC,EAAC,aAAa,CAAC,CAAC,CAAC;CACvD,CAAC,CAAC;AAEH,oBAAY,SAAS,CAAC,CAAC,GAAC,GAAG,IAAI,CAAC,MAAM,EAAC,MAAM,KAAK,CAAC,KAAK,EAAC,CAAC,KAAK,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/types.js b/dist/types.js new file mode 100644 index 0000000..11e638d --- /dev/null +++ b/dist/types.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/dist/types.js.map b/dist/types.js.map new file mode 100644 index 0000000..c768b79 --- /dev/null +++ b/dist/types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/updux.d.ts b/dist/updux.d.ts new file mode 100644 index 0000000..31b7d2f --- /dev/null +++ b/dist/updux.d.ts @@ -0,0 +1,22 @@ +import { UpduxConfig, Dictionary, Action, ActionCreator, Mutation, Upreducer, UpduxDispatch } from './types'; +import { Middleware, Store } from 'redux'; +declare type StoreWithDispatchActions Action; +}> = Store & { + dispatch: { + [type in keyof Actions]: (...args: any) => void; + }; +}; +export declare class Updux { + subduxes: Dictionary; + actions: Dictionary; + initial: S; + mutations: Dictionary; + upreducer: Upreducer; + reducer: (state: S | undefined, action: Action) => S; + middleware: Middleware<{}, S, UpduxDispatch>; + createStore: () => StoreWithDispatchActions; + constructor(config: UpduxConfig); +} +export default Updux; +//# sourceMappingURL=updux.d.ts.map \ No newline at end of file diff --git a/dist/updux.d.ts.map b/dist/updux.d.ts.map new file mode 100644 index 0000000..8dee058 --- /dev/null +++ b/dist/updux.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"updux.d.ts","sourceRoot":"","sources":["../src/updux.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7G,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAE1C,aAAK,wBAAwB,CAAC,CAAC,GAAC,GAAG,EAAC,OAAO,GAAC;IAAE,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,EAAC,GAAG,KAAK,MAAM,CAAA;CAAE,IAAI,KAAK,CAAC,CAAC,CAAC,GAAG;IACpG,QAAQ,EAAE;SAAI,IAAI,IAAI,MAAM,OAAO,GAAI,CAAC,GAAG,IAAI,EAAC,GAAG,KAAK,IAAI;KAAE,CAAA;CACjE,CAAC;AAEF,qBAAa,KAAK,CAAC,CAAC,GAAC,GAAG;IAEpB,QAAQ,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;IAE5B,OAAO,EAAE,UAAU,CAAC,aAAa,CAAC,CAAA;IAElC,OAAO,EAAE,CAAC,CAAC;IAEX,SAAS,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IAEhC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IAExB,OAAO,EAAE,CAAC,KAAK,EAAC,CAAC,GAAC,SAAS,EAAC,MAAM,EAAC,MAAM,KAAK,CAAC,CAAC;IAEhD,UAAU,EAAE,UAAU,CAAC,EAAE,EAAC,CAAC,EAAC,aAAa,CAAC,CAAC;IAE3C,WAAW,EAAE,MAAM,wBAAwB,CAAC,CAAC,CAAC,CAAC;gBAEnC,MAAM,EAAE,WAAW;CAwClC;AAED,eAAe,KAAK,CAAC"} \ No newline at end of file diff --git a/dist/updux.js b/dist/updux.js index 6263609..b1a42c8 100644 --- a/dist/updux.js +++ b/dist/updux.js @@ -1,48 +1,30 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = exports.Updux = void 0; - -var _fp = _interopRequireDefault(require("lodash/fp")); - -var _buildActions = _interopRequireDefault(require("./buildActions")); - -var _buildInitial = _interopRequireDefault(require("./buildInitial")); - -var _buildMutations = _interopRequireDefault(require("./buildMutations")); - -var _buildCreateStore = _interopRequireDefault(require("./buildCreateStore")); - -var _buildMiddleware = _interopRequireDefault(require("./buildMiddleware")); - -var _buildUpreducer = _interopRequireDefault(require("./buildUpreducer")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - +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 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")); class Updux { - constructor(config) { - this.subduxes = _fp.default.mapValues(value => _fp.default.isPlainObject(value) ? new Updux(value) : value)(_fp.default.getOr({}, 'subduxes', config)); - this.actions = (0, _buildActions.default)(config.actions, config.mutations, config.effects, Object.values(this.subduxes).map(({ - actions - }) => actions)); - this.initial = (0, _buildInitial.default)(config.initial, _fp.default.mapValues(({ - initial - }) => initial)(this.subduxes)); - this.mutations = (0, _buildMutations.default)(config.mutations, this.subduxes); - this.upreducer = (0, _buildUpreducer.default)(this.initial, this.mutations); - - this.reducer = (state, action) => { - return this.upreducer(action)(state); - }; - - this.middleware = (0, _buildMiddleware.default)(config.effects, this.actions, config.subduxes); - this.createStore = (0, _buildCreateStore.default)(this.reducer, this.initial, this.middleware, this.actions); - } - + constructor(config) { + this.subduxes = fp_1.default.mapValues((value) => fp_1.default.isPlainObject(value) ? new Updux(value) : value)(fp_1.default.getOr({}, 'subduxes', config)); + this.actions = buildActions_1.default(config.actions, [...Object.keys(config.mutations || {}), ...Object.keys(config.effects || {})], fp_1.default.flatten(Object.values(this.subduxes).map(({ actions }) => Object.entries(actions)))); + this.initial = buildInitial_1.default(config.initial, fp_1.default.mapValues(({ initial }) => initial)(this.subduxes)); + this.mutations = buildMutations_1.default(config.mutations, this.subduxes); + this.upreducer = buildUpreducer_1.default(this.initial, this.mutations); + this.reducer = (state, action) => { + return this.upreducer(action)(state); + }; + this.middleware = buildMiddleware_1.default(config.effects, this.actions, Object.values(this.subduxes).map(sd => sd.middleware)); + const actions = this.actions; + this.createStore = buildCreateStore_1.default(this.reducer, this.initial, this.middleware, this.actions); + } } - exports.Updux = Updux; -var _default = Updux; -exports.default = _default; \ No newline at end of file +exports.default = Updux; +//# sourceMappingURL=updux.js.map \ No newline at end of file diff --git a/dist/updux.js.map b/dist/updux.js.map new file mode 100644 index 0000000..d6ae157 --- /dev/null +++ b/dist/updux.js.map @@ -0,0 +1 @@ +{"version":3,"file":"updux.js","sourceRoot":"","sources":["../src/updux.ts"],"names":[],"mappings":";;;;;AAAA,mDAA2B;AAC3B,kEAA0C;AAC1C,kEAA0C;AAC1C,sEAA8C;AAE9C,0EAAkD;AAClD,wEAAgD;AAChD,sEAA8C;AAS9C,MAAa,KAAK;IAkBd,YAAY,MAAmB;QAE3B,IAAI,CAAC,QAAQ,GAAG,YAAE,CAAC,SAAS,CACxB,CAAC,KAAuB,EAAE,EAAE,CAAC,YAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAE,CAAC,YAAE,CAAC,KAAK,CAAC,EAAE,EAAC,UAAU,EAAC,MAAM,CAAC,CAC9F,CAAC;QAGvB,IAAI,CAAC,OAAO,GAAG,sBAAY,CACvB,MAAM,CAAC,OAAO,EACd,CAAE,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,IAAE,EAAE,CAAC,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vD,CAAC;IACzD,CAAC;CAEJ;AA1DD,sBA0DC;AAED,kBAAe,KAAK,CAAC"} \ No newline at end of file diff --git a/package.json b/package.json index ffcbd03..c5da6b5 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "build": "tsc", "test": "jest" }, - "version": "0.1.0", + "version": "0.2.0", "repository": { "type": "git", "url": "git+https://github.com/yanick/updux.git"