-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
Summary: public This is the first module moving to the new model of working with Promises. We now warn on uses of callback version. At some point we will remove that. Reviewed By: davidaurelio Differential Revision: D2849811 fb-gh-sync-id: 8a31924cc2b438efc58f3ad22d5f27c273563472
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
let Systrace = require('Systrace'); | ||
let ErrorUtils = require('ErrorUtils'); | ||
let JSTimersExecution = require('JSTimersExecution'); | ||
let Platform = require('Platform'); | ||
|
||
let invariant = require('invariant'); | ||
let keyMirror = require('keyMirror'); | ||
|
@@ -318,10 +319,21 @@ class MessageQueue { | |
if (type === MethodTypes.remoteAsync) { | ||
fn = function(...args) { | ||
return new Promise((resolve, reject) => { | ||
self.__nativeCall(module, method, args, resolve, (errorData) => { | ||
var error = createErrorFromErrorData(errorData); | ||
reject(error); | ||
}); | ||
self.__nativeCall( | ||
module, | ||
method, | ||
args, | ||
(data) => { | ||
// iOS always wraps the data in an Array regardless of what the | ||
// shape of the data so we strip it out | ||
// Android sends the data back properly | ||
// TODO: Remove this once iOS has support for Promises natively (t9774697) | ||
resolve(Platform.OS == 'ios' ? data[0] : data); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
geof90
Contributor
|
||
}, | ||
(errorData) => { | ||
var error = createErrorFromErrorData(errorData); | ||
reject(error); | ||
}); | ||
}); | ||
}; | ||
} else { | ||
|
4 comments
on commit 9baff8f
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.
@satya164 Here is the change to CameraRoll we were talking about.
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.
@dmmiller Thanks.
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.
Is there anywhere to see an example use with promises? The docs seems outdated.
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.
@samuelkraft It's the same API. Just that it returns a promise rather than taking success and error callbacks. A PR will be awesome to update the docs.
@ide Notice this change to iOS promises. The parameter is no longer wrapped in an array. It is just whatever object is passed from the native side. I think you might be the only person relying on this. I changed it to match Android which doesn't put the extra wrapper around it. Hopefully I didn't break you or not too badly anyway.