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

Commit 9e2f3eb

Browse files
committed
Add reselect
1 parent 40a9f83 commit 9e2f3eb

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"react-redux": "^5.0.7",
4646
"redux": "^3.7.2",
4747
"redux-thunk": "^2.2.0",
48+
"reselect": "^3.0.1",
4849
"style-loader": "0.19.0",
4950
"superagent": "^3.8.2",
5051
"sw-precache-webpack-plugin": "0.11.4",

frontend/src/containers/app.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { connect } from 'react-redux';
33
import { loadApp, checkApiStatus } from '../actions/app';
4+
import * as AppSelectors from '../selectors/app';
45

56
// eslint-disable-next-line
67
import styles from './app.css';
@@ -54,7 +55,7 @@ class App extends React.Component {
5455

5556
export default connect((store, props) => {
5657
return {
57-
loaded: store.app.loaded,
58-
apiStatus: store.app.apiStatus
58+
loaded: AppSelectors.getLoadedStatus(store),
59+
apiStatus: AppSelectors.getApiStatus(store)
5960
};
6061
})(App);

frontend/src/reducers/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ACTION_TYPES } from '../constants/action-types';
22

33
const initialState = {
44
loaded: false,
5-
apiStatus: undefined
5+
apiStatus: null
66
};
77

88
export default function app(state = initialState, action) {

frontend/src/selectors/app.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { createSelector } from 'reselect';
2+
import _ from 'lodash';
3+
4+
export const getAppStore = store => store.app;
5+
6+
export const getApiStatus = createSelector(
7+
[getAppStore],
8+
(appStore) => {
9+
return _.get(appStore, 'apiStatus');
10+
}
11+
);
12+
13+
export const getLoadedStatus = createSelector(
14+
[getAppStore],
15+
(appStore) => {
16+
return _.get(appStore, 'loaded');
17+
}
18+
);

frontend/yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6070,6 +6070,10 @@ requires-port@1.0.x, requires-port@1.x.x, requires-port@~1.0.0:
60706070
version "1.0.0"
60716071
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
60726072

6073+
reselect@^3.0.1:
6074+
version "3.0.1"
6075+
resolved "https://registry.yarnpkg.com/reselect/-/reselect-3.0.1.tgz#efdaa98ea7451324d092b2b2163a6a1d7a9a2147"
6076+
60736077
resolve-cwd@^2.0.0:
60746078
version "2.0.0"
60756079
resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-2.0.0.tgz#00a9f7387556e27038eae232caa372a6a59b665a"

0 commit comments

Comments
 (0)