Skip to content
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

Closed
wants to merge 7 commits into from

Conversation

paguillama
Copy link

@paguillama paguillama commented Oct 17, 2016

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.

@paguillama
Copy link
Author

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",
Copy link
Author

@paguillama paguillama Oct 18, 2016

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 :|

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/25223149/is-there-any-way-for-jscs-to-ignore-rules-per-file-block-or-line

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

Copy link
Author

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.

@paguillama
Copy link
Author

Test output:

bash ./test-runner.sh 

> [email protected] test-server /home/gablo/Desktop/projects/pg/todomvc
> gulp test-server &

[02:57:27] Using gulpfile ~/Desktop/projects/pg/todomvc/gulpfile.js
[02:57:27] Starting 'test-server'...
[02:57:27] Finished 'test-server' after 3.67 ms

> @ lint /home/gablo/Desktop/projects/pg/todomvc/tooling
> cd .. && jscs "examples/react-redux" "tests/"

react-redux, NaN, NaN, NaN

> todomvc-browser-tests@ test /home/gablo/Desktop/projects/pg/todomvc/tests
> mocha allTests.js --no-timeouts --reporter spec "--framework=react-redux"



  TodoMVC - react-redux
    When page is initially opened
      ✓ should focus on the todo input field
    No Todos
      ✓ should hide #main and #footer (315ms)
    New Todo
      ✓ should allow me to add todo items (329ms)
      ✓ should clear text input field when an item is added (194ms)
      ✓ should append new items to the bottom of the list (495ms)
      ✓ should trim text input (187ms)
      ✓ should show #main and #footer when items added (199ms)
    Mark all as completed
      ✓ should allow me to mark all items as completed (67ms)
      ✓ should correctly update the complete all checked state (185ms)
      ✓ should allow me to clear the completion state of all items (91ms)
      ✓ complete all checkbox should update state when items are completed / cleared (182ms)
    Item
      ✓ should allow me to mark items as complete (399ms)
      ✓ should allow me to un-mark items as complete (383ms)
    Editing
      ✓ should focus the input (38ms)
      ✓ should hide other controls when editing (130ms)
      ✓ should save edits on enter (220ms)
      ✓ should save edits on blur (274ms)
      ✓ should trim entered text (238ms)
      ✓ should remove the item if an empty text string was entered (172ms)
      ✓ should cancel edits on escape (196ms)
    Counter
      ✓ should display the current number of todo items (304ms)
    Clear completed button
      ✓ should display the correct text (86ms)
      ✓ should remove completed items when clicked (204ms)
      ✓ should be hidden when there are no items that are completed (227ms)
    Persistence
      ✓ should persist its data (670ms)
    Routing
      ✓ should allow me to display active items (181ms)
      ✓ should respect the back button (353ms)
      ✓ should allow me to display completed items (235ms)
      ✓ should allow me to display all items (325ms)
      ✓ should highlight the currently applied filter (164ms)


  30 passing (55s)

@arthurvr
Copy link
Member

arthurvr commented Nov 6, 2016

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!

@paguillama
Copy link
Author

Yes, maybe @fkereki can help us reviewing this PR

@@ -0,0 +1,7 @@
// Action types constants
export const ADD_TODO = 'ADD_TODO';

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.

Copy link
Author

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 = {

Choose a reason for hiding this comment

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

Copy link
Author

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() {

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() {

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 ?

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>

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

Choose a reason for hiding this comment

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

Better than statics, use a constants.js file

}

render() {
const label = this.state.editing ?

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) {

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) {

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() {

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

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

Choose a reason for hiding this comment

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

Are these comments needed?

Copy link
Author

@paguillama paguillama Nov 15, 2016

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

Choose a reason for hiding this comment

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

Check -- does this work?

Copy link
Author

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;
}

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);

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;
}

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.

Copy link

@fkerekiglobant fkerekiglobant left a 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
@paguillama
Copy link
Author

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?

@FadySamirSadek
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants