Skip to content

Commit

Permalink
Framework: Refuse to persist any UI state
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Feb 16, 2016
1 parent 580f8ac commit c8faa44
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 237 deletions.
10 changes: 1 addition & 9 deletions client/state/ui/editor/media/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,12 @@ import { combineReducers } from 'redux';
/**
* Internal dependencies
*/
import {
EDITOR_MEDIA_EDIT_ITEM_SET,
SERIALIZE,
DESERIALIZE
} from 'state/action-types';
import { EDITOR_MEDIA_EDIT_ITEM_SET } from 'state/action-types';

export function editItem( state = null, action ) {
switch ( action.type ) {
case EDITOR_MEDIA_EDIT_ITEM_SET:
return action.item || null;
case SERIALIZE:
return null;
case DESERIALIZE:
return null;
}

return state;
Expand Down
27 changes: 0 additions & 27 deletions client/state/ui/editor/media/test/reducer.js

This file was deleted.

12 changes: 1 addition & 11 deletions client/state/ui/reader/sidebar/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@ import { combineReducers } from 'redux';
*/
import {
READER_SIDEBAR_LISTS_TOGGLE,
READER_SIDEBAR_TAGS_TOGGLE,
SERIALIZE,
DESERIALIZE
READER_SIDEBAR_TAGS_TOGGLE
} from 'state/action-types';

export function isListsOpen( state = false, action ) {
switch ( action.type ) {
case READER_SIDEBAR_LISTS_TOGGLE:
return ! state;
case SERIALIZE:
return false;
case DESERIALIZE:
return false;
}

return state;
Expand All @@ -30,10 +24,6 @@ export function isTagsOpen( state = false, action ) {
switch ( action.type ) {
case READER_SIDEBAR_TAGS_TOGGLE:
return ! state;
case SERIALIZE:
return false;
case DESERIALIZE:
return false;
}

return state;
Expand Down
51 changes: 0 additions & 51 deletions client/state/ui/reader/sidebar/test/reducer.js

This file was deleted.

34 changes: 9 additions & 25 deletions client/state/ui/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ export function selectedSiteId( state = null, action ) {
switch ( action.type ) {
case SELECTED_SITE_SET:
return action.siteId || null;
case SERIALIZE:
return null;
case DESERIALIZE:
return null
}

return state;
Expand All @@ -50,10 +46,6 @@ export function recentlySelectedSiteIds( state = [], action ) {
state.pop();
}
return state;
case SERIALIZE:
return [];
case DESERIALIZE:
return [];
}

return state;
Expand All @@ -64,10 +56,6 @@ export function section( state = false, action ) {
switch ( action.type ) {
case SET_SECTION:
return ( action.section !== undefined ) ? action.section : state;
case SERIALIZE:
return state;
case DESERIALIZE:
return state;
}
return state;
}
Expand All @@ -76,10 +64,6 @@ export function hasSidebar( state = true, action ) {
switch ( action.type ) {
case SET_SECTION:
return ( action.hasSidebar !== undefined ) ? action.hasSidebar : state;
case SERIALIZE:
return state;
case DESERIALIZE:
return state;
}
return state;
}
Expand All @@ -95,10 +79,6 @@ export function isLoading( state = false, action ) {
switch ( action.type ) {
case SET_SECTION:
return ( action.isLoading !== undefined ) ? action.isLoading : state;
case SERIALIZE:
return false;
case DESERIALIZE:
return false;
}
return state;
}
Expand All @@ -107,15 +87,11 @@ export function chunkName( state = false, action ) {
switch ( action.type ) {
case SET_SECTION:
return ( action.chunkName !== undefined ) ? action.chunkName : state;
case SERIALIZE:
return false;
case DESERIALIZE:
return false;
}
return state;
}

export default combineReducers( {
const reducer = combineReducers( {
section,
isLoading,
hasSidebar,
Expand All @@ -126,3 +102,11 @@ export default combineReducers( {
editor,
reader
} );

export default function( state, action ) {
if ( SERIALIZE === action.type || DESERIALIZE === action.type ) {
return {};
}

return reducer( state, action );
}
135 changes: 21 additions & 114 deletions client/state/ui/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,30 @@ import { expect } from 'chai';
/**
* Internal dependencies
*/
import { SELECTED_SITE_SET, SERIALIZE, DESERIALIZE } from 'state/action-types';
import {
selectedSiteId,
recentlySelectedSiteIds,
section,
hasSidebar,
isLoading,
chunkName
} from '../reducer';
SELECTED_SITE_SET,
SERIALIZE,
DESERIALIZE
} from 'state/action-types';
import reducer, { selectedSiteId } from '../reducer';

describe( 'reducer', () => {
it( 'should refuse to persist any state', () => {
const state = reducer( {
selectedSiteId: 2916284
}, { type: SERIALIZE } );

expect( state ).to.eql( {} );
} );

it( 'should refuse to restore any persisted state', () => {
const state = reducer( {
selectedSiteId: 2916284
}, { type: DESERIALIZE } );

expect( state ).to.eql( {} );
} );

describe( '#selectedSiteId()', () => {
it( 'should default to null', () => {
const state = selectedSiteId( undefined, {} );
Expand All @@ -41,111 +54,5 @@ describe( 'reducer', () => {

expect( state ).to.be.null;
} );

it( 'should not persist data because this is not implemented', () => {
const state = selectedSiteId( 2916284, {
type: SERIALIZE
} );

expect( state ).to.eql( null );
} );

it( 'should not load persisted state because this is not implemented', () => {
const state = selectedSiteId( 2916284, {
type: DESERIALIZE
} );

expect( state ).to.eql( null );
} );
} );

describe( '#recentlySelectedSiteIds()', () => {
it( 'should not persist data because this is not implemented', () => {
const state = recentlySelectedSiteIds( [ 2916284 ], {
type: SERIALIZE
} );

expect( state ).to.eql( [] );
} );

it( 'should not load persisted state because this is not implemented', () => {
const state = recentlySelectedSiteIds( [ 2916284 ], {
type: DESERIALIZE
} );

expect( state ).to.eql( [] );
} );
} );

describe( '#section()', () => {
it( 'should persist data', () => {
const state = section( 'hello', {
type: SERIALIZE
} );

expect( state ).to.eql( 'hello' );
} );

it( 'should load persisted state', () => {
const state = section( 'hello', {
type: DESERIALIZE
} );

expect( state ).to.eql( 'hello' );
} );
} );

describe( '#hasSidebar()', () => {
it( 'should persist data', () => {
const state = hasSidebar( false, {
type: SERIALIZE
} );

expect( state ).to.eql( false );
} );

it( 'should load persisted state', () => {
const state = hasSidebar( false, {
type: DESERIALIZE
} );

expect( state ).to.eql( false );
} );
} );

describe( '#isLoading()', () => {
it( 'should not persist data because this is not implemented', () => {
const state = isLoading( true, {
type: SERIALIZE
} );

expect( state ).to.eql( false );
} );

it( 'should not load persisted state because this is not implemented', () => {
const state = isLoading( true, {
type: DESERIALIZE
} );

expect( state ).to.eql( false );
} );
} );

describe( '#chunkName()', () => {
it( 'should not persist data because this is not implemented', () => {
const state = chunkName( 'hello', {
type: SERIALIZE
} );

expect( state ).to.eql( false );
} );

it( 'should not load persisted state because this is not implemented', () => {
const state = chunkName( 'hello', {
type: DESERIALIZE
} );

expect( state ).to.eql( false );
} );
} );
} );

0 comments on commit c8faa44

Please sign in to comment.