-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
API consistency in React Native #4971
Comments
I think consistent use of ES6 Also if the decision for Promises everywhere is made, use-sites of other callback styles should probably be deprecated, except for uses that are clearly not a |
What feichngr said - I would go with promises. Love working with fetch() in RN right now. Functions returning promises makes for some nice composability. |
Yeah, personally I think that promises are the way to go. Currently the problem with promises in React native is that errors are not shown unless you call |
Another vote for promises, especially since babel lets us use |
Nice writeup @satya164 :) Another vote for promises |
@davidaurelio is the promise polyfill with error tracking being used in RN yet? |
No, will update it… thanks for the reminder! |
@davidaurelio the Promise polyfill is going to live in fbjs after this PR is merged, fyi: #5084 |
@skevy thanks for the heads up. |
Summary: Adds support for tracking unhandled rejections with `console.warn` (= yellow box). I will create a follow-up with proper error stack formatting. related: #4971 fixes: #4045, #4142 public {F59857438} {F59857439} Reviewed By: bestander Differential Revision: D2803126 fb-gh-sync-id: 376b33e42a967675a04338cbff3ec315a77d1037
Now that RN has rejection tracking for promises, we could get started on this. @skevy |
Summary: Adds support for tracking unhandled rejections with `console.warn` (= yellow box). I will create a follow-up with proper error stack formatting. related: facebook#4971 fixes: facebook#4045, facebook#4142 public {F59857438} {F59857439} Reviewed By: bestander Differential Revision: D2803126 fb-gh-sync-id: 376b33e42a967675a04338cbff3ec315a77d1037
This may be opening a whole different can of worms, but I think it would be worth considering including/standardizing on an RxJS // Basic example to print all connectivity events
NetInfo.connectivityEvents.subscribe(connection => console.log(`current connection: ${connection}`));
// Start sync when connected on wifi
NetInfo.connectivityEvents.filter(connection => connection === 'wifi').subscribe(startSync); |
I think so. Also word through the grapevine is some bigger cos are moving away from Observable. |
Summary: A promise based API for handling Link for Android and iOS. Refer #4971 The iOS part doesn't handle errors. Will need someone with iOS knowledge to do that. cc skevy ide brentvatne mkonicek vjeux nicklockwood Closes #5336 Reviewed By: svcscm Differential Revision: D2866664 Pulled By: androidtrunkagent fb-gh-sync-id: 67e68a827e6b85886bfa84e79b897f079e78b1b5
Summary: A promise based API for handling Link for Android and iOS. Refer facebook#4971 The iOS part doesn't handle errors. Will need someone with iOS knowledge to do that. cc skevy ide brentvatne mkonicek vjeux nicklockwood Closes facebook#5336 Reviewed By: svcscm Differential Revision: D2866664 Pulled By: androidtrunkagent fb-gh-sync-id: 67e68a827e6b85886bfa84e79b897f079e78b1b5
Is this still something we should keep opened? Looks like we have decided to go with Promise-based API, that's what other libraries started to adapting and the general |
@grabbou Yeah, we can file smaller issues and close this. |
OK I'll close this one. Just saw the description again, it's an awesome writeup! Have a lot of APIs been migrated to Promises? |
@mkonicek Thank you :) Yeah, most have been migrated to promises. I think only |
And.... ActionSheetIOS but there's open PR for that :) |
Currently React Native has lots of incosnistencies in its APIs. This is an attempt to settle on a standard way for API methods and change the current APIs to the standard format by discussing a migration path.
Currently available modules and their callbacks
The available APIs can be categorized into the following categories,
1. Node-style error-first callbacks
2. Value first callbacks
3. Separate callbacks for success and error, success-first
4. Separate callbacks for success and error, error-first
5. Callbacks with no error
6. Promise based APIs
Candidates for the standardized callbacks
The callbacks should encourage error handling IMO. Keeping that in mind, I think the following should be good candidates.
Problems to discuss
If I missed any, please edit the post and add them. Thanks :D
cc @vjeux @mkonicek @nicklockwood @ide @brentvatne @skevy
The text was updated successfully, but these errors were encountered: