-
Notifications
You must be signed in to change notification settings - Fork 53
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
React API improvements #233
Conversation
This is needed to pass errors with subscriptions, the same way we do it for the async functions by throwing errors. Contains the following changes: - Add the add SubscriptionCallback type. - Add types to all the subscriptions methods. - Move all the subscription methods to use node-style callbacks. - Update documentation and examples.
Rather than separate ones, which creates less updates.
Together, this utility and type can be used to help app connectors declare their subscriptions easily.
Codecov Report
@@ Coverage Diff @@
## master #233 +/- ##
==========================================
- Coverage 39.20% 38.87% -0.34%
==========================================
Files 113 114 +1
Lines 2043 2089 +46
Branches 314 318 +4
==========================================
+ Hits 801 812 +11
- Misses 1242 1277 +35
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
This is going to be so useful, thanks for turning it around so quickly @bpierre ! I've been doing a little bit of testing and also left a few surface level comments. Something I've noticed is with the unsubs, when I unmount Votes
in the react demo both components seem to be unsubscribed and then loading gets stuck on the remount. Is this expected?
The options and connector props of the <Connect /> component are now memoized, except if connector is a live instance, in which case it is the responsibility of the provider to memoize it. This commit also makes loading states the default.
Good catch, thanks! It should be fixed since add4da4. Updates should now be reduced to the strict minimum, and the loading issue is now fixed. Could you please try and tell me if it works for you? |
Awesome stuff, the inclusion of the buttons in the demo was nice too 😁 the mounting issue is fixed! but I still saw the same problem with the |
Updated the onSetting() method of the Disputable Voting app to the new subscription format.
@bpierre – Loading statuses are consistent and working great! I did spin up the org viewer react demo as well just to double check some things and I'm seeing a |
Move new subscription methods to the new format.
@andy-hook oops ba35574 It should all be fine now, I tested all the examples. Let me know if that works for you! |
Works great! Edit: removing happy clappy Morgan Freeman to save my eyes, but he remains in spirit :) |
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.
fixes #216, builds on #229
This PR contains various improvements for the React API. I suggest to review them commit by commit, every section ends with a link to the related commits (“see …”).
Loading behavior
Since we replaced the GraphQL subscriptions by queries with polling (see #203), the hooks provided by the React API were updating too often, and incorrectly (see #216). This version is now taking care of only triggering updates when a changed happened, and to only use loading states when necessary.
See 0f0206a, a223382, 3589809.
createAppHook(): allow connector configuration to be set
App connectors can receive a source connector and its options, but this wasn’t possible when using
createAppHook()
. A second parameter has been added, to either pass a specific connector or to change its options:See f0dbc28.
createAppHook(): add a dependencies array
Hooks created through
createAppHook()
now accept a dependency array, that can get used to refresh its callback. When no dependency array is passed, the callback never updates.See 7f661d3.
Populating status.error rather than throwing errors
In many cases, errors were thrown rather than populating the
status.error
object in the React API. It is an issue that was also happening with the JS API (see #229). It has now been fixed.See ddaad5b, 79c5382.
App methods subscriptions
Prior to this version, it was not possible to subscribe to app methods using
createAppHook()
. The fetched data was returned once, and only updated when the component was mounted again. The feature has been added, and we can now subscribe to any app methods, alongside the core ones (useApp()
,usePermissions()
, …). Every part of the React API is now listening to changes and reacting accordingly.To use this feature, the subscription methods (
onX
) should be called, but without passing a callback.createAppHook()
will take care of handling the subscription.Of course, it also works with the dependencies array, taking care of unsubscribing and subscribing to the new query:
Important: this only works with app connectors enabling this syntax. All the core app connectors have been updated for it, but third party app connectors will require to be updated too.
See #229, 918810b, 2d2cc88, 0278280, 65cc59c, 8e32638, 7a173b9, 0e77afb, 2076bc4.