diff --git a/client/state/test/utils.js b/client/state/test/utils.js index 4b39fd3a4f274..e1226c67114ea 100644 --- a/client/state/test/utils.js +++ b/client/state/test/utils.js @@ -27,7 +27,7 @@ describe( 'utils', () => { let keyedReducer; let reducer; let withSchemaValidation; - let combineReducersWithPersistence; + let combineReducers; let isValidStateWithSchema; let withoutPersistence; @@ -39,7 +39,7 @@ describe( 'utils', () => { extendAction, keyedReducer, withSchemaValidation, - combineReducersWithPersistence, + combineReducers, isValidStateWithSchema, withoutPersistence, } = require( 'state/utils' ) ); @@ -441,7 +441,7 @@ describe( 'utils', () => { } ); } ); - describe( '#combineReducersWithPersistence', () => { + describe( '#combineReducers', () => { const load = { type: DESERIALIZE }; const write = { type: SERIALIZE }; const grow = { type: 'GROW' }; @@ -485,7 +485,7 @@ describe( 'utils', () => { let reducers; beforeEach( () => { - reducers = combineReducersWithPersistence( { + reducers = combineReducers( { age, height } ); @@ -522,12 +522,12 @@ describe( 'utils', () => { } ); it( 'nested reducers work on load', () => { - reducers = combineReducersWithPersistence( { + reducers = combineReducers( { age, height, date } ); - const nested = combineReducersWithPersistence( { + const nested = combineReducers( { person: reducers, count } ); @@ -539,12 +539,12 @@ describe( 'utils', () => { } ); it( 'nested reducers work on persist', () => { - reducers = combineReducersWithPersistence( { + reducers = combineReducers( { age, height, date } ); - const nested = combineReducersWithPersistence( { + const nested = combineReducers( { person: reducers, count } ); @@ -556,15 +556,15 @@ describe( 'utils', () => { } ); it( 'deeply nested reducers work on load', () => { - reducers = combineReducersWithPersistence( { + reducers = combineReducers( { age, height, date } ); - const nested = combineReducersWithPersistence( { + const nested = combineReducers( { person: reducers, } ); - const veryNested = combineReducersWithPersistence( { + const veryNested = combineReducers( { bob: nested, count } ); @@ -576,15 +576,15 @@ describe( 'utils', () => { } ); it( 'deeply nested reducers work on persist', () => { - reducers = combineReducersWithPersistence( { + reducers = combineReducers( { age, height, date } ); - const nested = combineReducersWithPersistence( { + const nested = combineReducers( { person: reducers, } ); - const veryNested = combineReducersWithPersistence( { + const veryNested = combineReducers( { bob: nested, count } ); @@ -596,14 +596,14 @@ describe( 'utils', () => { } ); it( 'deeply nested reducers work with reducer with a custom handler', () => { - reducers = combineReducersWithPersistence( { + reducers = combineReducers( { height, date } ); - const nested = combineReducersWithPersistence( { + const nested = combineReducers( { person: reducers, } ); - const veryNested = combineReducersWithPersistence( { + const veryNested = combineReducers( { bob: nested, count } ); @@ -615,7 +615,7 @@ describe( 'utils', () => { } ); it( 'uses the provided validation from withSchemaValidation', () => { - reducers = combineReducersWithPersistence( { + reducers = combineReducers( { height: withSchemaValidation( schema, height ), count } ); @@ -628,7 +628,7 @@ describe( 'utils', () => { } ); it( 'uses the provided validation from createReducer', () => { - reducers = combineReducersWithPersistence( { + reducers = combineReducers( { height: createReducer( 160, {}, schema ), count } ); diff --git a/client/state/utils.js b/client/state/utils.js index 47c0703d73a3c..a97bf2db05c9b 100644 --- a/client/state/utils.js +++ b/client/state/utils.js @@ -3,7 +3,7 @@ */ import validator from 'is-my-json-valid'; import { merge, flow, partialRight, reduce, isEqual, omit } from 'lodash'; -import { combineReducers } from 'redux'; +import { combineReducers as combine } from 'redux'; /** * Internal dependencies @@ -322,7 +322,7 @@ export const withSchemaValidation = ( schema, reducer ) => { * * age.schema = schema; * - * const combinedReducer = combineReducersWithPersistence( { + * const combinedReducer = combineReducers( { * age, * height * } ); @@ -354,7 +354,7 @@ export const withSchemaValidation = ( schema, reducer ) => { * }; * date.hasCustomPersistence = true; * - * const combinedReducer = combineReducersWithPersistence( { + * const combinedReducer = combineReducers( { * date, * height * } ); @@ -368,12 +368,12 @@ export const withSchemaValidation = ( schema, reducer ) => { * @param {object} reducers - object containing the reducers to merge * @returns {function} - Returns the combined reducer function */ -export function combineReducersWithPersistence( reducers ) { +export function combineReducers( reducers ) { const validatedReducers = reduce( reducers, ( validated, next, key ) => { const { schema, hasCustomPersistence } = next; return { ...validated, [ key ]: hasCustomPersistence ? next : withSchemaValidation( schema, next ) }; }, {} ); - const combined = combineReducers( validatedReducers ); + const combined = combine( validatedReducers ); combined.hasCustomPersistence = true; return combined; } diff --git a/docs/our-approach-to-data.md b/docs/our-approach-to-data.md index 681a9398db6a0..68d9d9c8ab493 100644 --- a/docs/our-approach-to-data.md +++ b/docs/our-approach-to-data.md @@ -395,14 +395,14 @@ handlers to avoid data shape errors. ### Opt-in to Persistence ( [#13542](https://github.com/Automattic/wp-calypso/pull/13542) ) If we choose not to use `createReducer` we can opt-in to persistence by adding a schema as a property on the reducer. -We do this by combining all of our reducers using `combineReducersWithPersistence` at every level of the tree instead -of [combineReducers](http://redux.js.org/docs/api/combineReducers.html). Each reducer is then wrapped with +We do this by combining all of our reducers using `combineReducers` from `state/utils` at every level of the tree instead +of [combineReducers](http://redux.js.org/docs/api/combineReducers.html) from `redux`. Each reducer is then wrapped with `withSchemaValidation` which returns a wrapped reducer that validates on `DESERIALZE` if a schema is present and returns initial state on both `SERIALIZE` and `DESERIALZE` if a schema is not present. To opt-out of persistence we combine the reducers without any attached schema. ```javascript -return combineReducersWithPersistence( { +return combineReducers( { age, height, } ); @@ -411,7 +411,7 @@ return combineReducersWithPersistence( { To persist, we add the schema as a property on the reducer: ```javascript age.schema = ageSchema; -return combineReducersWithPersistence( { +return combineReducers( { age, height, } ); @@ -422,7 +422,7 @@ on `DESERIALIZE` so all we need to do is set a boolean bit on the reducer, to en incorrectly from the default handling provided by `withSchemaValidation`. ```javascript date.hasCustomPersistence = true; -return combineReducersWithPersistence( { +return combineReducers( { age, height, date,