Skip to content

Commit

Permalink
Framework: do not persist sites
Browse files Browse the repository at this point in the history
  • Loading branch information
gwwar committed Feb 29, 2016
1 parent 7c29ebc commit ff4cfa3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 33 deletions.
17 changes: 1 addition & 16 deletions client/state/sites/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@
* External dependencies
*/
import { combineReducers } from 'redux';
import pickBy from 'lodash/pickBy';
import keyBy from 'lodash/keyBy';
import isFunction from 'lodash/isFunction';
import omit from 'lodash/omit';

/**
* Internal dependencies
*/
import { plans } from './plans/reducer';
import { SITE_RECEIVE, SERIALIZE, DESERIALIZE } from 'state/action-types';
import { sitesSchema } from './schema';
import { isValidStateWithSchema } from 'state/utils';

/**
* Tracks all known site objects, indexed by site ID.
Expand All @@ -29,17 +23,8 @@ export function items( state = {}, action ) {
[ action.site.ID ]: action.site
} );
case SERIALIZE:
// scrub _events, _maxListeners, and other misc functions
const sites = Object.keys( state ).map( ( siteID ) => {
let plainJSObject = pickBy( state[ siteID ], ( value ) => ! isFunction( value ) );
plainJSObject = omit( plainJSObject, [ '_events', '_maxListeners'] );
return plainJSObject;
} );
return keyBy( sites, 'ID' );
return {};
case DESERIALIZE:
if ( isValidStateWithSchema( state, sitesSchema ) ) {
return state;
}
return {};
}
return state;
Expand Down
23 changes: 6 additions & 17 deletions client/state/sites/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe( 'reducer', () => {
} );
} );
describe( 'persistence', () => {
it( 'should return a js object on SERIALIZE', () => {
it( 'does not persist state because this is not implemented yet', () => {
const original = deepFreeze( {
2916284: {
ID: 2916284,
Expand All @@ -75,11 +75,9 @@ describe( 'reducer', () => {
}
} );
const state = items( original, { type: SERIALIZE } );
expect( state ).to.eql( {
2916284: { ID: 2916284, name: 'WordPress.com Example Blog' }
} );
expect( state ).to.eql( {} );
} );
it( 'validates state on DESERIALIZE', () => {
it( 'does not load persisted state because this is not implemented yet', () => {
const original = deepFreeze( {
2916284: {
ID: 2916284,
Expand All @@ -91,25 +89,16 @@ describe( 'reducer', () => {
}
} );
const state = items( original, { type: DESERIALIZE } );
expect( state ).to.eql( {
2916284: {
ID: 2916284,
name: 'WordPress.com Example Blog'
},
2916285: {
ID: 2916285,
name: 'WordPress.com Example Blog 2'
}
} );
expect( state ).to.eql( {} );
} );
it( 'returns initial state when state is missing required properties', () => {
it.skip( 'returns initial state when state is missing required properties', () => {
const original = deepFreeze( {
2916284: { name: 'WordPress.com Example Blog' }
} );
const state = items( original, { type: DESERIALIZE } );
expect( state ).to.eql( {} );
} );
it( 'returns initial state when state has invalid keys', () => {
it.skip( 'returns initial state when state has invalid keys', () => {
const original = deepFreeze( {
foobar: { name: 'WordPress.com Example Blog' }
} );
Expand Down

0 comments on commit ff4cfa3

Please sign in to comment.