- Notifications
You must be signed in to change notification settings - Fork 1
V3 #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
V3 #5
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here if I wrote the following code, the linter would warn that I should use export default
instead
export const updateName = (text) => ({ type: actionTypes.HELLO_WORLD_NAME_UPDATE, text, });
export const updateName = (text) => ({ | ||
type: actionTypes.HELLO_WORLD_NAME_UPDATE, | ||
text, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linter will warn that I should use export default
here as there's only one export. But if I did so, mapDisptachToProps related code in the container file (HelloWorld.jsx) would be weird. Should I create a dummy action here to bypass this warning or can we ignore this rule? I think the rule is not quite suitable in this kind of circumstances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add this line to the top of the file:
/* eslint-disable import/prefer-default-export */
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nostophilia Please make the following changes and create a v4 branch. We're close!
@robwise, @alexfedoseev please confirm my suggestions.
export const updateName = (text) => ({ | ||
type: actionTypes.HELLO_WORLD_NAME_UPDATE, | ||
text, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add this line to the top of the file:
/* eslint-disable import/prefer-default-export */
// See https://www.npmjs.com/package/mirror-creator | ||
// Allows us to set up constants in a slightly more concise syntax. See: | ||
// client/app/bundles/HelloWorld/actions/helloWorldActionCreators.jsx | ||
import mirrorCreator from 'mirror-creator'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove mirrorCreator
Instead, use the simple form:
export default { HELLO_WORLD_NAME_UPDATE: 'HELLO_WORLD_NAME_UPDATE' };
So this file just has above lines..
@alexfedoseev Please confirm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use
export const HELLO_WORLD_NAME_UPDATE = 'HELLO_WORLD_NAME_UPDATE';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with Alex
@@ -0,0 +1,14 @@ | |||
import actionTypes from '../constants/helloWorldConstants'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this file should be helloWorldReducer.js
and not name.jsx
@@ -0,0 +1,14 @@ | |||
import actionTypes from '../constants/helloWorldConstants'; | |||
| |||
const name = (state = '', action) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use this for the initial state:
{ name: '' }
It's really confusing for me with a single value for the reducer.
Also, we can use the spread operator for the reducer
return { ...state, name: text }
to ensure we don't mutate state.
@robwise, @alexfedoseev please confirm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's standard practice to write reducers with single values like that and is in the basic Todos
example from Redux
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. Because combineReducers is used in index.js, so the intialState is actually:
{ name: '' }
I think it's better to use combineReducers and child reducer to handle a simple slice of state. So I suggest have a name reducer in helloWorldReducer.js and also call combineReducers in this file.
} | ||
}; | ||
| ||
export default name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export default helloWorldReducer;
No description provided.