From 5dccc991e052bc3f664bdef138fa1aa620ed94e1 Mon Sep 17 00:00:00 2001 From: Kai Moseley Date: Wed, 13 Jun 2018 09:45:28 +0100 Subject: [PATCH] refactor(interface): Move resetAll to top level --- readme.md | 6 ++++-- src/__tests__/buildStoreChunk.test.js | 7 +++---- src/buildStoreChunk.js | 5 +---- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/readme.md b/readme.md index 14464c8..7b4cdb5 100644 --- a/readme.md +++ b/readme.md @@ -148,10 +148,12 @@ const exampleBatchedUpdateHittingSameReducerMultipleTimes = createCombinedAction ``` #### resetAll -The special `resetAll` action is available for nested reducers (i.e. those where more than just one reducer has been defined in the chunk). Calling this action allows you to reset all of the reducers in the chunk simultaneously. +The special `resetAll` action is available for nested reducers (i.e. those where more than just one reducer has been defined in the chunk). Calling this action allows you to reset all of the reducers in the chunk simultaneously. It is exposed at the top level, rather +than within the actions object, due to it being a breaking change when mapping over the actions object. In v2 it will be moved into the +actions object! ``` -store.dispatch(actions.resetAll()); +store.dispatch(storeChunk.resetAll()); ``` #### Examples diff --git a/src/__tests__/buildStoreChunk.test.js b/src/__tests__/buildStoreChunk.test.js index b5874ca..4e7e474 100644 --- a/src/__tests__/buildStoreChunk.test.js +++ b/src/__tests__/buildStoreChunk.test.js @@ -20,7 +20,7 @@ describe("buildStoreChunk", () => { example: Types.reducer(Types.string()) }) ) - ).toEqual(["reducers", "actions", "selectors"]); + ).toEqual(["reducers", "actions", "selectors", "resetAll"]); }); describe("Resulting chunk", () => { @@ -92,8 +92,7 @@ describe("buildStoreChunk", () => { "nested2", "nested3", "nested4", - "nested5", - "resetAll" + "nested5" ]); }); it("Actions object has the correct top level structure for a non nested chunk", () => { @@ -219,7 +218,7 @@ describe("buildStoreChunk", () => { }) ); - store.dispatch(chunk.actions.resetAll()); + store.dispatch(chunk.resetAll()); expect(chunk.selectors.nested2(store.getState())).toEqual({ foo: 0, bar: "" diff --git a/src/buildStoreChunk.js b/src/buildStoreChunk.js index 4cba420..671db6a 100644 --- a/src/buildStoreChunk.js +++ b/src/buildStoreChunk.js @@ -105,10 +105,7 @@ export function buildStoreChunk( if (locationString === name) { return { ...processedStructure, - actions: { - ...processedStructure.actions, - resetAll: createResetAllAction(name, processedStructure.actions) - } + resetAll: createResetAllAction(name, processedStructure.actions) }; }