Skip to content

Commit

Permalink
Framework: rename combineReducersWithPersistence to combineReducers
Browse files Browse the repository at this point in the history
  • Loading branch information
gwwar committed May 24, 2017
1 parent 14e80ac commit 6fd6c1b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
38 changes: 19 additions & 19 deletions client/state/test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe( 'utils', () => {
let keyedReducer;
let reducer;
let withSchemaValidation;
let combineReducersWithPersistence;
let combineReducers;
let isValidStateWithSchema;
let withoutPersistence;

Expand All @@ -39,7 +39,7 @@ describe( 'utils', () => {
extendAction,
keyedReducer,
withSchemaValidation,
combineReducersWithPersistence,
combineReducers,
isValidStateWithSchema,
withoutPersistence,
} = require( 'state/utils' ) );
Expand Down Expand Up @@ -441,7 +441,7 @@ describe( 'utils', () => {
} );
} );

describe( '#combineReducersWithPersistence', () => {
describe( '#combineReducers', () => {
const load = { type: DESERIALIZE };
const write = { type: SERIALIZE };
const grow = { type: 'GROW' };
Expand Down Expand Up @@ -485,7 +485,7 @@ describe( 'utils', () => {
let reducers;

beforeEach( () => {
reducers = combineReducersWithPersistence( {
reducers = combineReducers( {
age,
height
} );
Expand Down Expand Up @@ -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
} );
Expand All @@ -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
} );
Expand All @@ -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
} );
Expand All @@ -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
} );
Expand All @@ -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
} );
Expand All @@ -615,7 +615,7 @@ describe( 'utils', () => {
} );

it( 'uses the provided validation from withSchemaValidation', () => {
reducers = combineReducersWithPersistence( {
reducers = combineReducers( {
height: withSchemaValidation( schema, height ),
count
} );
Expand All @@ -628,7 +628,7 @@ describe( 'utils', () => {
} );

it( 'uses the provided validation from createReducer', () => {
reducers = combineReducersWithPersistence( {
reducers = combineReducers( {
height: createReducer( 160, {}, schema ),
count
} );
Expand Down
10 changes: 5 additions & 5 deletions client/state/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -322,7 +322,7 @@ export const withSchemaValidation = ( schema, reducer ) => {
*
* age.schema = schema;
*
* const combinedReducer = combineReducersWithPersistence( {
* const combinedReducer = combineReducers( {
* age,
* height
* } );
Expand Down Expand Up @@ -354,7 +354,7 @@ export const withSchemaValidation = ( schema, reducer ) => {
* };
* date.hasCustomPersistence = true;
*
* const combinedReducer = combineReducersWithPersistence( {
* const combinedReducer = combineReducers( {
* date,
* height
* } );
Expand All @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions docs/our-approach-to-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
} );
Expand All @@ -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,
} );
Expand All @@ -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,
Expand Down

0 comments on commit 6fd6c1b

Please sign in to comment.