Skip to content

Conversation

mongjong59
Copy link

No description provided.

Copy link
Author

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,
});
Copy link
Author

@mongjong59 mongjong59 Nov 4, 2016

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.

Copy link
Member

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 */ 
Copy link
Member

@justin808 justin808 left a 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,
});
Copy link
Member

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';
Copy link
Member

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

Copy link
Member

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';
Copy link

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';
Copy link
Member

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) => {
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link

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

Copy link
Author

@mongjong59 mongjong59 Nov 9, 2016

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export default helloWorldReducer;

@justin808 justin808 closed this Mar 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants