Skip to content

Commit 013c6e0

Browse files
committed
fixes for review
1 parent e51db47 commit 013c6e0

File tree

15 files changed

+37
-78
lines changed

15 files changed

+37
-78
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
{}

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ exports[`Index renders correctly when loaded 1`] = `
3232
renderRow={[Function]}
3333
scrollEventThrottle={50}
3434
scrollRenderAheadDistance={1000}
35-
stickyHeaderIndices={Array []}
36-
style={Object {}}>
35+
stickyHeaderIndices={Array []}>
3736
<View
3837
style={
3938
Object {
@@ -64,7 +63,7 @@ exports[`Index renders correctly when loaded 1`] = `
6463
"textAlign": "center",
6564
}
6665
}>
67-
Justin
66+
Alexey
6867
</Text>
6968
<Text
7069
accessible={true}
@@ -77,7 +76,7 @@ exports[`Index renders correctly when loaded 1`] = `
7776
"marginHorizontal": 10,
7877
}
7978
}>
80-
Another random comment
79+
Just some random comment
8180
</Text>
8281
</View>
8382
<View
@@ -110,7 +109,7 @@ exports[`Index renders correctly when loaded 1`] = `
110109
"textAlign": "center",
111110
}
112111
}>
113-
Alexey
112+
Justin
114113
</Text>
115114
<Text
116115
accessible={true}
@@ -123,7 +122,7 @@ exports[`Index renders correctly when loaded 1`] = `
123122
"marginHorizontal": 10,
124123
}
125124
}>
126-
Just some random comment
125+
Another random comment
127126
</Text>
128127
</View>
129128
</ScrollView>
@@ -138,9 +137,8 @@ exports[`Index renders correctly when loaded 1`] = `
138137
"justifyContent": "center",
139138
}
140139
}>
141-
<TouchableHighlight
142-
activeOpacity={0.85}
143-
onPress={[Function]}
140+
<View
141+
onPress={undefined}
144142
style={
145143
Array [
146144
Object {
@@ -192,7 +190,7 @@ exports[`Index renders correctly when loaded 1`] = `
192190
}>
193191
194192
</Text>
195-
</TouchableHighlight>
193+
</View>
196194
</View>
197195
</View>
198196
`;
@@ -231,8 +229,7 @@ exports[`Index renders correctly when loading 1`] = `
231229
renderRow={[Function]}
232230
scrollEventThrottle={50}
233231
scrollRenderAheadDistance={1000}
234-
stickyHeaderIndices={Array []}
235-
style={Object {}} />
232+
stickyHeaderIndices={Array []} />
236233
<View
237234
style={
238235
Object {
@@ -244,9 +241,8 @@ exports[`Index renders correctly when loading 1`] = `
244241
"justifyContent": "center",
245242
}
246243
}>
247-
<TouchableHighlight
248-
activeOpacity={0.85}
249-
onPress={[Function]}
244+
<View
245+
onPress={undefined}
250246
style={
251247
Array [
252248
Object {
@@ -298,7 +294,7 @@ exports[`Index renders correctly when loading 1`] = `
298294
}>
299295
300296
</Text>
301-
</TouchableHighlight>
297+
</View>
302298
</View>
303299
</View>
304300
`;

mobile/ReactNativeTutorial/__tests__/bundles/comments/effects/__snapshots__/createComment.js.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ exports[`createComment creates a comment in the store and sends request to api 1
22
Array [
33
Object {
44
"entities": Object {
5-
"temp0": Object {
5+
"temp:0": Object {
66
"author": "Alexey",
7-
"id": "temp0",
7+
"id": "temp:0",
88
"text": "Random comment",
99
},
1010
},
@@ -19,15 +19,15 @@ Array [
1919
"args": Array [
2020
Object {
2121
"author": "Alexey",
22-
"id": "temp0",
22+
"id": "temp:0",
2323
"text": "Random comment",
2424
},
2525
],
2626
"name": "postComment",
2727
"type": "CALL",
2828
},
2929
Object {
30-
"id": "temp0",
30+
"id": "temp:0",
3131
"type": "COMMENTS_STORE:REMOVE",
3232
},
3333
Object {

mobile/ReactNativeTutorial/__tests__/bundles/comments/effects/__snapshots__/fetch.js.snap

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ Array [
99
"name": "fetchComments",
1010
"type": "CALL",
1111
},
12-
Object {
13-
"args": Array [
14-
[Error: Invalid Json],
15-
],
16-
"name": "bound log",
17-
"type": "CALL",
18-
},
1912
Object {
2013
"args": Array [
2114
"Error",

mobile/ReactNativeTutorial/app/api/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import _ from 'lodash/fp';
2-
import { normalize, Schema, arrayOf } from 'normalizr';
2+
import { normalize } from 'normalizr';
3+
import { commentSchema, commentsSchema } from './schemas';
34

45
// You can use localhost for development, but only on iOS. Android emulator is considered
56
// a standalone machine with it's own localhost. Workaround is to specify the actual
@@ -27,13 +28,11 @@ const postRequest = async (url, payload) => apiRequest(url, 'POST', payload);
2728
export const fetchComments = async () => {
2829
const response = await getRequest('comments.json');
2930
const camelizedResponse = _.mapKeys(_.camelCase, response);
30-
const commentSchema = new Schema('comments');
31-
return normalize(camelizedResponse, { comments: arrayOf(commentSchema) });
31+
return normalize(camelizedResponse, { comments: commentsSchema });
3232
};
3333

3434
export const postComment = async (payload) => {
3535
const response = await postRequest('comments.json', { comment: payload });
3636
const camelizedResponse = _.mapKeys(_.camelCase, response);
37-
const commentSchema = new Schema('comments');
3837
return normalize(camelizedResponse, commentSchema);
3938
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { Schema, arrayOf } from 'normalizr';
2+
export const commentSchema = new Schema('comments');
3+
export const commentsSchema = arrayOf(commentSchema);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const Footer = () => (
1313
reverse
1414
name="add"
1515
color="#f50"
16-
onPress={() => Actions.commentsAdd()}
16+
onPress={Actions.commentsAdd}
1717
/>
1818
</View>
1919
);

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
11
// @flow
22
import React from 'react';
33
import { ListView, RefreshControl } from 'react-native';
4-
import _ from 'lodash/fp';
54
import type { IndexPropsType } from '../../../containers/Index';
65
import Item from './Item/Item';
76

8-
import styles from './ListStyle';
9-
107
type PropsType = IndexPropsType;
118

129
const List = (props: PropsType) => {
13-
const data = _.compose(
14-
_.reverse,
15-
_.sortBy(_.get('id')),
16-
_.values
17-
)(props.comments);
1810
const dataSource = new ListView.DataSource({ rowHasChanged: (r1: any, r2: any) => r1 !== r2 })
19-
.cloneWithRows(data);
11+
.cloneWithRows(props.comments || []);
2012
return (
2113
<ListView
2214
enableEmptySections
23-
style={styles.container}
2415
dataSource={dataSource}
2516
renderRow={(item: any) => <Item {...item} />}
2617
refreshControl={

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

Lines changed: 0 additions & 8 deletions
This file was deleted.

mobile/ReactNativeTutorial/app/reducers/commentFormReducer.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ export const initialState = fromJS({
99

1010
const update = (state, action) => state.merge(action.payload);
1111

12-
export default (state, action) => {
13-
if (!state) {
14-
return initialState;
15-
}
16-
12+
export default (state = initialState, action) => {
1713
switch (action.type) {
1814
case UPDATE:
1915
return update(state, action);

mobile/ReactNativeTutorial/app/reducers/commentsStoreReducer.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ const create = (state, action) => state.merge(action.entities);
1414
const remove = (state, action) => state.delete(action.id);
1515
const setLoading = (state, action) => state.setIn(['meta', 'loading'], action.loading);
1616

17-
export default (state, action) => {
18-
if (!state) {
19-
return initialState;
20-
}
21-
17+
export default (state = initialState, action) => {
2218
switch (action.type) {
2319
case CREATE:
2420
return create(state, action);

mobile/ReactNativeTutorial/app/selectors/commentsPropsSelector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import commentsStoreSelector from './commentsStoreSelector';
55
export default createSelector(
66
commentsStoreSelector,
77
commentsStore => Map({
8-
comments: commentsStore.delete('meta').valueSeq().sort((a, b) => b.get('id') - a.get('id')),
8+
comments: commentsStore.delete('meta').valueSeq().sortBy(x => x.get('id')).reverse(),
99
meta: commentsStore.get('meta'),
1010
})
1111
);

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ import Index from '../../bundles/comments/containers/Index';
66

77
import styles from './RouterStyle';
88

9-
const reducerCreate = params => {
10-
const defaultReducer = Reducer(params);
11-
return (state, action) => {
12-
console.log('Executing navigation action', action);
13-
return defaultReducer(state, action);
14-
};
9+
const reducerCreate = params => (state, action) => {
10+
console.log('Executing navigation action', action);
11+
return Reducer(params)(state, action);
1512
};
1613

1714
export default () => (

mobile/ReactNativeTutorial/app/setup/store.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,5 @@ import effectsMiddleware from 'redux-thunk-effects';
33
import loggerMiddleware from './loggerMiddleware';
44
import appReducer, { initialState } from '../reducers';
55

6-
let composedStore;
7-
if (__DEV__) {
8-
composedStore = compose(applyMiddleware(loggerMiddleware, effectsMiddleware));
9-
} else {
10-
composedStore = compose(applyMiddleware(effectsMiddleware));
11-
}
12-
const store = composedStore(createStore)(appReducer, initialState);
13-
14-
export default store;
6+
const middlewares = __DEV__ ? [effectsMiddleware, loggerMiddleware] : [effectsMiddleware];
7+
export default createStore(appReducer, initialState, applyMiddleware(...middlewares));

mobile/ReactNativeTutorial/app/utils/redux.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/* eslint-disable import/prefer-default-export */
22
import _ from 'lodash/fp';
33

4+
// The format for tempId (id for temporary object not stored on the remote server yet)
5+
// is temp{n}, e.g. temp0, temp1, etc.
6+
// This function gets the maximum tempId, e.g. temp10 and returns then next id, e.g. temp11
47
export const getNewId = (store) => {
58
const tempPrefix = 'temp:';
69
const tempRegex = new RegExp(`^${tempPrefix}`);
@@ -10,5 +13,5 @@ export const getNewId = (store) => {
1013
.map(key => parseInt(key.substring(tempPrefix.length), 10))
1114
.max();
1215
const newId = _.isNil(maxId) ? 0 : maxId + 1;
13-
return `temp${newId}`;
16+
return `temp:${newId}`;
1417
};

0 commit comments

Comments
 (0)