Skip to content

Commit

Permalink
refactor: adjust code format based on eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
wellyshen committed Apr 1, 2020
1 parent 08bf3bf commit 890fee0
Show file tree
Hide file tree
Showing 21 changed files with 98 additions and 97 deletions.
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Allows you to precompile ES6 syntax
require('@babel/register')({
plugins: ['dynamic-import-node']
plugins: ['dynamic-import-node'],
});

// Setup global variables for server-side
Expand Down
4 changes: 2 additions & 2 deletions postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
module.exports = {
plugins: [
// Add "-ms-" prefixes for Grid Layout
require('autoprefixer')({ grid: true })
]
require('autoprefixer')({ grid: true }),
],
};
2 changes: 1 addition & 1 deletion src/actions/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
AppState,
USER_REQUESTING,
USER_SUCCESS,
USER_FAILURE
USER_FAILURE,
} from '../types';

const API_URL = 'https://jsonplaceholder.typicode.com/users';
Expand Down
2 changes: 1 addition & 1 deletion src/actions/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
AppState,
USERS_REQUESTING,
USERS_SUCCESS,
USERS_FAILURE
USERS_FAILURE,
} from '../types';

const API_URL = 'https://jsonplaceholder.typicode.com/users';
Expand Down
8 changes: 4 additions & 4 deletions src/app/__tests__/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('<App />', () => {
default: (): void => null,
subscribe: (): void => null,
dispatch: (): void => null,
getState: () => ({ home: (): void => null })
getState: () => ({ home: (): void => null }),
};
const fakeRoute = {
routes: [
Expand All @@ -22,9 +22,9 @@ describe('<App />', () => {
<div>
<h1>Welcome Home!</h1>
</div>
)
}
]
),
},
],
};

const tree = renderer
Expand Down
8 changes: 4 additions & 4 deletions src/config/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export default {
meta: [
{
name: 'description',
content: 'The best react universal starter boilerplate in the world.'
}
]
}
content: 'The best react universal starter boilerplate in the world.',
},
],
},
};
4 changes: 2 additions & 2 deletions src/pages/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ export const Home = ({ readyStatus, list, fetchUsersIfNeeded }: Props) => {

const mapStateToProps = ({ home: { readyStatus, list } }: AppState) => ({
readyStatus,
list
list,
});

const mapDispatchToProps = (dispatch: ThunkDispatch) => ({
fetchUsersIfNeeded: () => dispatch(usersAction.fetchUsersIfNeeded())
fetchUsersIfNeeded: () => dispatch(usersAction.fetchUsersIfNeeded()),
});

export default connect(mapStateToProps, mapDispatchToProps)(memo(Home));
4 changes: 2 additions & 2 deletions src/pages/Home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import loadable from '@loadable/component';
import { Loading, ErrorBoundary } from '../../components';

const Home = loadable(() => import('./Home'), {
fallback: <Loading />
fallback: <Loading />,
});

export default props => (
export default (props) => (
<ErrorBoundary>
<Home {...props} />
</ErrorBoundary>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/UserInfo/UserInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const UserInfo = ({ match, userInfo, fetchUserIfNeeded }: Props) => {
const mapStateToProps = ({ userInfo }: AppState) => ({ userInfo });

const mapDispatchToProps = (dispatch: ThunkDispatch) => ({
fetchUserIfNeeded: (id: string) => dispatch(userAction.fetchUserIfNeeded(id))
fetchUserIfNeeded: (id: string) => dispatch(userAction.fetchUserIfNeeded(id)),
});

export default connect(mapStateToProps, mapDispatchToProps)(memo(UserInfo));
4 changes: 2 additions & 2 deletions src/pages/UserInfo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import loadable from '@loadable/component';
import { Loading, ErrorBoundary } from '../../components';

const UserInfo = loadable(() => import('./UserInfo'), {
fallback: <Loading />
fallback: <Loading />,
});

export default props => (
export default (props) => (
<ErrorBoundary>
<UserInfo {...props} />
</ErrorBoundary>
Expand Down
12 changes: 6 additions & 6 deletions src/reducers/__tests__/home.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ describe('users data home', () => {
home(undefined, {
type: USERS_REQUESTING,
err: null,
data: []
data: [],
})
).toEqual({
readyStatus: 'request',
err: null,
list: []
list: [],
});
});

Expand All @@ -26,12 +26,12 @@ describe('users data home', () => {
expect(
home(undefined, {
type: USERS_FAILURE,
err
err,
})
).toEqual({
...initialState,
readyStatus: 'failure',
err
err,
});
});

Expand All @@ -41,12 +41,12 @@ describe('users data home', () => {
home(undefined, {
type: USERS_SUCCESS,
err: null,
data
data,
})
).toEqual({
...initialState,
readyStatus: 'success',
list: data
list: data,
});
});
});
16 changes: 8 additions & 8 deletions src/reducers/__tests__/userInfo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('user data userInfo', () => {
expect(
userInfo(undefined, {
type: USER_REQUESTING,
userId: '1'
userId: '1',
})
).toEqual({ 1: { readyStatus: 'request' } });
});
Expand All @@ -22,13 +22,13 @@ describe('user data userInfo', () => {
userInfo(undefined, {
type: USER_FAILURE,
userId: '1',
err
err,
})
).toEqual({
1: {
readyStatus: 'failure',
err
}
err,
},
});
});

