diff --git a/Changes b/Changes index 2971f9a..cc6f3f0 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,10 @@ # Revision history for Updux +1.1.0 2019-11-05 + - Document mapping behavior of the '*' subdux. + - add subduxUpreducer. + - add sink mutations. + 1.0.0 2019-11-04 - Pretty big rework. - Better documentation. diff --git a/README.md b/README.md index 5db9dc5..bc1f7a3 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,59 @@ const { } = updux; ``` +## Mapping a mutation to all values of a state + +Say you have a `todos` state that is an array of `todo` sub-states. It's easy +enough to have the main reducer maps away all items to the sub-reducer: + +``` +const todo = new Updux({ + mutations: { + review: () => u({ reviewed: true}), + done: () => u({done: true}), + }, +}); + +const todos = new Updux({ initial: [] }); + +todos.addMutation( + todo.actions.review, + (_,action) => state => state.map( todo.upreducer(action) ) +); +todos.addMutation( + todo.actions.done, + (id,action) => u.map(u.if(u.is('id',id), todo.upreducer(action))), +); + +``` + +But `updeep` can iterate through all the items of an array (or the values of +an object) via the special key `*`. So the todos updux above could also be +written: + +``` +const todo = new Updux({ + mutations: { + review: () => u({ reviewed: true}), + done: () => u({done: true}), + }, +}); + +const todos = new Updux({ + subduxes: { '*': todo }, +}); + +todos.addMutation( + todo.actions.done, + (id,action) => u.map(u.if(u.is('id',id), todo.upreducer(action))), + true +); +``` + +The advantages being that the actions/mutations/effects of the subdux will be +imported by the root updux as usual, and all actions that aren't being +overridden by a sink mutation will trickle down automatically. + ## Usage with Immer While Updux was created with Updeep in mind, it also plays very diff --git a/dist/buildMutations/index.d.ts b/dist/buildMutations/index.d.ts index cc17f48..732e130 100644 --- a/dist/buildMutations/index.d.ts +++ b/dist/buildMutations/index.d.ts @@ -1,5 +1,5 @@ /// import { Mutation, Action, Dictionary } from '../types'; -declare function buildMutations(mutations?: Dictionary, subduxes?: {}): import("lodash").Dictionary>>; +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 index 8476e7b..43d20ac 100644 --- a/dist/buildMutations/index.d.ts.map +++ b/dist/buildMutations/index.d.ts.map @@ -1 +1 @@ -{"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,CAAM,EACpC,QAAQ,KAAK,mEAgDhB;AAED,eAAe,cAAc,CAAC"} \ No newline at end of file +{"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"} \ No newline at end of file diff --git a/dist/buildMutations/index.js b/dist/buildMutations/index.js index 287235e..947ece9 100644 --- a/dist/buildMutations/index.js +++ b/dist/buildMutations/index.js @@ -20,12 +20,24 @@ function buildMutations(mutations = {}, subduxes = {}) { }); nonGlobby.forEach(([slice, { mutations = {}, reducer = {} }]) => { Object.entries(mutations).forEach(([type, mutation]) => { - const localized = (payload = null, action) => updeep_1.default.updateIn(slice)(mutation(payload, action)); + const localized = (payload = null, action) => { + return updeep_1.default.updateIn(slice)(mutation(payload, action)); + }; mergedMutations[type].push(localized); }); }); Object.entries(mutations).forEach(([type, mutation]) => { - mergedMutations[type].push(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); } diff --git a/dist/buildMutations/index.js.map b/dist/buildMutations/index.js.map index 9393ff4..753528e 100644 --- a/dist/buildMutations/index.js.map +++ b/dist/buildMutations/index.js.map @@ -1 +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,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,CAA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AAC,IAAI,EAAE,QAAQ,CAAC,EAAE,EAAE;QACrD,IAAK,KAAK,CAAC,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"} \ No newline at end of file diff --git a/dist/mappedUpdux.test.d.ts b/dist/mappedUpdux.test.d.ts new file mode 100644 index 0000000..281dbc4 --- /dev/null +++ b/dist/mappedUpdux.test.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=mappedUpdux.test.d.ts.map \ No newline at end of file diff --git a/dist/mappedUpdux.test.d.ts.map b/dist/mappedUpdux.test.d.ts.map new file mode 100644 index 0000000..74c28f0 --- /dev/null +++ b/dist/mappedUpdux.test.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"mappedUpdux.test.d.ts","sourceRoot":"","sources":["../src/mappedUpdux.test.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/mappedUpdux.test.js b/dist/mappedUpdux.test.js new file mode 100644 index 0000000..89c56ae --- /dev/null +++ b/dist/mappedUpdux.test.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 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 \ No newline at end of file diff --git a/dist/mappedUpdux.test.js.map b/dist/mappedUpdux.test.js.map new file mode 100644 index 0000000..86808af --- /dev/null +++ b/dist/mappedUpdux.test.js.map @@ -0,0 +1 @@ +{"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"} \ No newline at end of file diff --git a/dist/sink.test.d.ts b/dist/sink.test.d.ts new file mode 100644 index 0000000..0969df2 --- /dev/null +++ b/dist/sink.test.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=sink.test.d.ts.map \ No newline at end of file diff --git a/dist/sink.test.d.ts.map b/dist/sink.test.d.ts.map new file mode 100644 index 0000000..0c22f0a --- /dev/null +++ b/dist/sink.test.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"sink.test.d.ts","sourceRoot":"","sources":["../src/sink.test.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/sink.test.js b/dist/sink.test.js new file mode 100644 index 0000000..180d419 --- /dev/null +++ b/dist/sink.test.js @@ -0,0 +1,46 @@ +"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 \ No newline at end of file diff --git a/dist/sink.test.js.map b/dist/sink.test.js.map new file mode 100644 index 0000000..aae21d9 --- /dev/null +++ b/dist/sink.test.js.map @@ -0,0 +1 @@ +{"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,G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C,CAAC,OAAO,CAAC;QAC/D,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,EAAC,GAAG,EAAE,CAAC,EAAC;KACd,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/updux.d.ts b/dist/updux.d.ts index 964ccdd..ab27eb8 100644 --- a/dist/updux.d.ts +++ b/dist/updux.d.ts @@ -22,9 +22,10 @@ export declare class Updux { readonly upreducer: Upreducer; readonly reducer: (state: S | undefined, action: Action) => S; readonly mutations: Dictionary>; + readonly subduxUpreducer: Upreducer; readonly createStore: () => StoreWithDispatchActions; readonly asDux: Dux; - addMutation(creator: A, mutation: Mutation infer R ? R : never>): void; + addMutation(creator: A, mutation: Mutation infer R ? R : never>, isSink?: boolean): void; } 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 index b91c010..62694ad 100644 --- a/dist/updux.d.ts.map +++ b/dist/updux.d.ts.map @@ -1 +1 @@ -{"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,EACT,aAAa,EACd,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAC,UAAU,EAAE,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,o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AAK,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"} \ No newline at end of file diff --git a/dist/updux.js b/dist/updux.js index 1966c45..8a0ed8e 100644 --- a/dist/updux.js +++ b/dist/updux.js @@ -43,6 +43,9 @@ class Updux { 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); @@ -59,9 +62,12 @@ class Updux { initial: this.initial, }; } - addMutation(creator, mutation) { + addMutation(creator, mutation, isSink) { this.localActions[creator.type] = creator; - this.localMutations[creator.type] = this.groomMutations(mutation); + this.localMutations[creator.type] = [ + this.groomMutations(mutation), + isSink, + ]; } } __decorate([ @@ -88,6 +94,9 @@ __decorate([ __decorate([ mobx_1.computed ], Updux.prototype, "mutations", null); +__decorate([ + mobx_1.computed +], Updux.prototype, "subduxUpreducer", null); __decorate([ mobx_1.computed ], Updux.prototype, "createStore", null); diff --git a/dist/updux.js.map b/dist/updux.js.map index ea4bcbd..fa1f544 100644 --- a/dist/updux.js.map +++ b/dist/updux.js.map @@ -1 +1 @@ -{"version":3,"file":"updux.js","sourceRoot":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,OAAO;YACrB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;IACJ,CAAC;IAcD,WAAW,CACT,OAAU,EACV,QAAwE,EACxE,MAAgB;QAEhB,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;QAC1C,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG;YAClC,IAAI,CAAC,cAAc,CAAC,QAAe,CAAgB;YACnD,MAAM;SACP,CAAC;IACJ,CAAC;CACF;AA9La;IAAX,iBAAU;2CAET;AAEU;IAAX,iBAAU;2CAAiD;AAEhD;IAAX,iBAAU;6CAET;AA4BQ;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;AAnMH,sBA+OC;AAED,kBAAe,KAAK,CAAC"} \ No newline at end of file diff --git a/docs/assets/js/search.js b/docs/assets/js/search.js index da08a32..d0aa632 100644 --- a/docs/assets/js/search.js +++ b/docs/assets/js/search.js @@ -1,3 +1,3 @@ var typedoc = typedoc || {}; typedoc.search = typedoc.search || {}; - typedoc.search.data = {"kinds":{"32":"Variable","64":"Function","128":"Class","512":"Constructor","1024":"Property","2048":"Method","65536":"Type literal","262144":"Accessor","4194304":"Type alias"},"rows":[{"id":0,"kind":4194304,"name":"MaybePayload","url":"globals.html#maybepayload","classes":"tsd-kind-type-alias tsd-has-type-parameter tsd-is-not-exported"},{"id":1,"kind":4194304,"name":"Action","url":"globals.html#action","classes":"tsd-kind-type-alias tsd-has-type-parameter"},{"id":2,"kind":4194304,"name":"Dictionary","url":"globals.html#dictionary","classes":"tsd-kind-type-alias tsd-has-type-parameter"},{"id":3,"kind":65536,"name":"__type","url":"globals.html#dictionary.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"Dictionary"},{"id":4,"kind":4194304,"name":"Mutation","url":"globals.html#mutation","classes":"tsd-kind-type-alias tsd-has-type-parameter"},{"id":5,"kind":65536,"name":"__type","url":"globals.html#mutation.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"Mutation"},{"id":6,"kind":4194304,"name":"ActionPayloadGenerator","url":"globals.html#actionpayloadgenerator","classes":"tsd-kind-type-alias"},{"id":7,"kind":65536,"name":"__type","url":"globals.html#actionpayloadgenerator.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"ActionPayloadGenerator"},{"id":8,"kind":4194304,"name":"ActionCreator","url":"globals.html#actioncreator","classes":"tsd-kind-type-alias tsd-has-type-parameter"},{"id":9,"kind":4194304,"name":"UpduxDispatch","url":"globals.html#upduxdispatch","classes":"tsd-kind-type-alias"},{"id":10,"kind":4194304,"name":"UpduxConfig","url":"globals.html#upduxconfig","classes":"tsd-kind-type-alias tsd-has-type-parameter"},{"id":11,"kind":65536,"name":"__type","url":"globals.html#upduxconfig.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"UpduxConfig"},{"id":12,"kind":32,"name":"initial","url":"globals.html#upduxconfig.__type.initial","classes":"tsd-kind-variable tsd-parent-kind-type-literal tsd-is-not-exported","parent":"UpduxConfig.__type"},{"id":13,"kind":32,"name":"subduxes","url":"globals.html#upduxconfig.__type.subduxes","classes":"tsd-kind-variable tsd-parent-kind-type-literal tsd-is-not-exported","parent":"UpduxConfig.__type"},{"id":14,"kind":32,"name":"actions","url":"globals.html#upduxconfig.__type.actions","classes":"tsd-kind-variable tsd-parent-kind-type-literal tsd-is-not-exported","parent":"UpduxConfig.__type"},{"id":15,"kind":32,"name":"mutations","url":"globals.html#upduxconfig.__type.mutations","classes":"tsd-kind-variable tsd-parent-kind-type-literal tsd-is-not-exported","parent":"UpduxConfig.__type"},{"id":16,"kind":32,"name":"groomMutations","url":"globals.html#upduxconfig.__type.groommutations","classes":"tsd-kind-variable tsd-parent-kind-type-literal tsd-is-not-exported","parent":"UpduxConfig.__type"},{"id":17,"kind":32,"name":"effects","url":"globals.html#upduxconfig.__type.effects","classes":"tsd-kind-variable tsd-parent-kind-type-literal tsd-is-not-exported","parent":"UpduxConfig.__type"},{"id":18,"kind":4194304,"name":"Upreducer","url":"globals.html#upreducer","classes":"tsd-kind-type-alias tsd-has-type-parameter"},{"id":19,"kind":65536,"name":"__type","url":"globals.html#upreducer.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"Upreducer"},{"id":20,"kind":64,"name":"actionCreator","url":"globals.html#actioncreator","classes":"tsd-kind-function tsd-has-type-parameter"},{"id":21,"kind":64,"name":"actionFor","url":"globals.html#actionfor","classes":"tsd-kind-function tsd-is-not-exported"},{"id":22,"kind":4194304,"name":"ActionPair","url":"globals.html#actionpair","classes":"tsd-kind-type-alias tsd-is-not-exported"},{"id":23,"kind":64,"name":"buildActions","url":"globals.html#buildactions","classes":"tsd-kind-function"},{"id":24,"kind":64,"name":"buildInitial","url":"globals.html#buildinitial","classes":"tsd-kind-function tsd-has-type-parameter"},{"id":25,"kind":64,"name":"composeMutations","url":"globals.html#composemutations","classes":"tsd-kind-function tsd-is-not-exported"},{"id":26,"kind":4194304,"name":"SubMutations","url":"globals.html#submutations","classes":"tsd-kind-type-alias tsd-is-not-exported"},{"id":27,"kind":65536,"name":"__type","url":"globals.html#submutations.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"SubMutations"},{"id":28,"kind":64,"name":"buildMutations","url":"globals.html#buildmutations","classes":"tsd-kind-function"},{"id":29,"kind":64,"name":"buildCreateStore","url":"globals.html#buildcreatestore","classes":"tsd-kind-function tsd-has-type-parameter"},{"id":30,"kind":64,"name":"MiddlewareFor","url":"globals.html#middlewarefor","classes":"tsd-kind-function tsd-is-not-exported"},{"id":31,"kind":4194304,"name":"Next","url":"globals.html#next","classes":"tsd-kind-type-alias tsd-is-not-exported"},{"id":32,"kind":65536,"name":"__type","url":"globals.html#next.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"Next"},{"id":33,"kind":64,"name":"buildMiddleware","url":"globals.html#buildmiddleware","classes":"tsd-kind-function tsd-has-type-parameter"},{"id":34,"kind":64,"name":"buildUpreducer","url":"globals.html#buildupreducer","classes":"tsd-kind-function tsd-has-type-parameter"},{"id":35,"kind":128,"name":"Updux","url":"classes/updux.html","classes":"tsd-kind-class tsd-has-type-parameter"},{"id":36,"kind":1024,"name":"subduxes","url":"classes/updux.html#subduxes","classes":"tsd-kind-property tsd-parent-kind-class","parent":"Updux"},{"id":37,"kind":1024,"name":"initial","url":"classes/updux.html#initial","classes":"tsd-kind-property tsd-parent-kind-class","parent":"Updux"},{"id":38,"kind":1024,"name":"groomMutations","url":"classes/updux.html#groommutations","classes":"tsd-kind-property tsd-parent-kind-class","parent":"Updux"},{"id":39,"kind":65536,"name":"__type","url":"classes/updux.html#groommutations.__type","classes":"tsd-kind-type-literal tsd-parent-kind-property","parent":"Updux.groomMutations"},{"id":40,"kind":512,"name":"constructor","url":"classes/updux.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"Updux"},{"id":41,"kind":262144,"name":"middleware","url":"classes/updux.html#middleware","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"Updux"},{"id":42,"kind":262144,"name":"actions","url":"classes/updux.html#actions","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"Updux"},{"id":43,"kind":262144,"name":"upreducer","url":"classes/updux.html#upreducer","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"Updux"},{"id":44,"kind":262144,"name":"reducer","url":"classes/updux.html#reducer","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"Updux"},{"id":45,"kind":262144,"name":"mutations","url":"classes/updux.html#mutations","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"Updux"},{"id":46,"kind":262144,"name":"createStore","url":"classes/updux.html#createstore","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"Updux"},{"id":47,"kind":262144,"name":"asDux","url":"classes/updux.html#asdux","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"Updux"},{"id":48,"kind":2048,"name":"addMutation","url":"classes/updux.html#addmutation","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter","parent":"Updux"},{"id":49,"kind":4194304,"name":"StoreWithDispatchActions","url":"globals.html#storewithdispatchactions","classes":"tsd-kind-type-alias tsd-has-type-parameter tsd-is-not-exported"},{"id":50,"kind":4194304,"name":"Dux","url":"globals.html#dux","classes":"tsd-kind-type-alias tsd-has-type-parameter"},{"id":51,"kind":64,"name":"noopEffect","url":"globals.html#noopeffect","classes":"tsd-kind-function tsd-is-not-exported"},{"id":52,"kind":4194304,"name":"MyState","url":"globals.html#mystate","classes":"tsd-kind-type-alias tsd-is-not-exported"},{"id":53,"kind":65536,"name":"__type","url":"globals.html#mystate.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"MyState"},{"id":54,"kind":32,"name":"sum","url":"globals.html#mystate.__type.sum","classes":"tsd-kind-variable tsd-parent-kind-type-literal tsd-is-not-exported","parent":"MyState.__type"},{"id":55,"kind":64,"name":"tracer","url":"globals.html#tracer","classes":"tsd-kind-function tsd-is-not-exported"},{"id":56,"kind":64,"name":"timeout","url":"globals.html#timeout","classes":"tsd-kind-function tsd-is-not-exported"}]}; \ No newline at end of file + typedoc.search.data = {"kinds":{"32":"Variable","64":"Function","128":"Class","512":"Constructor","1024":"Property","2048":"Method","65536":"Type literal","262144":"Accessor","4194304":"Type alias"},"rows":[{"id":0,"kind":4194304,"name":"MaybePayload","url":"globals.html#maybepayload","classes":"tsd-kind-type-alias tsd-has-type-parameter tsd-is-not-exported"},{"id":1,"kind":4194304,"name":"Action","url":"globals.html#action","classes":"tsd-kind-type-alias tsd-has-type-parameter"},{"id":2,"kind":4194304,"name":"Dictionary","url":"globals.html#dictionary","classes":"tsd-kind-type-alias tsd-has-type-parameter"},{"id":3,"kind":65536,"name":"__type","url":"globals.html#dictionary.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"Dictionary"},{"id":4,"kind":4194304,"name":"Mutation","url":"globals.html#mutation","classes":"tsd-kind-type-alias tsd-has-type-parameter"},{"id":5,"kind":65536,"name":"__type","url":"globals.html#mutation.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"Mutation"},{"id":6,"kind":4194304,"name":"ActionPayloadGenerator","url":"globals.html#actionpayloadgenerator","classes":"tsd-kind-type-alias"},{"id":7,"kind":65536,"name":"__type","url":"globals.html#actionpayloadgenerator.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"ActionPayloadGenerator"},{"id":8,"kind":4194304,"name":"ActionCreator","url":"globals.html#actioncreator","classes":"tsd-kind-type-alias tsd-has-type-parameter"},{"id":9,"kind":4194304,"name":"UpduxDispatch","url":"globals.html#upduxdispatch","classes":"tsd-kind-type-alias"},{"id":10,"kind":4194304,"name":"UpduxConfig","url":"globals.html#upduxconfig","classes":"tsd-kind-type-alias tsd-has-type-parameter"},{"id":11,"kind":65536,"name":"__type","url":"globals.html#upduxconfig.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"UpduxConfig"},{"id":12,"kind":32,"name":"initial","url":"globals.html#upduxconfig.__type.initial","classes":"tsd-kind-variable tsd-parent-kind-type-literal tsd-is-not-exported","parent":"UpduxConfig.__type"},{"id":13,"kind":32,"name":"subduxes","url":"globals.html#upduxconfig.__type.subduxes","classes":"tsd-kind-variable tsd-parent-kind-type-literal tsd-is-not-exported","parent":"UpduxConfig.__type"},{"id":14,"kind":32,"name":"actions","url":"globals.html#upduxconfig.__type.actions","classes":"tsd-kind-variable tsd-parent-kind-type-literal tsd-is-not-exported","parent":"UpduxConfig.__type"},{"id":15,"kind":32,"name":"mutations","url":"globals.html#upduxconfig.__type.mutations","classes":"tsd-kind-variable tsd-parent-kind-type-literal tsd-is-not-exported","parent":"UpduxConfig.__type"},{"id":16,"kind":32,"name":"groomMutations","url":"globals.html#upduxconfig.__type.groommutations","classes":"tsd-kind-variable tsd-parent-kind-type-literal tsd-is-not-exported","parent":"UpduxConfig.__type"},{"id":17,"kind":32,"name":"effects","url":"globals.html#upduxconfig.__type.effects","classes":"tsd-kind-variable tsd-parent-kind-type-literal tsd-is-not-exported","parent":"UpduxConfig.__type"},{"id":18,"kind":4194304,"name":"Upreducer","url":"globals.html#upreducer","classes":"tsd-kind-type-alias tsd-has-type-parameter"},{"id":19,"kind":65536,"name":"__type","url":"globals.html#upreducer.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"Upreducer"},{"id":20,"kind":64,"name":"actionCreator","url":"globals.html#actioncreator","classes":"tsd-kind-function tsd-has-type-parameter"},{"id":21,"kind":64,"name":"actionFor","url":"globals.html#actionfor","classes":"tsd-kind-function tsd-is-not-exported"},{"id":22,"kind":4194304,"name":"ActionPair","url":"globals.html#actionpair","classes":"tsd-kind-type-alias tsd-is-not-exported"},{"id":23,"kind":64,"name":"buildActions","url":"globals.html#buildactions","classes":"tsd-kind-function"},{"id":24,"kind":64,"name":"buildInitial","url":"globals.html#buildinitial","classes":"tsd-kind-function tsd-has-type-parameter"},{"id":25,"kind":64,"name":"composeMutations","url":"globals.html#composemutations","classes":"tsd-kind-function tsd-is-not-exported"},{"id":26,"kind":4194304,"name":"SubMutations","url":"globals.html#submutations","classes":"tsd-kind-type-alias tsd-is-not-exported"},{"id":27,"kind":65536,"name":"__type","url":"globals.html#submutations.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"SubMutations"},{"id":28,"kind":64,"name":"buildMutations","url":"globals.html#buildmutations","classes":"tsd-kind-function"},{"id":29,"kind":64,"name":"buildCreateStore","url":"globals.html#buildcreatestore","classes":"tsd-kind-function tsd-has-type-parameter"},{"id":30,"kind":64,"name":"MiddlewareFor","url":"globals.html#middlewarefor","classes":"tsd-kind-function tsd-is-not-exported"},{"id":31,"kind":4194304,"name":"Next","url":"globals.html#next","classes":"tsd-kind-type-alias tsd-is-not-exported"},{"id":32,"kind":65536,"name":"__type","url":"globals.html#next.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"Next"},{"id":33,"kind":64,"name":"buildMiddleware","url":"globals.html#buildmiddleware","classes":"tsd-kind-function tsd-has-type-parameter"},{"id":34,"kind":64,"name":"buildUpreducer","url":"globals.html#buildupreducer","classes":"tsd-kind-function tsd-has-type-parameter"},{"id":35,"kind":128,"name":"Updux","url":"classes/updux.html","classes":"tsd-kind-class tsd-has-type-parameter"},{"id":36,"kind":1024,"name":"subduxes","url":"classes/updux.html#subduxes","classes":"tsd-kind-property tsd-parent-kind-class","parent":"Updux"},{"id":37,"kind":1024,"name":"initial","url":"classes/updux.html#initial","classes":"tsd-kind-property tsd-parent-kind-class","parent":"Updux"},{"id":38,"kind":1024,"name":"groomMutations","url":"classes/updux.html#groommutations","classes":"tsd-kind-property tsd-parent-kind-class","parent":"Updux"},{"id":39,"kind":65536,"name":"__type","url":"classes/updux.html#groommutations.__type","classes":"tsd-kind-type-literal tsd-parent-kind-property","parent":"Updux.groomMutations"},{"id":40,"kind":512,"name":"constructor","url":"classes/updux.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"Updux"},{"id":41,"kind":262144,"name":"middleware","url":"classes/updux.html#middleware","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"Updux"},{"id":42,"kind":262144,"name":"actions","url":"classes/updux.html#actions","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"Updux"},{"id":43,"kind":262144,"name":"upreducer","url":"classes/updux.html#upreducer","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"Updux"},{"id":44,"kind":262144,"name":"reducer","url":"classes/updux.html#reducer","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"Updux"},{"id":45,"kind":262144,"name":"mutations","url":"classes/updux.html#mutations","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"Updux"},{"id":46,"kind":262144,"name":"subduxUpreducer","url":"classes/updux.html#subduxupreducer","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"Updux"},{"id":47,"kind":262144,"name":"createStore","url":"classes/updux.html#createstore","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"Updux"},{"id":48,"kind":262144,"name":"asDux","url":"classes/updux.html#asdux","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"Updux"},{"id":49,"kind":2048,"name":"addMutation","url":"classes/updux.html#addmutation","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter","parent":"Updux"},{"id":50,"kind":4194304,"name":"StoreWithDispatchActions","url":"globals.html#storewithdispatchactions","classes":"tsd-kind-type-alias tsd-has-type-parameter tsd-is-not-exported"},{"id":51,"kind":4194304,"name":"Dux","url":"globals.html#dux","classes":"tsd-kind-type-alias tsd-has-type-parameter"}]}; \ No newline at end of file diff --git a/docs/classes/updux.html b/docs/classes/updux.html index 96e18a8..0336f25 100644 --- a/docs/classes/updux.html +++ b/docs/classes/updux.html @@ -124,6 +124,7 @@
  • middleware
  • mutations
  • reducer
  • +
  • subduxUpreducer
  • upreducer
  • @@ -148,7 +149,7 @@
  • Parameters

    @@ -264,7 +265,7 @@
  • @@ -294,7 +295,7 @@ payload,meta}) (with the extra sugar that if meta or p
  • @@ -319,7 +320,7 @@ payload,meta}) (with the extra sugar that if meta or p
  • @@ -368,7 +369,7 @@ store.dispatch( actions.addTodo(...) );
  • @@ -392,7 +393,7 @@ store.dispatch( actions.addTodo(...) );
  • @@ -416,7 +417,7 @@ store.dispatch( actions.addTodo(...) );
  • @@ -450,6 +451,78 @@ store.dispatch( actions.addTodo(...) );
  • +
    + +

    subduxUpreducer

    +
      +
    • get subduxUpreducer(): function
    • +
    +
      +
    • + +
      +
      +

      Returns the upreducer made of the merge of all sudbuxes reducers, without + the local mutations. Useful, for example, for sink mutations.

      +
      +
      +
      example
      +
      import todo from './todo'; // updux for a single todo
      +import Updux from 'updux';
      +import u from 'updeep';
      +
      +const todos = new Updux({ initial: [], subduxes: { '*': todo } });
      +todos.addMutation(
      +    todo.actions.done,
      +    ({todo_id},action) => u.map( u.if( u.is('id',todo_id) ), todos.subduxUpreducer(action) )
      +    true
      +);
      +
      +
      +

      Returns function

      +
        +
      • +
          +
        • (action: Action): function
        • +
        +
          +
        • +

          Parameters

          + +

          Returns function

          +
            +
          • +
              +
            • (state: S): S
            • +
            +
              +
            • +

              Parameters

              +
                +
              • +
                state: S
                +
              • +
              +

              Returns S

              +
            • +
            +
          • +
          +
        • +
        +
      • +
      +
    • +
    +

    upreducer

    @@ -460,7 +533,7 @@ store.dispatch( actions.addTodo(...) );
  • Returns Upreducer<S>

    @@ -474,13 +547,13 @@ store.dispatch( actions.addTodo(...) );

    addMutation

      -
    • addMutation<A>(creator: A, mutation: Mutation<S, A extends (...args: any[]) => infer R ? R : never>): void
    • +
    • addMutation<A>(creator: A, mutation: Mutation<S, A extends (...args: any[]) => infer R ? R : never>, isSink?: undefined | false | true): void
    • @@ -508,6 +581,13 @@ store.dispatch( actions.addTodo(...) );
    • mutation: Mutation<S, A extends (...args: any[]) => infer R ? R : never>
    • +
    • +
      Optional isSink: undefined | false | true
      +
      +

      If true, disables the subduxes mutations for this action. To + conditionally run the subduxes mutations, check out subduxUpreducer.

      +
      +

    Returns void

  • @@ -560,6 +640,9 @@ store.dispatch( actions.addTodo(...) );
  • reducer
  • +
  • + subduxUpreducer +
  • upreducer
  • @@ -594,9 +677,6 @@ store.dispatch( actions.addTodo(...) );
  • Mutation
  • -
  • - MyState -
  • Next
  • @@ -645,15 +725,6 @@ store.dispatch( actions.addTodo(...) );
  • composeMutations
  • -
  • - noopEffect -
  • -
  • - timeout -
  • -
  • - tracer -
  • diff --git a/docs/globals.html b/docs/globals.html index a9de54d..d350fa7 100644 --- a/docs/globals.html +++ b/docs/globals.html @@ -84,7 +84,6 @@
  • Dux
  • MaybePayload
  • Mutation
  • -
  • MyState
  • Next
  • StoreWithDispatchActions
  • SubMutations
  • @@ -106,9 +105,6 @@
  • buildMutations
  • buildUpreducer
  • composeMutations
  • -
  • noopEffect
  • -
  • timeout
  • -
  • tracer
  • @@ -312,24 +308,6 @@ -
    - -

    MyState

    -
    MyState: object
    - -
    -

    Type declaration

    -
      -
    • -
      sum: number
      -
    • -
    -
    -

    Next

    @@ -932,7 +910,7 @@ const rootUpdux = updux({

    buildMutations

      -
    • buildMutations(mutations?: Dictionary<Mutation>, subduxes?: object): Dictionary<function>
    • +
    • buildMutations(mutations?: Dictionary<Mutation | Object>, subduxes?: object): Dictionary<function>
    • @@ -944,7 +922,7 @@ const rootUpdux = updux({

      Parameters

      • -
        Default value mutations: Dictionary<Mutation> = {}
        +
        Default value mutations: Dictionary<Mutation | Object> = {}
      • Default value subduxes: object = {}
        @@ -1050,69 +1028,6 @@ const rootUpdux = updux({
    -
    - -

    Const noopEffect

    -
      -
    • noopEffect(): (Anonymous function)
    • -
    -
      -
    • - -

      Returns (Anonymous function)

      -
    • -
    -
    -
    - -

    timeout

    -
      -
    • timeout(ms: number): Promise<unknown>
    • -
    -
      -
    • - -

      Parameters

      -
        -
      • -
        ms: number
        -
      • -
      -

      Returns Promise<unknown>

      -
    • -
    -
    -
    - -

    Const tracer

    -
      -
    • tracer(chr: string): CurriedUpdate1<object>
    • -
    -
      -
    • - -

      Parameters

      -
        -
      • -
        chr: string
        -
      • -
      -

      Returns CurriedUpdate1<object>

      -
    • -
    -
    diff --git a/docs/index.html b/docs/index.html index 33e256d..79645b4 100644 --- a/docs/index.html +++ b/docs/index.html @@ -138,7 +138,7 @@ store.dispatch.inc(3);

    Description

    The formal documentation of the class Updux and its associated functions and - types can be found over here.

    + types can be found over here.

    Exporting upduxes

    @@ -168,6 +168,49 @@ const updux = new Updux({ ... }); createStore, middleware, } = updux; + +

    Mapping a mutation to all values of a state

    +
    +

    Say you have a todos state that is an array of todo sub-states. It's easy + enough to have the main reducer maps away all items to the sub-reducer:

    +
    const todo = new Updux({
    +    mutations: {
    +        review: () => u({ reviewed: true}),
    +        done: () => u({done: true}),
    +    },
    +});
    +
    +const todos = new Updux({ initial: [] });
    +
    +todos.addMutation( 
    +    todo.actions.review, 
    +    (_,action) => state => state.map( todo.upreducer(action) )  
    +);
    +todos.addMutation(
    +    todo.actions.done, 
    +    (id,action) => u.map(u.if(u.is('id',id), todo.upreducer(action))),
    +);
    +

    But updeep can iterate through all the items of an array (or the values of + an object) via the special key *. So the todos updux above could also be + written:

    +
    const todo = new Updux({
    +    mutations: {
    +        review: () => u({ reviewed: true}),
    +        done: () => u({done: true}),
    +    },
    +});
    +
    +const todos = new Updux({
    +    subduxes: { '*': todo },
    +});
    +
    +todos.addMutation(
    +    todo.actions.done, 
    +    (id,action) => u.map(u.if(u.is('id',id), todo.upreducer(action))), 
    +    true
    +);

    The advantages being that the actions/mutations/effects of the subdux will be + imported by the root updux as usual, and all actions that aren't being + overridden by a sink mutation will trickle down automatically.

    Usage with Immer

    @@ -244,9 +287,6 @@ const updux = new Updux({ ... });
  • Mutation
  • -
  • - MyState -
  • Next
  • @@ -295,15 +335,6 @@ const updux = new Updux({ ... });
  • composeMutations
  • -
  • - noopEffect -
  • -
  • - timeout -
  • -
  • - tracer -
  • diff --git a/package.json b/package.json index f1f073e..4b050d4 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "build": "tsc && typedoc", "test": "jest" }, - "version": "1.0.0", + "version": "1.1.0", "repository": { "type": "git", "url": "git+https://github.com/yanick/updux.git" diff --git a/src/buildMutations/index.ts b/src/buildMutations/index.ts index 472a1a0..d20f77a 100644 --- a/src/buildMutations/index.ts +++ b/src/buildMutations/index.ts @@ -12,7 +12,7 @@ type SubMutations = { } function buildMutations( - mutations :Dictionary = {}, + mutations :Dictionary = {}, subduxes = {} ) { // we have to differentiate the subduxes with '*' than those @@ -49,15 +49,24 @@ function buildMutations( nonGlobby.forEach(([slice, {mutations = {}, reducer = {}}]:any[]) => { Object.entries(mutations).forEach(([type, mutation]) => { - const localized = (payload = null, action :Action) => - u.updateIn(slice)((mutation as Mutation)(payload, action)); + const localized = (payload = null, action :Action) => { + return u.updateIn(slice)((mutation as Mutation)(payload, action)); + } mergedMutations[type].push(localized); }); }); Object.entries(mutations).forEach(([type, mutation]) => { - mergedMutations[type].push(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.mapValues(composeMutations)(mergedMutations); diff --git a/src/mappedUpdux.test.ts b/src/mappedUpdux.test.ts new file mode 100644 index 0000000..ee5d2fc --- /dev/null +++ b/src/mappedUpdux.test.ts @@ -0,0 +1,29 @@ +import Updux from './updux'; +import u from 'updeep'; + +const todo = new Updux({ + mutations: { + review: () => u({ reviewed: true}), + done: () => u({done: true}), + }, +}); + +const todos = new Updux({ + subduxes: { '*': todo }, +}); + +todos.addMutation( + todo.actions.done, (id,action) => u.map(u.if(u.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 }, + ]); +}); diff --git a/src/sink.test.ts b/src/sink.test.ts new file mode 100644 index 0000000..0d8a942 --- /dev/null +++ b/src/sink.test.ts @@ -0,0 +1,56 @@ +import Updux from './updux'; + +const foo = new Updux({ + initial: 0, + mutations: { + doIt: () => (state: number) => { + return state + 1; + }, + doTheThing: () => (state: number) => { + return state + 3; + }, + }, +}); + +const bar = new Updux<{foo: number}>({ + subduxes: {foo}, +}); + +bar.addMutation( + foo.actions.doTheThing, + (_, action) => state => { + return { + ...state, + baz: bar.subduxUpreducer(action)(state), + }; + }, + true, +); + +bar.addMutation( + foo.actions.doIt, + () => (state: any) => ({...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}, + }); +}); diff --git a/src/updux.ts b/src/updux.ts index a159b50..6443db2 100644 --- a/src/updux.ts +++ b/src/updux.ts @@ -42,12 +42,12 @@ export type Dux = Pick< >; /** - * `Updux` is a way to minimize and simplify the boilerplate associated with the - * creation of a `Redux` store. It takes a shorthand configuration - * object, and generates the appropriate reducer, actions, middleware, etc. - * In true `Redux`-like fashion, upduxes can be made of sub-upduxes (`subduxes` for short) for different slices of the root state. - * @typeparam S Store's state type. Defaults to `any`. - */ + * `Updux` is a way to minimize and simplify the boilerplate associated with the + * creation of a `Redux` store. It takes a shorthand configuration + * object, and generates the appropriate reducer, actions, middleware, etc. + * In true `Redux`-like fashion, upduxes can be made of sub-upduxes (`subduxes` for short) for different slices of the root state. + * @typeparam S Store's state type. Defaults to `any`. + */ export class Updux { subduxes: Dictionary; @@ -60,41 +60,41 @@ export class Updux { */ initial: S; -/** - * Function that can be provided to alter all local mutations of the updux - * (the mutations of subduxes are left untouched). - * - * Can be used, for example, for Immer integration: - * - * ``` - * import Updux from 'updux'; - * import { produce } from 'Immer'; - * - * const updux = new Updux({ - * initial: { counter: 0 }, - * groomMutations: mutation => (...args) => produce( mutation(...args) ), - * mutations: { - * add: (inc=1) => draft => draft.counter += inc - * } - * }); - * - * ``` - * - * Or perhaps for debugging: - * - * ``` - * import Updux from 'updux'; - * - * const updux = new Updux({ - * initial: { counter: 0 }, - * groomMutations: mutation => (...args) => state => { - * console.log( "got action ", args[1] ); - * return mutation(...args)(state); - * } - * }); - * - * ``` - */ + /** + * Function that can be provided to alter all local mutations of the updux + * (the mutations of subduxes are left untouched). + * + * Can be used, for example, for Immer integration: + * + * ``` + * import Updux from 'updux'; + * import { produce } from 'Immer'; + * + * const updux = new Updux({ + * initial: { counter: 0 }, + * groomMutations: mutation => (...args) => produce( mutation(...args) ), + * mutations: { + * add: (inc=1) => draft => draft.counter += inc + * } + * }); + * + * ``` + * + * Or perhaps for debugging: + * + * ``` + * import Updux from 'updux'; + * + * const updux = new Updux({ + * initial: { counter: 0 }, + * groomMutations: mutation => (...args) => state => { + * console.log( "got action ", args[1] ); + * return mutation(...args)(state); + * } + * }); + * + * ``` + */ groomMutations: (mutation: Mutation) => Mutation; @observable private localEffects: Dictionary< @@ -103,7 +103,9 @@ export class Updux { @observable private localActions: Dictionary; - @observable private localMutations: Dictionary>; + @observable private localMutations: Dictionary< + Mutation | [Mutation, boolean | undefined] + >; constructor(config: UpduxConfig = {}) { this.groomMutations = config.groomMutations || ((x: Mutation) => x); @@ -186,6 +188,27 @@ export class Updux { return buildMutations(this.localMutations, this.subduxes); } + /** + * Returns the upreducer made of the merge of all sudbuxes reducers, without + * the local mutations. Useful, for example, for sink mutations. + * @example + * ``` + * import todo from './todo'; // updux for a single todo + * import Updux from 'updux'; + * import u from 'updeep'; + * + * const todos = new Updux({ initial: [], subduxes: { '*': todo } }); + * todos.addMutation( + * todo.actions.done, + * ({todo_id},action) => u.map( u.if( u.is('id',todo_id) ), todos.subduxUpreducer(action) ) + * true + * ); + * ``` + */ + @computed get subduxUpreducer() { + return buildUpreducer(this.initial, buildMutations({}, this.subduxes)); + } + /** * Same as doing * @@ -245,6 +268,9 @@ export class Updux { * Adds a mutation and its associated action to the updux. * If a local mutation was already associated to the action, * it will be replaced by the new one. + * @param isSink + * If `true`, disables the subduxes mutations for this action. To + * conditionally run the subduxes mutations, check out [[subduxUpreducer]]. * @example * ``` * updux.addMutation( add, inc => state => state + inc ); @@ -253,11 +279,13 @@ export class Updux { addMutation( creator: A, mutation: Mutation infer R ? R : never>, + isSink?: boolean, ) { this.localActions[creator.type] = creator; - this.localMutations[creator.type] = this.groomMutations( - mutation as any, - ) as Mutation; + this.localMutations[creator.type] = [ + this.groomMutations(mutation as any) as Mutation, + isSink, + ]; } } diff --git a/typedoc.json b/typedoc.json index 3730d0d..57328f4 100644 --- a/typedoc.json +++ b/typedoc.json @@ -4,5 +4,6 @@ "out": "docs", "mode": "file", "excludePrivate": true, - "excludeNotExported": false + "excludeNotExported": false, + "exclude": [ "src/**/*test.ts" ] }