-
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
[Bridge] Order of callbacks on native bridge modules is backwards #186
Comments
Good catch. @jordwalke attempted to always have error callback THEN success callback. The motivation was to never forget the error callback but this introduced more confusion than anything and didn't pick up. There are still some remaining of this attempt here and there. |
There is no way to enforce which is which so any method can rename them how it wants. We should probably just rename the vars in the bridge impl to cb1 and cb2.
|
It might be worth keeping some structure and documenting the (successCallback, errorCallback) convention. One benefit of the convention is that it makes the migration towards Promises / ES7 async functions (the discussion in #172) easier. Concretely the migration layer could roughly look like this: function promisifyLegacyBridgeMethodThatHonorsConvention(method) {
return function() {
var context = this;
var args = Array.slice.call(arguments);
return new Promise((resolve, reject) {
// Assume last two args to the legacy method are the success and error callbacks
// by convention... might need a wrapper function that massages the args into a form
// that resolve/reject expect but this is the gist of the idea
args.push(resolve);
args.push(reject);
method.apply(context, args);
});
};
} |
The JS (BatchedBridgeFactory & MessageQueue) expects the last two arguments of async bridge methods to be
errorCallback
,successCallback
:but the RCTBridgeModules define
successCallback:errorCallback:
. This isn't causing any issues - pointing it out mostly in case it causes confusion down the road.The text was updated successfully, but these errors were encountered: