Skip to content

Commit 029623b

Browse files
committed
refactored hocs into containers
1 parent ae74a79 commit 029623b

File tree

7 files changed

+142
-30
lines changed

7 files changed

+142
-30
lines changed

mobile/ReactNativeTutorial/__tests__/bundles/comments/components/__snapshots__/Index.js.snap

+106
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,109 @@ exports[`test renders correctly 1`] = `
103103
</View>
104104
</View>
105105
`;
106+
107+
exports[`test renders correctly 2`] = `
108+
<View
109+
style={
110+
Object {
111+
"flex": 1,
112+
}
113+
}>
114+
<ScrollView
115+
dataSource={
116+
ListViewDataSource {
117+
"items": 0,
118+
}
119+
}
120+
enableEmptySections={true}
121+
initialListSize={10}
122+
onContentSizeChange={[Function]}
123+
onEndReachedThreshold={1000}
124+
onKeyboardDidHide={undefined}
125+
onKeyboardDidShow={undefined}
126+
onKeyboardWillHide={undefined}
127+
onKeyboardWillShow={undefined}
128+
onLayout={[Function]}
129+
onScroll={[Function]}
130+
pageSize={1}
131+
refreshControl={
132+
<RefreshControl
133+
onRefresh={[Function]}
134+
refreshing={true}
135+
tintColor="#4641B5" />
136+
}
137+
removeClippedSubviews={true}
138+
renderRow={[Function]}
139+
scrollEventThrottle={50}
140+
scrollRenderAheadDistance={1000}
141+
stickyHeaderIndices={Array []}
142+
style={Object {}} />
143+
<View
144+
style={
145+
Object {
146+
"alignItems": "center",
147+
"backgroundColor": "#EFEFF2",
148+
"borderTopColor": "#D2D2D2",
149+
"borderTopWidth": 1,
150+
"height": 70,
151+
"justifyContent": "center",
152+
}
153+
}>
154+
<TouchableHighlight
155+
activeOpacity={0.85}
156+
onPress={[Function]}
157+
style={
158+
Array [
159+
Object {
160+
"margin": 7,
161+
},
162+
Object {
163+
"borderRadius": 28,
164+
"height": 52,
165+
"width": 52,
166+
},
167+
Object {
168+
"shadowColor": "rgba(0,0,0, .4)",
169+
"shadowOffset": Object {
170+
"height": 1,
171+
"width": 1,
172+
},
173+
"shadowOpacity": 1,
174+
"shadowRadius": 1,
175+
},
176+
Object {
177+
"alignItems": "center",
178+
"backgroundColor": "#f50",
179+
"justifyContent": "center",
180+
},
181+
undefined,
182+
]
183+
}
184+
underlayColor="#f50">
185+
<Text
186+
accessible={true}
187+
allowFontScaling={false}
188+
ellipsizeMode="tail"
189+
style={
190+
Array [
191+
Object {
192+
"color": "white",
193+
"fontFamily": "Material Icons",
194+
"fontSize": 24,
195+
"fontStyle": "normal",
196+
"fontWeight": "normal",
197+
},
198+
Array [
199+
Object {
200+
"backgroundColor": "transparent",
201+
},
202+
undefined,
203+
],
204+
]
205+
}>
206+
207+
</Text>
208+
</TouchableHighlight>
209+
</View>
210+
</View>
211+
`;

mobile/ReactNativeTutorial/app/bundles/comments/components/Add/Add.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import React from 'react';
33
import { View } from 'react-native';
44
import { FormLabel, FormInput, Button } from 'react-native-elements';
55

6-
import withAddProps from '../../hocs/withAddProps';
7-
import type { AddPropsType } from '../../hocs/withAddProps';
6+
import type { AddPropsType } from '../../containers/Add';
87

98
import styles from './AddStyle';
109

@@ -26,4 +25,4 @@ const Add = (props: PropsType) => (
2625
</View>
2726
);
2827

29-
export default withAddProps(Add);
28+
export default Add;

mobile/ReactNativeTutorial/app/bundles/comments/components/Index/Index.js

+8-20
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,17 @@ import React from 'react';
33
import { View } from 'react-native';
44
import List from './List/List';
55
import Footer from './Footer/Footer';
6-
import withIndexProps from '../../hocs/withIndexProps';
7-
import type { IndexPropsType } from '../../hocs/withIndexProps';
6+
import type { IndexPropsType } from '../../containers/Index';
87

98
import styles from './IndexStyle';
109

1110
type PropsType = IndexPropsType;
1211

13-
class Index extends React.Component {
12+
const Index = (props: PropsType) => (
13+
<View style={styles.container}>
14+
<List {...props} />
15+
<Footer />
16+
</View>
17+
);
1418

15-
props: PropsType;
16-
17-
componentDidMount() {
18-
this.props.actions.fetch();
19-
}
20-
21-
render() {
22-
return (
23-
<View style={styles.container}>
24-
<List {...this.props} />
25-
<Footer />
26-
</View>
27-
);
28-
}
29-
}
30-
31-
export default withIndexProps(Index);
19+
export default Index;

mobile/ReactNativeTutorial/app/bundles/comments/components/Index/List/List.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import React from 'react';
33
import { ListView, RefreshControl } from 'react-native';
44
import _ from 'lodash/fp';
5-
import type { IndexPropsType } from '../../../hocs/withIndexProps';
5+
import type { IndexPropsType } from '../../../containers/Index';
66
import Item from './Item/Item';
77

88
import styles from './ListStyle';

mobile/ReactNativeTutorial/app/bundles/comments/hocs/withAddProps.js renamed to mobile/ReactNativeTutorial/app/bundles/comments/containers/Add.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
// @flow
2+
import React from 'react';
23
import { bindActionCreators } from 'redux';
34
import { connect } from 'react-redux';
45
import { createSelector } from 'reselect';
56

67
import commentFormSelector from '../../../selectors/commentFormSelector';
78
import { actions } from '../sagas';
9+
import Add from '../components/Add/Add';
810

911
export type AddPropsType = {
1012
author?: string,
@@ -25,5 +27,6 @@ const mapDispatchToProps = (dispatch: Function) => ({
2527
actions: bindActionCreators(actions, dispatch),
2628
});
2729

28-
export default (Component: ReactClass<AddPropsType>): ReactClass<{}> =>
29-
connect(mapStateToProps, mapDispatchToProps)(Component);
30+
const AddContainer = (props: AddPropsType) => <Add {...props} />;
31+
32+
export default connect(mapStateToProps, mapDispatchToProps)(AddContainer);

mobile/ReactNativeTutorial/app/bundles/comments/hocs/withIndexProps.js renamed to mobile/ReactNativeTutorial/app/bundles/comments/containers/Index.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
/* eslint-disable react/no-unused-prop-types */
12
// @flow
3+
import React from 'react';
24
import { bindActionCreators } from 'redux';
35
import { connect } from 'react-redux';
46
import { createSelector } from 'reselect';
57

68
import commentsStoreSelector from '../../../selectors/commentsStoreSelector';
79
import { actions } from '../sagas';
810

11+
import Index from '../components/Index/Index';
12+
913
type CommentType = {
1014
author?: string,
1115
text?: string,
@@ -23,6 +27,19 @@ export type IndexPropsType = {
2327
}
2428
}
2529

30+
class IndexContainer extends React.Component {
31+
32+
props: IndexPropsType;
33+
34+
componentDidMount() {
35+
this.props.actions.fetch();
36+
}
37+
38+
render() {
39+
return <Index {...this.props} />;
40+
}
41+
}
42+
2643
const mapStateToProps = createSelector(
2744
commentsStoreSelector,
2845
(commentsStore: any) => ({
@@ -35,5 +52,4 @@ const mapDispatchToProps = (dispatch: Function) => ({
3552
actions: bindActionCreators(actions, dispatch),
3653
});
3754

38-
export default (Component: ReactClass<IndexPropsType>): ReactClass<{}> =>
39-
connect(mapStateToProps, mapDispatchToProps)(Component);
55+
export default connect(mapStateToProps, mapDispatchToProps)(IndexContainer);

mobile/ReactNativeTutorial/app/setup/Router/Router.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { Scene, Router, Reducer } from 'react-native-router-flux';
3-
import Add from '../../bundles/comments/components/Add/Add';
4-
import Index from '../../bundles/comments/components/Index/Index';
3+
import Add from '../../bundles/comments/containers/Add';
4+
import Index from '../../bundles/comments/containers/Index';
55

66
import styles from './RouterStyle';
77

0 commit comments

Comments
 (0)