Skip to content

Commit

Permalink
add immutable and redux-immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
jokeyrhyme committed Feb 22, 2016
1 parent ead4b45 commit 9eb718d
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[version]
0.21.0
0.22.0

[ignore]
.*/bin/.*
Expand Down Expand Up @@ -48,4 +48,4 @@ suppress_type=$FixMe

suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(1[0-6]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*www[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(1[0-6]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*www[a-z,_]*\\)?)\\)? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
6 changes: 5 additions & 1 deletion config/_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@ const config = {
colors : true
},
compiler_vendor : [
'classnames',
'history',
'immutable',
'react',
'react-redux',
'react-router',
'react-router-redux',
'redux'
'redux',
'redux-immutable',
'redux-thunk'
],

// ----------------------------------
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"dev:nw": "npm run dev -- --nw",
"dev:no-debug": "npm run dev -- --no_debug",
"test": "better-npm-run test",
"posttest": "npm-run-all lint:fix",
"test:dev": "npm run test -- --watch",
"deploy": "better-npm-run deploy",
"flow:check": "babel-node bin/flow-check",
Expand Down Expand Up @@ -70,6 +71,7 @@
"debug": "^2.2.0",
"history": "^2.0.0",
"iconv-lite": "^0.4.13",
"immutable": "3.7.6",
"koa": "^2.0.0-alpha.3",
"koa-connect-history-api-fallback": "^0.3.0",
"koa-convert": "^1.2.0",
Expand All @@ -81,6 +83,7 @@
"react-router": "^2.0.0",
"react-router-redux": "^4.0.0-beta",
"redux": "^3.0.0",
"redux-immutable": "3.0.5",
"redux-thunk": "^1.0.0",
"url": "^0.11.0",
"yargs": "^4.1.0"
Expand Down Expand Up @@ -134,6 +137,7 @@
"mocha": "^2.2.5",
"node-sass": "^3.3.3",
"nodemon": "^1.8.1",
"npm-run-all": "1.5.1",
"phantomjs-polyfill": "0.0.1",
"phantomjs-prebuilt": "^2.1.3",
"postcss-loader": "^0.8.0",
Expand Down
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const browserHistory = useRouterHistory(createBrowserHistory)({
basename: __BASENAME__
});
const history = syncHistoryWithStore(browserHistory, store, {
selectLocationState: (state) => state.router
selectLocationState: (state) => state.get('router')
});

// Now that we have the Redux store, we can create our routes. We provide
Expand Down
4 changes: 3 additions & 1 deletion src/redux/configureStore.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Map } from 'immutable';
import { applyMiddleware, compose, createStore } from 'redux';
import thunk from 'redux-thunk';

import rootReducer from './rootReducer';

export default function configureStore (initialState = {}) {
export default function configureStore (initialState = new Map()) {
// Compose final middleware and use devtools in debug environment
let middleware = applyMiddleware(thunk);
if (__DEBUG__) {
Expand Down
2 changes: 1 addition & 1 deletion src/redux/modules/counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const ACTION_HANDLERS = {
// Reducer
// ------------------------------------
const initialState = 0;
export default function counterReducer (state: number = initialState, action: Action): number {
export function counterReducer (state: number = initialState, action: Action): number {
const handler = ACTION_HANDLERS[action.type];

return handler ? handler(state, action) : state;
Expand Down
18 changes: 18 additions & 0 deletions src/redux/modules/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Immutable from 'immutable';
import { UPDATE_LOCATION } from 'react-router-redux';

let initialState;

initialState = Immutable.fromJS({
location: undefined
});

// custom immutable-friendly reducer: https://github.com/gajus/redux-immutable
export const routerReducer = (state = initialState, action) => {
if (action.type === UPDATE_LOCATION) {
return state.merge({
location: action.payload
});
}
return state;
};
7 changes: 4 additions & 3 deletions src/redux/rootReducer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { combineReducers } from 'redux';
import { routerReducer as router } from 'react-router-redux';
import counter from './modules/counter';
import { combineReducers } from 'redux-immutable';

import { routerReducer as router } from './modules/router';
import { counterReducer as counter } from './modules/counter';

export default combineReducers({
counter,
Expand Down
5 changes: 3 additions & 2 deletions src/views/HomeView/HomeView.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* @flow */
import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import { increment, doubleAsync } from '../../redux/modules/counter';
import classnames from 'classnames';

import { increment, doubleAsync } from '../../redux/modules/counter';
import DuckImage from './Duck.jpg';
import classes from './HomeView.css';

Expand Down Expand Up @@ -58,7 +59,7 @@ export class HomeView extends React.Component<void, Props, void> {
}

const mapStateToProps = (state) => ({
counter: state.counter
counter: state.get('counter')
});
export default connect((mapStateToProps), {
increment: () => increment(1),
Expand Down
2 changes: 1 addition & 1 deletion tests/redux/modules/counter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
COUNTER_INCREMENT,
increment,
doubleAsync,
default as counterReducer
counterReducer
} from 'redux/modules/counter';

describe('(Redux Module) Counter', function () {
Expand Down

0 comments on commit 9eb718d

Please sign in to comment.