Expand All @@ -37,19 +37,19 @@ describe('user data userInfo', () => {
name: 'Welly',
phone: '007',
email: '[email protected]',
website: 'www.test.com'
website: 'www.test.com',
};
expect(
userInfo(undefined, {
type: USER_SUCCESS,
userId: '1',
data
data,
})
).toEqual({
1: {
readyStatus: 'success',
info: data
}
info: data,
},
});
});
});
10 changes: 5 additions & 5 deletions src/reducers/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,34 @@ import {
UsersAction,
USERS_REQUESTING,
USERS_SUCCESS,
USERS_FAILURE
USERS_FAILURE,
} from '../types';

// Export for unit testing
export const initialState: HomeState = {
readyStatus: 'invalid',
err: null,
list: []
list: [],
};

export default (state = initialState, action: UsersAction) => {
switch (action.type) {
case USERS_REQUESTING:
return {
...state,
readyStatus: 'request'
readyStatus: 'request',
};
case USERS_SUCCESS:
return {
...state,
readyStatus: 'success',
list: action.data
list: action.data,
};
case USERS_FAILURE:
return {
...state,
readyStatus: 'failure',
err: action.err
err: action.err,
};
default:
return state;
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export default (history: History) =>
// Register reducers here
home,
userInfo,
router: connectRouter(history)
router: connectRouter(history),
});
14 changes: 7 additions & 7 deletions src/reducers/userInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
UserAction,
USER_REQUESTING,
USER_SUCCESS,
USER_FAILURE
USER_FAILURE,
} from '../types';

export default (state: UserInfoState = {}, action: UserAction) => {
Expand All @@ -12,24 +12,24 @@ export default (state: UserInfoState = {}, action: UserAction) => {
return {
...state,
[action.userId]: {
readyStatus: 'request'
}
readyStatus: 'request',
},
};
case USER_SUCCESS:
return {
...state,
[action.userId]: {
readyStatus: 'success',
info: action.data
}
info: action.data,
},
};
case USER_FAILURE:
return {
...state,
[action.userId]: {
readyStatus: 'failure',
err: action.err
}
err: action.err,
},
};
default:
return state;
Expand Down
16 changes: 8 additions & 8 deletions src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ export default [
exact: true,
component: asyncHome, // Add your route here
loadData: () => [
usersAction.fetchUsersIfNeeded()
usersAction.fetchUsersIfNeeded(),
// Add other pre-fetched actions here
]
],
},
{
path: '/UserInfo/:id',
component: asyncUserInfo,
loadData: ({ params }: { params: { id: string } }) => [
userAction.fetchUserIfNeeded(params.id)
]
userAction.fetchUserIfNeeded(params.id),
],
},
{
component: NotFound
}
]
}
component: NotFound,
},
],
},
];
2 changes: 1 addition & 1 deletion src/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,6 @@ app.get('*', (req, res) => {
});

// @ts-ignore
app.listen(config.port, config.host, err => {
app.listen(config.port, config.host, (err) => {
if (err) console.error(chalk.red(`==> 😭 OMG!!! ${err}`));
});
4 changes: 2 additions & 2 deletions src/utils/configureStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export default ({ initialState, url }: Argv) => {
// Create a history depending on the environment
const history = isServer
? createMemoryHistory({
initialEntries: [url || '/']
initialEntries: [url || '/'],
})
: createBrowserHistory();
const middlewares = [
routerMiddleware(history),
thunk
thunk,
// Add other middlewares here
];
// Use Redux DevTools Extension in development
Expand Down
2 changes: 1 addition & 1 deletion src/utils/renderHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default (
trimCustomFragments: true,
minifyCSS: true,
minifyJS: true,
minifyURLs: true
minifyURLs: true,
};

// Minify html in production
Expand Down
Loading

0 comments on commit 890fee0

Please sign in to comment.