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

Voting: use aragonAPI for React + React hooks #717

Merged
merged 38 commits into from
Apr 10, 2019
Merged

Conversation

bpierre
Copy link
Contributor

@bpierre bpierre commented Mar 18, 2019

@bpierre bpierre changed the title Voting react api Voting: use @aragon/api-react + React hooks Mar 18, 2019
@bpierre bpierre requested review from 2color and sohkai March 21, 2019 11:46
@bpierre bpierre marked this pull request as ready for review March 21, 2019 11:46
@coveralls
Copy link

coveralls commented Mar 21, 2019

Coverage Status

Coverage remained the same at 96.734% when pulling 2af4569 on voting-react-api into c4c936f on master.

@bpierre bpierre requested a review from sohkai April 3, 2019 17:21
Copy link
Contributor

@sohkai sohkai left a comment

Choose a reason for hiding this comment

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

I'm not sold on migrating App.js to use hooks completely.

I like it for simple components without too much logic, but for the main state container and logic controller of an app (which usually has no use for lifecycle hooks), it feels more difficult to read and understand due to everything being declared in-place without a lot of syntactic separation.

Particularly tricky is the dependencies lists, which looks likely to bite us at one point or another.

apps/voting/app/src/app-hooks.js Outdated Show resolved Hide resolved
apps/voting/app/src/App.js Outdated Show resolved Hide resolved
apps/voting/app/src/components/VotePanelContent.js Outdated Show resolved Hide resolved
apps/voting/app/src/components/VotePanelContent.js Outdated Show resolved Hide resolved
apps/voting/app/src/App.js Outdated Show resolved Hide resolved
apps/voting/app/src/vote-hooks.js Outdated Show resolved Hide resolved
apps/voting/app/src/vote-hooks.js Outdated Show resolved Hide resolved
apps/voting/app/src/vote-hooks.js Outdated Show resolved Hide resolved
apps/voting/app/src/App.js Outdated Show resolved Hide resolved
apps/voting/app/src/App.js Outdated Show resolved Hide resolved
bpierre added 5 commits April 8, 2019 23:34
voting-app.js now contains most of the logic of the app.

Other changes:

- Remove vote-hooks.js: usePromise() is now in utils-hook.js, and the
  rest is in voting-app.js
- Remove provideNetwork (replaced by useNetwork() from @aragon/api-react)
- Replace the provideSettings HOC by a useSettings() hook.
- Refactor IdentityManager.js to expose a hook rather than a context.
- Remove app-hooks.js and app-contexts.js (made useless by specialized
  hooks / providers like SettingsProvider / useSettings() and
  IdentityProvider / useIdentity()).
Since it contains more than a component.
@bpierre bpierre requested a review from sohkai April 9, 2019 00:46
@@ -31,6 +26,8 @@
"jsxBracketSameLine": false
}
],
"react-hooks/rules-of-hooks": "error",
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

apps/voting/app/src/App.js Show resolved Hide resolved
apps/voting/app/src/App.js Outdated Show resolved Hide resolved
apps/voting/app/src/App.js Outdated Show resolved Hide resolved
apps/voting/app/src/vote-utils.js Outdated Show resolved Hide resolved
apps/voting/app/src/identity-manager.js Outdated Show resolved Hide resolved
apps/voting/app/src/identity-manager.js Show resolved Hide resolved
apps/voting/app/src/voting-app.js Outdated Show resolved Hide resolved
prevVote.numData.votingPower === nextVote.numData.votingPower &&
prevVote.numData.yea === nextVote.numData.yea &&
prevVote.numData.nay === nextVote.numData.nay
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sohkai now 1000x faster 😆

Copy link
Contributor

@sohkai sohkai left a comment

Choose a reason for hiding this comment

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

One last small thing and I think this is good to go ⚡️!

apps/voting/app/src/components/VotingCard/VotingCard.js Outdated Show resolved Hide resolved
@bpierre bpierre merged commit ad4a43c into master Apr 10, 2019
@bpierre bpierre deleted the voting-react-api branch April 10, 2019 15:30
ramilexe pushed a commit to ConsiderItDone/aragon-apps that referenced this pull request Dec 9, 2021
The app is now using aragonAPI for React, and has also been a bit rearranged
to take advantage of using React Hooks. The idea is to keep using the Voting app
as an experiment to find and validate patterns related to React Hooks that we could use.

A new file, `app-logic.js`, contains most of the logic to be used by `App.js`, by exporting
`AppLogicProvider` and `useAppLogic()`. This is meant to be the pattern used by other apps
in the future (providing that we validate this idea).

Other changes:

- VotingCard now skips any unnecessary update.
- The vote texts (description and metadata) are now a separate component rather than
  being pre-rendered (that way it is easier to skip updates).
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.

5 participants