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

Framework: dispatchRequest update (sites users select) #27615

Merged
merged 11 commits into from
Oct 10, 2018

Conversation

sixhours
Copy link
Contributor

@sixhours sixhours commented Oct 3, 2018

Changes proposed in this Pull Request

See #25121

In this patch we're replacing the use of dispatchRequest() in the data layer handler to use the newer API exposed as dispatchRequestEx() This should have no change in actual effect or interaction.

(I still need to finish updating the Jest tests, this is a WIP.)

Testing instructions

  • Switch to this PR, navigate to My Sites -> People
  • Make sure no errors are thrown in the console
  • Make sure Jest tests pass
  • ...? I'm not sure how else to verify this is working properly. Guidance appreciated!

@sixhours sixhours self-assigned this Oct 3, 2018
@matticbot
Copy link
Contributor

@Automattic Automattic deleted a comment Oct 3, 2018
@ghost
Copy link

ghost commented Oct 3, 2018

That's a great PR description, thank you so much for your effort!

Generated by 🚫 dangerJS

dispatch
)
);
return map( normalizedUsers, flow( receiveUser ) );
Copy link
Contributor

@flootr flootr Oct 4, 2018

Choose a reason for hiding this comment

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

I think we can remove the flow() call because we're not composing functions anymore.

jsnajdr
jsnajdr previously requested changes Oct 4, 2018
...omit( action, 'meta' ),
page: page + 1,
perPage,
} );
Copy link
Member

Choose a reason for hiding this comment

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

Here, fetchUsers used to actually dispatch the action, but now it just returns the action object. We either need to dispatch it or return it from the handler to really execute it.

dispatch
)
);
return map( normalizedUsers, flow( receiveUser ) );
Copy link
Member

Choose a reason for hiding this comment

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

The returned array should optionally contain the fetchUsers action that is dispatched when there are more pages of results available -- we store the users we just got into Redux and at the same time issue a request for the next page.

An idea for a big improvement: add a new action, RECEIVE_USERS, that will store all users in an array as part of one state update.

Dispatching an array of N RECEIVE_USER actions will cause N state updates and N React rerenders of the app.

@sixhours
Copy link
Contributor Author

Thanks @jsnajdr for the explanation! I took another look at this but I can't figure out how to make it connect properly using the new dispatch method. I'm going to hand it back to you so I don't hold this process up, and keep an eye on the ticket to see how you do it. :)

…uing request for next page

Improve the `receiveSuccess` handler to first store the just-received page of user results using
the `USERS_RECEIVE` action, and then optionally issue a request for the next page.
@jsnajdr
Copy link
Member

jsnajdr commented Oct 10, 2018

Thanks @sixhours for working on this issue! I added a few finishing touches and I believe it's ready to merge now. Details on what I did:

  • added new USERS_RECEIVE action that can atomically add all users from a response to Redux state
  • amended the receiveSuccess handler to use the new action and also correctly issue a request for the new page. I used a thunk that calls two dispatches internally. It's also possible to return an array of one or two actions, but I believe that a thunk is more readable in this case.
  • some janitorial changes: migrate test expectations to Jest, fix ESLint warnings in JSDoc comments

@flootr Can you have a quick look at the PR? I don't want to approve and merge my own commits 😉

@jsnajdr jsnajdr dismissed their stale review October 10, 2018 08:14

The issues got fixed by myself, someone else will need to review

Copy link
Contributor

@flootr flootr left a comment

Choose a reason for hiding this comment

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

LGTM

@jsnajdr jsnajdr merged commit e58b0b6 into master Oct 10, 2018
@jsnajdr jsnajdr deleted the update/framework-sites-users-select branch October 10, 2018 09:06
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