+60
-37
lines changedFilter options
+60
-37
lines changed Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
1
+
export function createReducer(initialState, fnMap) {
2
+
return (state = initialState, {type, payload}) => {
3
+
const handler = fnMap[type];
4
+
5
+
return handler ? handler(state, payload) : state;
6
+
};
7
+
}
8
+
9
+
export function reduceReducers(...reducers) {
10
+
return (previous, current) =>
11
+
reducers.reduce(
12
+
(p, r) => r(p, current),
13
+
previous
14
+
);
15
+
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
1
-
import React, {Component} from "react";
1
+
import {connect} from "react-redux";
2
2
3
3
import TabBar from "./TabBar";
4
4
5
-
export default class TabBarContainer extends Component {
6
-
constructor(props) {
7
-
super(props);
5
+
import {selectCurrentTab} from "./tabSelectors";
6
+
import {selectTab} from "./tabActions";
8
7
9
-
const {tabs = [{name : null}]} = props;
8
+
const mapState = (state) => {
9
+
const currentTab = selectCurrentTab(state);
10
10
11
-
const firstTab = tabs[0];
12
-
13
-
this.state = {
14
-
currentTab : firstTab.name
15
-
} ;
16
-
}
11
+
return {currentTab};
12
+
}
17
13
18
-
onTabClick = (name) => {
19
-
this.setState({currentTab : name});
20
-
}
14
+
const actions = {onTabClick : selectTab};
21
15
22
-
render() {
23
-
const {tabs, ...otherProps} = this.props;
24
-
const {currentTab} = this.state;
25
-
26
-
return (
27
-
<TabBar
28
-
{...otherProps}
29
-
currentTab={currentTab}
30
-
onTabClick={this.onTabClick}
31
-
tabs={tabs}
32
-
/>
33
-
)
34
-
}
35
-
}
16
+
export default connect(mapState, actions)(TabBar);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
1
+
import {TAB_SELECTED} from "./tabConstants";
2
+
3
+
export function selectTab(tabName) {
4
+
return {
5
+
type : TAB_SELECTED,
6
+
payload : {tabName},
7
+
};
8
+
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
+
export const TAB_SELECTED = "TAB_SELECTED";
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
1
+
import {createReducer} from "common/utils/reducerUtils";
2
+
3
+
import {TAB_SELECTED} from "./tabConstants";
4
+
5
+
const initialState = {
6
+
currentTab : "unitInfo",
7
+
};
8
+
9
+
export function selectTab(state, payload) {
10
+
return {
11
+
currentTab : payload.tabName,
12
+
};
13
+
}
14
+
15
+
export default createReducer(initialState, {
16
+
[TAB_SELECTED] : selectTab,
17
+
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
1
+
import {createSelector} from "reselect";
2
+
3
+
export const selectTabs = state => state.tabs;
4
+
5
+
export const selectCurrentTab = createSelector(
6
+
selectTabs,
7
+
tabs => tabs.currentTab
8
+
);
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
1
1
import {combineReducers} from "redux";
2
2
3
-
import testReducer from "./testReducer";
3
+
import tabReducer from "features/tabs/tabReducer";
4
4
5
5
const rootReducer = combineReducers({
6
-
test : testReducer,
6
+
tabs : tabReducer,
7
7
});
8
8
9
9
export default rootReducer;
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4