-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move state management to Redux reducer (#694)
- Loading branch information
Aaron Carlino
authored
Oct 17, 2018
1 parent
e31f56a
commit 978922b
Showing
8 changed files
with
87 additions
and
10 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
TABS_ACTIVATE_TAB: 'TABS_ACTIVATE_TAB', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import ACTION_TYPES from './TabsActionTypes'; | ||
|
||
/** | ||
* Sets the active tab | ||
* | ||
* @param {String} fieldId ID for field | ||
* @param {String} name of the tab | ||
* @return {Object} | ||
*/ | ||
export function activateTab(fieldId, tab) { | ||
return { | ||
type: ACTION_TYPES.TABS_ACTIVATE_TAB, | ||
payload: { fieldId, tab }, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import deepFreeze from 'deep-freeze-strict'; | ||
import getFieldReducer from 'lib/reduxFieldReducer'; | ||
import ACTION_TYPES from './TabsActionTypes'; | ||
|
||
/** | ||
* Default state | ||
*/ | ||
const initialState = deepFreeze({ fields: {} }); | ||
|
||
/** | ||
* Default object for an empty field state | ||
*/ | ||
const initialFieldState = deepFreeze({ | ||
activeTab: null | ||
}); | ||
|
||
export default function tabsReducer(state = initialState, action = null) { | ||
// Get field reducer | ||
const reduceField = getFieldReducer(state, action, initialFieldState); | ||
|
||
// Actions | ||
switch (action.type) { | ||
case ACTION_TYPES.TABS_ACTIVATE_TAB: { | ||
return reduceField(() => ({ activeTab: action.payload.tab })); | ||
} | ||
|
||
default: | ||
return state; | ||
} | ||
} |