Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Themes: Remove Flux stores #1363

Merged
merged 3 commits into from
Dec 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions shared/lib/themes/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
Theme Data
==========

Contains stores and action creators for themes, and the theme showcase.
Contains reducers and action creators for themes, and the theme showcase.

## Stores

We're transitioning to a more `redux`-like architecture, so our Flux `./stores` are created from `./reducers`, using our own `createReducerStore()`.
## Reducers

### current-theme

Expand Down
8 changes: 2 additions & 6 deletions shared/lib/themes/reducers/current-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { fromJS } from 'immutable';
*/
import ThemeConstants from 'lib/themes/constants';

export const initialState = fromJS( {
const initialState = fromJS( {
isActivating: false,
hasActivated: false,
currentThemes: {}
} );

export const reducer = ( state = initialState, action ) => {
export default ( state = initialState, action ) => {
switch ( action.type ) {
case ThemeConstants.RECEIVE_CURRENT_THEME:
return state.setIn( [ 'currentThemes', action.site.ID ], {
Expand All @@ -33,7 +33,3 @@ export const reducer = ( state = initialState, action ) => {
}
return state;
};

export function getCurrentTheme( state, siteId ) {
return state.get( 'currentThemes' ).get( siteId );
}
8 changes: 4 additions & 4 deletions shared/lib/themes/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { combineReducers } from 'redux';
/**
* Internal dependencies
*/
import { reducer as themes } from './themes';
import { reducer as themesList } from './themes-list';
import { reducer as themesLastQuery } from './themes-last-query';
import { reducer as currentTheme } from './current-theme';
import themes from './themes';
import themesList from './themes-list';
import themesLastQuery from './themes-last-query';
import currentTheme from './current-theme';

export default combineReducers( {
themes,
Expand Down
12 changes: 2 additions & 10 deletions shared/lib/themes/reducers/themes-last-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import { fromJS } from 'immutable';
*/
import ThemeConstants from '../constants';

export const initialState = fromJS( {
const initialState = fromJS( {
previousSiteId: 0,
currentSiteId: null,
isJetpack: null,
lastParams: null,
} );

export const reducer = ( state = initialState, action ) => {
export default ( state = initialState, action ) => {
switch ( action.type ) {
case ThemeConstants.QUERY_THEMES:
return state.set( 'lastParams', action.params );
Expand All @@ -29,11 +29,3 @@ export const reducer = ( state = initialState, action ) => {

return state;
};

export function hasSiteChanged( state ) {
return state.get( 'previousSiteId' ) !== state.get( 'currentSiteId' );
};

export function hasParams( state ) {
return !! state.get( 'lastParams' );
}
4 changes: 2 additions & 2 deletions shared/lib/themes/reducers/themes-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const defaultQueryState = fromJS( {
isFetchingNextPage: false
} );

export const initialState = query( fromJS( {
const initialState = query( fromJS( {
list: [],
nextId: 0,
query: {},
Expand Down Expand Up @@ -54,7 +54,7 @@ function isActionForLastPage( list, action ) {
action.themes.length === 0;
}

export const reducer = ( state = initialState, action ) => {
export default ( state = initialState, action ) => {
switch ( action.type ) {
case ThemeConstants.QUERY_THEMES:
return query( state, action.params );
Expand Down
9 changes: 2 additions & 7 deletions shared/lib/themes/reducers/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import transform from 'lodash/object/transform';
*/
import ThemeConstants from 'lib/themes/constants';

export const initialState = fromJS( {
const initialState = fromJS( {
themes: {},
currentSiteId: 0
} );
Expand All @@ -26,7 +26,7 @@ function setActiveTheme( themeId, themes ) {
.setIn( [ themeId, 'active' ], true );
}

export const reducer = ( state = initialState, action ) => {
export default( state = initialState, action ) => {
switch ( action.type ) {
case ThemeConstants.RECEIVE_THEMES:
const isNewSite = action.isJetpack && ( action.siteId !== state.get( 'currentSiteId' ) );
Expand All @@ -40,8 +40,3 @@ export const reducer = ( state = initialState, action ) => {
}
return state;
};

export function getThemeById( state, id ) {
const theme = state.getIn( [ 'themes', id ] );
return theme ? theme.toJS() : undefined;
}
14 changes: 0 additions & 14 deletions shared/lib/themes/stores/current-theme.js

This file was deleted.

15 changes: 0 additions & 15 deletions shared/lib/themes/stores/themes-last-query.js

This file was deleted.

15 changes: 0 additions & 15 deletions shared/lib/themes/stores/themes-list.js

This file was deleted.

12 changes: 0 additions & 12 deletions shared/lib/themes/stores/themes.js

This file was deleted.

38 changes: 0 additions & 38 deletions shared/lib/themes/test/current-theme-store.js

This file was deleted.

39 changes: 39 additions & 0 deletions shared/lib/themes/test/current-theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { expect } from 'chai';
import { createStore } from 'redux';

import ThemeConstants from '../constants';
import reducer from '../reducers/current-theme';

describe( 'current-theme', () => {
const SITE = { ID: 77203074 }; // dummy id

const actionReceiveCurrentTheme = {
type: ThemeConstants.RECEIVE_CURRENT_THEME,
themeId: 'twentyfifteen',
themeName: 'Twenty Fifteen',
site: SITE
};

let store;

function getCurrentTheme( siteId ) {
return store.getState().get( 'currentThemes' ).get( siteId );
}

beforeEach( () => {
store = createStore( reducer );
} );

describe( 'get()', () => {
beforeEach( () => {
store.dispatch( actionReceiveCurrentTheme );
} );

it( 'returns the current theme for the supplied site id', () => {
const currentTheme = getCurrentTheme( SITE.ID );

expect( currentTheme.id ).to.equal( 'twentyfifteen' );
expect( currentTheme.name ).to.equal( 'Twenty Fifteen' );
} );
} );
} );
Loading