Skip to content
This repository was archived by the owner on Mar 22, 2020. It is now read-only.

Commit 03f40b8

Browse files
committed
Add prettier config; Upgrade deps; Remove immutable;
1 parent e1ab686 commit 03f40b8

25 files changed

+9449
-13558
lines changed

.prettierignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
build/
2+
node_modules/
3+
internals/generators/
4+
internals/scripts/
5+
package-lock.json
6+
yarn.lock
7+
package.json

.prettierrc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"printWidth": 80,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": true,
6+
"singleQuote": true,
7+
"trailingComma": "all"
8+
}

.vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"workbench.colorCustomizations": {
3+
"tab.unfocusedActiveBorder": "#fff0"
4+
}
5+
}

app/app.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import '@babel/polyfill';
1212
import React from 'react';
1313
import ReactDOM from 'react-dom';
1414
import { Provider } from 'react-redux';
15-
import { ConnectedRouter } from 'react-router-redux';
15+
import { ConnectedRouter } from 'connected-react-router';
1616
import FontFaceObserver from 'fontfaceobserver';
17-
import createHistory from 'history/createBrowserHistory';
17+
import history from 'utils/history';
1818
import 'sanitize.css/sanitize.css';
1919

2020
// Import root app
@@ -43,18 +43,15 @@ openSansObserver.load().then(() => {
4343

4444
// Create redux store with history
4545
const initialState = {};
46-
const history = createHistory();
4746
const store = configureStore(initialState, history);
4847
const MOUNT_NODE = document.getElementById('app');
4948

5049
const render = () => {
5150
ReactDOM.render(
5251
<Provider store={store}>
53-
{/* <LanguageProvider messages={messages}> */}
5452
<ConnectedRouter history={history}>
5553
<App />
5654
</ConnectedRouter>
57-
{/* </LanguageProvider> */}
5855
</Provider>,
5956
MOUNT_NODE
6057
);

app/components/List/List.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const List = ({ component, items }) => {
2626
};
2727

2828
List.propTypes = {
29-
component: PropTypes.func.isRequired,
29+
component: PropTypes.elementType.isRequired,
3030
items: PropTypes.array,
3131
};
3232

app/configureStore.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
*/
44

55
import { createStore, applyMiddleware, compose } from 'redux';
6-
import { fromJS } from 'immutable';
7-
import { routerMiddleware } from 'react-router-redux';
6+
import { routerMiddleware } from 'connected-react-router';
87
import createSagaMiddleware from 'redux-saga';
98
import createReducer from './reducers';
109

@@ -29,14 +28,13 @@ export default function configureStore(initialState = {}, history) {
2928
: compose;
3029
/* eslint-enable */
3130

32-
const store = createStore(createReducer(), fromJS(initialState), composeEnhancers(...enhancers));
31+
const store = createStore(createReducer(), initialState, composeEnhancers(...enhancers));
3332

3433
// Extensions
3534
store.runSaga = sagaMiddleware.run;
3635
store.injectedReducers = {}; // Reducer registry
3736
store.injectedSagas = {}; // Saga registry
3837

39-
// Make reducers hot reloadable, see http://mxs.is/googmo
4038
/* istanbul ignore next */
4139
if (module.hot) {
4240
module.hot.accept('./reducers', () => {

app/containers/App/reducer.js

+30-35
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,44 @@
1-
/*
2-
* AppReducer
3-
*
4-
* The reducer takes care of our data. Using actions, we can change our
5-
* application state.
6-
* To add a new action, add it to the switch statement in the reducer function
7-
*
8-
* Example:
9-
* case YOUR_ACTION_CONSTANT:
10-
* return state.set('yourStateVariable', true);
11-
*/
12-
13-
import { fromJS } from 'immutable';
14-
15-
import {
16-
LOAD_REPOS_SUCCESS,
17-
LOAD_REPOS,
18-
LOAD_REPOS_ERROR,
19-
} from './constants';
1+
import { LOAD_REPOS_SUCCESS, LOAD_REPOS, LOAD_REPOS_ERROR } from './constants';
202

213
// The initial state of the App
22-
const initialState = fromJS({
4+
export const initialState = {
235
loading: false,
246
error: false,
257
currentUser: false,
268
userData: {
279
repositories: false,
2810
},
29-
});
11+
};
3012

3113
function appReducer(state = initialState, action) {
3214
switch (action.type) {
33-
case LOAD_REPOS:
34-
return state
35-
.set('loading', true)
36-
.set('error', false)
37-
.setIn(['userData', 'repositories'], false);
38-
case LOAD_REPOS_SUCCESS:
39-
return state
40-
.setIn(['userData', 'repositories'], action.repos)
41-
.set('loading', false)
42-
.set('currentUser', action.username);
43-
case LOAD_REPOS_ERROR:
44-
return state
45-
.set('error', action.error)
46-
.set('loading', false);
15+
case LOAD_REPOS: {
16+
const newState = {
17+
...state,
18+
loading: true,
19+
error: false,
20+
userData: {
21+
repositories: false,
22+
},
23+
};
24+
25+
return newState;
26+
}
27+
case LOAD_REPOS_SUCCESS: {
28+
const newState = {
29+
...state,
30+
loading: false,
31+
userData: {
32+
repositories: action.repos,
33+
},
34+
currentUser: action.username,
35+
};
36+
return newState;
37+
}
38+
39+
case LOAD_REPOS_ERROR: {
40+
return { ...state, error: action.error, loading: false };
41+
}
4742
default:
4843
return state;
4944
}

app/containers/App/selectors.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,33 @@
1-
/**
2-
* The global state selectors
3-
*/
4-
51
import { createSelector } from 'reselect';
2+
import { initialState } from './reducer';
63

7-
const selectGlobal = (state) => state.get('global');
4+
const selectGlobal = (state) => state.global || initialState;
85

9-
const selectRoute = (state) => state.get('route');
6+
const selectRoute = (state) => state.router;
107

118
const makeSelectCurrentUser = () => createSelector(
129
selectGlobal,
13-
(globalState) => globalState.get('currentUser')
10+
(globalState) => globalState.currentUser
1411
);
1512

1613
const makeSelectLoading = () => createSelector(
1714
selectGlobal,
18-
(globalState) => globalState.get('loading')
15+
(globalState) => globalState.loading
1916
);
2017

2118
const makeSelectError = () => createSelector(
2219
selectGlobal,
23-
(globalState) => globalState.get('error')
20+
(globalState) => globalState.error
2421
);
2522

2623
const makeSelectRepos = () => createSelector(
2724
selectGlobal,
28-
(globalState) => globalState.getIn(['userData', 'repositories'])
25+
(globalState) => globalState.userData.repositories
2926
);
3027

3128
const makeSelectLocation = () => createSelector(
3229
selectRoute,
33-
(routeState) => routeState.get('location').toJS()
30+
(routeState) => routeState.location
3431
);
3532

3633
export {
+34-28
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
1-
import { fromJS } from 'immutable';
2-
31
import appReducer from '../reducer';
4-
import {
5-
loadRepos,
6-
reposLoaded,
7-
repoLoadingError,
8-
} from '../actions';
2+
import { loadRepos, reposLoaded, repoLoadingError } from '../actions';
93

104
describe('appReducer', () => {
115
let state;
126
beforeEach(() => {
13-
state = fromJS({
7+
state = {
148
loading: false,
159
error: false,
1610
currentUser: false,
17-
userData: fromJS({
11+
userData: {
1812
repositories: false,
19-
}),
20-
});
13+
},
14+
};
2115
});
2216

2317
it('should return the initial state', () => {
@@ -26,35 +20,47 @@ describe('appReducer', () => {
2620
});
2721

2822
it('should handle the loadRepos action correctly', () => {
29-
const expectedResult = state
30-
.set('loading', true)
31-
.set('error', false)
32-
.setIn(['userData', 'repositories'], false);
33-
23+
const expectedResult = {
24+
...state,
25+
loading: true,
26+
error: false,
27+
userData: { repositories: false },
28+
};
3429
expect(appReducer(state, loadRepos())).toEqual(expectedResult);
3530
});
3631

3732
it('should handle the reposLoaded action correctly', () => {
38-
const fixture = [{
39-
name: 'My Repo',
40-
}];
33+
const fixture = [
34+
{
35+
name: 'My Repo',
36+
},
37+
];
4138
const username = 'test';
42-
const expectedResult = state
43-
.setIn(['userData', 'repositories'], fixture)
44-
.set('loading', false)
45-
.set('currentUser', username);
39+
const expectedResult = {
40+
...state,
41+
loading: false,
42+
currentUser: username,
43+
userData: { repositories: fixture },
44+
};
4645

47-
expect(appReducer(state, reposLoaded(fixture, username))).toEqual(expectedResult);
46+
expect(appReducer(state, reposLoaded(fixture, username))).toEqual(
47+
expectedResult,
48+
);
4849
});
4950

5051
it('should handle the repoLoadingError action correctly', () => {
5152
const fixture = {
5253
msg: 'Not found',
5354
};
54-
const expectedResult = state
55-
.set('error', fixture)
56-
.set('loading', false);
5755

58-
expect(appReducer(state, repoLoadingError(fixture))).toEqual(expectedResult);
56+
const expectedResult = {
57+
...state,
58+
error: fixture,
59+
loading: false,
60+
};
61+
62+
expect(appReducer(state, repoLoadingError(fixture))).toEqual(
63+
expectedResult,
64+
);
5965
});
6066
});

0 commit comments

Comments
 (0)