Skip to content

Commit

Permalink
Remove @@init actionType, move state initialization to lib/createReducer
Browse files Browse the repository at this point in the history
  • Loading branch information
quangbuule committed Jun 28, 2015
1 parent b92c909 commit 920a118
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/js/consts/ActionTypes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import keyMirror from 'react/lib/keyMirror';

export default {
init: '@@INIT',

Repo: keyMirror({
getByUsername: null,
Expand Down
6 changes: 6 additions & 0 deletions src/js/lib/createReducer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import Immutable, { Map, List } from 'immutable';

export default function createReducer(intialState, handlers) {
return (state = intialState, action) => {
if (!Map.isMap(state) && !List.isList(state)) {
intialState = Immutable.fromJS(intialState);
}

const handler = handlers[action.type];

if (!handler) {
Expand Down
7 changes: 0 additions & 7 deletions src/js/reducers/Repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ import createReducer from '../lib/createReducer';
const initialState = Immutable.fromJS({});

export default createReducer(initialState, {
/**
* This will receive and initialize state from __INITIAL_STATE__.Repo
*/
[ActionTypes.init](state) {
return Immutable.fromJS(state);
},

/**
* Because github use header for pagination, so we should receive res from
* api call and store res to store's state also.
Expand Down
3 changes: 0 additions & 3 deletions src/js/reducers/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import createReducer from '../lib/createReducer';
const initialState = Immutable.fromJS({});

export default createReducer(initialState, {
[ActionTypes.init](state) {
return Immutable.fromJS(state);
},

[ActionTypes.User.getOneByUsername](state, { username, res }) {
return state.merge({
Expand Down

0 comments on commit 920a118

Please sign in to comment.