-
Notifications
You must be signed in to change notification settings - Fork 13.8k
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
Adds React/Redux example #1706
Adds React/Redux example #1706
Conversation
I will work on the CI issue :) |
@@ -50,6 +50,8 @@ | |||
"examples/typescript-*/js/**/*.js", | |||
"examples/vanilladart/**/*.js", | |||
"examples/vanilla-es6/dist/bundle.js", | |||
"examples/react-redux/js/reducers/*.js", |
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.
These reducers use object spread operator.
Adding the esnext
option to jscs works but I couldn't find a way to extend a jscs configuration or use a specific one on the js
folder in order to override this option. I also tried disabling jscs with inline comments (/* jscs: disable */
) and didn't work. So I removed reducers from linting :|
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.
Quoting:
To ignore all rules
// Code here will be linted with JSCS.
// jscs:disable
// Code here will be ignored by JSCS.
// jscs:enable
To ignore a specific rule:
// Code here will be linted with JSCS.
// jscs:disable specificRule
// Code here will be ignored by JSCS.
// jscs:enable specificRule
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 tried it, but it didn't work. The only way I found to make it work is with the esnext
flag.
Test output:
|
Took a quick look and the code looks very good, except some tiny style issues. I personally don't use Redux or React frequently though. Do you know anyone active in the redux community that might want to review this? Thanks for the PR! |
Yes, maybe @fkereki can help us reviewing this PR |
@@ -0,0 +1,7 @@ | |||
// Action types constants | |||
export const ADD_TODO = 'ADD_TODO'; |
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 suggest alphabetic ordering.
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.
Done!
|
||
export default class AddTodo extends React.Component { | ||
|
||
static propTypes = { |
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.
Check http://stackoverflow.com/questions/38363156/static-proptypes-not-working-under-es6 -- is the static
usage valid?
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.
Removing the actions
property throws:
Warning: Failed prop type: Required prop `actions` was not specified in `AddTodo`.
in AddTodo (created by Connect(AddTodo))
in Connect(AddTodo) (created by Header)
in header (created by Header)
in Header (created by App)
in div (created by App)
in App (created by Connect(App))
in Connect(App) (created by RouterContext)
in RouterContext (created by Router)
in Router
in Provider
That's because the stage-0
preset contains the transform-class-properties, transpiling static properties for us.
|
||
static ENTER_KEY = 13 | ||
|
||
constructor() { |
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.
Usual is
constructor(props){
super(props);
todos: PropTypes.array.isRequired | ||
} | ||
|
||
constructor() { |
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.
Same comment as above regarding props
parameter
</li> | ||
</ul> | ||
{ | ||
!completedCount ? |
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.
Generally you prefer assigning the expression to a variable, and here just write {thatVariable}
const Header = () => ( | ||
<header className="header"> | ||
<h1>todos</h1> | ||
<AddTodo></AddTodo> |
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.
Usually you would write <AddTodo/>
text: PropTypes.string.isRequired | ||
} | ||
|
||
static ENTER_KEY = 13 |
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.
Better than static
s, use a constants.js file
} | ||
|
||
render() { | ||
const label = this.state.editing ? |
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 rather have an if (this.state.editing)
and assign variables within
type="text" | ||
value={this.state.newText} | ||
ref={input => { | ||
if (input != null) { |
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.
You can write input && input.focus()
onChange={this.handleEditChange}></input>; | ||
|
||
let classNames = []; | ||
if (this.props.completed) { |
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.
You can write (this.props.completed) && classNames.push("completed");
}).isRequired).isRequired | ||
} | ||
|
||
constructor() { |
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.
See comment above
/> | ||
); | ||
|
||
const allCompleted = this.props.todos |
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.
Maybe do a find
to see if there's any non-completed one?
// Renders the application on the .todoapp element | ||
render( | ||
<Provider store={store}> | ||
{/* Provider passes the store to child elements through React context |
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.
Are these comments needed?
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 know it's too much for real code, but they will give others a better understanding on what's going on in order to take a good decision about what framework to use.
|
||
const toggleTodo = state => { | ||
return { | ||
// Object spread operator is not supported by jshint yet |
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.
Check -- does this work?
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.
Yes, jshint ignore
works fine ignoring the spread operator. jscs: disable
is the breaking one.
case actionTypes.TOGGLE_TODO: | ||
if (state.id !== action.id) { | ||
return state; | ||
} |
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 prefer an else
here
|
||
return toggleTodo(state); | ||
case actionTypes.TOGGLE_ALL: | ||
return action.toggleTo === state.completed ? state : toggleTodo(state); |
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.
Use the same style in the previous case, and this one; either an if/then/else or a ternary ? operator.
// so reducers will use their own defaults | ||
if (serializedState === null) { | ||
return undefined; | ||
} |
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 include an else
here.
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.
Please look at the comments, OK?
Code changes regarding review comments
Happy new year community!!! As usual, people try to remove past year pending stuff, and I'm not the exception :) Someone else wants to help reviewing this PR? |
Dear @paguillama, I sincerely apologize for the delay in addressing your contribution. The project experienced a period of inactivity, and combined with my personal time constraints, several updates, including yours, remained unaddressed for longer than anticipated. I am actively working to remedy these outstanding tasks and am committed to ensuring more timely responses in the future. Regrettably, I must close this PR due to its age and extended period without updates. However, if you are still keen on aiding the effort to publish the react-redux example on the TodoMVC website, I would greatly appreciate your expertise. Please consider reviewing PR #2198 and offering any suggestions you believe might enhance the implementation. Thank you for your understanding and continued support. |
This PR adds a React/Redux example.
It is basically this React/Redux example, without some non-react-redux code, and some changes to match the specs.