Skip to content

Commit

Permalink
Merge pull request #3621 from Automattic/update/disable-persistence-w…
Browse files Browse the repository at this point in the history
…ithout-schemas

Framework: Update/disable persistence without schemas
  • Loading branch information
gwwar committed Feb 29, 2016
2 parents f3057b4 + ff4cfa3 commit dea6260
Show file tree
Hide file tree
Showing 23 changed files with 176 additions and 161 deletions.
8 changes: 7 additions & 1 deletion client/state/receipts/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { combineReducers } from 'redux';
import {
RECEIPT_FETCH,
RECEIPT_FETCH_COMPLETED,
RECEIPT_FETCH_FAILED
RECEIPT_FETCH_FAILED,
SERIALIZE,
DESERIALIZE
} from 'state/action-types';

export const initialReceiptState = {
Expand Down Expand Up @@ -51,6 +53,10 @@ export function items( state = {}, action ) {
error: action.error,
isRequesting: false
} );
case SERIALIZE:
return {};
case DESERIALIZE:
return {};
}

return state;
Expand Down
31 changes: 30 additions & 1 deletion client/state/receipts/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
* External dependencies
*/
import { expect } from 'chai';
import deepFreeze from 'deep-freeze';

/**
* Internal dependencies
*/
import {
RECEIPT_FETCH,
RECEIPT_FETCH_COMPLETED,
RECEIPT_FETCH_FAILED
RECEIPT_FETCH_FAILED,
SERIALIZE,
DESERIALIZE
} from 'state/action-types';
import { items } from '../reducer';

Expand Down Expand Up @@ -86,5 +89,31 @@ describe( 'reducer', () => {
}
} );
} );
describe( 'persistence', () => {
it( 'does not persist data because this is not implemented yet', () => {
const original = deepFreeze( {
11111111: {
data: { amount: 10 },
error: null,
hasLoadedFromServer: true,
isRequesting: true
}
} );
const state = items( original, { type: SERIALIZE } );
expect( state ).to.eql( {} );
} );
it( 'does not load persisted data because this is not implemented yet', () => {
const original = deepFreeze( {
11111111: {
data: { amount: 10 },
error: null,
hasLoadedFromServer: true,
isRequesting: true
}
} );
const state = items( original, { type: DESERIALIZE } );
expect( state ).to.eql( {} );
} );
} );
} );
} );
8 changes: 4 additions & 4 deletions client/state/sharing/publicize/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export function fetchingConnections( state = {}, action ) {
[ siteId ]: PUBLICIZE_CONNECTIONS_REQUEST === type
} );
case SERIALIZE:
return state;
return {};
case DESERIALIZE:
return state;
return {};
}

return state;
Expand All @@ -55,9 +55,9 @@ export function connections( state = {}, action ) {
case PUBLICIZE_CONNECTIONS_RECEIVE:
return Object.assign( {}, state, keyBy( action.data.connections, 'ID' ) );
case SERIALIZE:
return state;
return {};
case DESERIALIZE:
return state;
return {};
}

return state;
Expand Down
59 changes: 11 additions & 48 deletions client/state/sharing/publicize/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import { expect } from 'chai';
import deepFreeze from 'deep-freeze';

/**
* Internal dependencies
Expand Down Expand Up @@ -47,42 +48,26 @@ describe( '#fetchingConnections()', () => {
} );

describe( 'persistence', () => {
it( 'should load valid persisted data', () => {
const persistedState = Object.freeze( {
it( 'never loads persisted data', () => {
const persistedState = deepFreeze( {
2916284: false,
123456: undefined
} );
const state = fetchingConnections( persistedState, {
type: DESERIALIZE
} );
expect( state ).to.eql( { 2916284: false, 123456: undefined } );
} );

it.skip( 'should ignore loading data with invalid keys', () => {
const persistedState = Object.freeze( { foo: false } );
const state = fetchingConnections( persistedState, {
type: DESERIALIZE
} );
expect( state ).to.eql( {} );
} );

it.skip( 'should ignore loading data with invalid values', () => {
const persistedState = Object.freeze( { 2916284: 'foo' } );
const state = fetchingConnections( persistedState, {
type: DESERIALIZE
} );
expect( state ).to.eql( {} );
} );

it( 'should persists data', () => {
const state = Object.freeze( {
it( 'never persists data', () => {
const state = deepFreeze( {
2916284: false,
123456: undefined
} );
const persistedState = fetchingConnections( state, {
type: SERIALIZE
} );
expect( persistedState ).to.eql( state );
expect( persistedState ).to.eql( {} );
} );
} );
} );
Expand Down Expand Up @@ -137,45 +122,23 @@ describe( '#connections()', () => {
} );

describe( 'persistence', () => {
it( 'should persist data', () => {
const state = Object.freeze( {
it( 'does not persist data because this is not implemented yet', () => {
const state = deepFreeze( {
1: { ID: 1, site_ID: 2916284 },
2: { ID: 2, site_ID: 2916284 }
} );
const persistedState = connections( state, { type: SERIALIZE } );
expect( persistedState ).to.eql( state );
expect( persistedState ).to.eql( {} );
} );

it( 'should load valid data', () => {
const persistedState = Object.freeze( {
it( 'does not load persisted data because this is not implemented yet', () => {
const persistedState = deepFreeze( {
1: { ID: 1, site_ID: 2916284 },
2: { ID: 2, site_ID: 2916284 }
} );
const state = connections( persistedState, {
type: DESERIALIZE
} );
expect( state ).to.eql( persistedState );
} );

it.skip( 'should ignore loading data with invalid keys', () => {
const persistedState = Object.freeze( {
foo: { ID: 1, site_ID: 2916284 },
bar: { ID: 2, site_ID: 2916284 }
} );
const state = connections( persistedState, {
type: DESERIALIZE
} );
expect( state ).to.eql( {} );
} );

it.skip( 'should ignore loading data with invalid values', () => {
const persistedState = Object.freeze( {
1: { ID: 1, site_ID: 'foo' },
2: { ID: 2, site_ID: 2916284 }
} );
const state = connections( persistedState, {
type: DESERIALIZE
} );
expect( state ).to.eql( {} );
} );
} );
Expand Down
4 changes: 2 additions & 2 deletions client/state/site-settings/exporter/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ export function advancedSettings( state = {}, action ) {
[ action.siteId ]: action.advancedSettings
} );
case SERIALIZE:
return state;
return {};
case DESERIALIZE:
return state;
return {};
}
return state;
}
Expand Down
8 changes: 4 additions & 4 deletions client/state/site-settings/exporter/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ describe( 'reducer', () => {
} );

describe( '#advancedSettings()', () => {
it( 'should persist state', () => {
it( 'does not persist data because this is not implemented yet', () => {
const settings = { 100658273: SAMPLE_ADVANCED_SETTINGS };
const state = advancedSettings( settings, { type: SERIALIZE } );
expect( state ).to.eql( settings );
expect( state ).to.eql( {} );
} );

it( 'should load persisted state', () => {
it( 'does not load persisted data because this is not implemented yet', () => {
const settings = { 100658273: SAMPLE_ADVANCED_SETTINGS };
const state = advancedSettings( settings, { type: DESERIALIZE } );
expect( state ).to.eql( settings );
expect( state ).to.eql( {} );
} );

it( 'should index settings by site ID', () => {
Expand Down
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
4 changes: 4 additions & 0 deletions client/state/support/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export function errorMessage( state = null, action ) {
return action.errorMessage;
case SUPPORT_USER_ACTIVATE:
return null;
case SERIALIZE:
return null;
case DESERIALIZE:
return null;
}

return state;
Expand Down
Loading

0 comments on commit dea6260

Please sign in to comment.