mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-10 23:59:42 +08:00
Make getConfiguration return a promise
This commit is contained in:
@@ -19,18 +19,13 @@ function setUpTestDependencies(testSdk, testConfiguration, testNativeBridge){
|
||||
if (testNativeBridge) NativeCodePush = testNativeBridge;
|
||||
}
|
||||
|
||||
function getConfiguration(callback) {
|
||||
if (config) {
|
||||
setImmediate(function() {
|
||||
callback(/*error=*/ null, config);
|
||||
function getConfiguration() {
|
||||
return Promise
|
||||
.resolve(config || NativeCodePush.getConfiguration())
|
||||
.then((configuration) => {
|
||||
if (!config) config = configuration;
|
||||
return config;
|
||||
});
|
||||
} else {
|
||||
NativeCodePush.getConfiguration(function(err, configuration) {
|
||||
if (err) callback(err);
|
||||
config = configuration;
|
||||
callback(/*error=*/ null, config);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getSdk(callback) {
|
||||
@@ -39,7 +34,7 @@ function getSdk(callback) {
|
||||
callback(/*error=*/ null, sdk);
|
||||
});
|
||||
} else {
|
||||
getConfiguration(function(err, configuration) {
|
||||
getConfiguration().then(function(configuration) {
|
||||
sdk = new Sdk(requestFetchAdapter, configuration);
|
||||
callback(/*error=*/ null, sdk);
|
||||
});
|
||||
@@ -47,8 +42,7 @@ function getSdk(callback) {
|
||||
}
|
||||
|
||||
function checkForUpdate(callback) {
|
||||
getConfiguration(function(err, configuration) {
|
||||
if (err) callback(err);
|
||||
getConfiguration().then(function(configuration) {
|
||||
getSdk(function(err, sdk) {
|
||||
if (err) callback(err);
|
||||
NativeCodePush.getLocalPackage(function(err, localPackage) {
|
||||
|
||||
@@ -80,9 +80,10 @@ RCT_EXPORT_METHOD(setUsingTestFolder:(BOOL) shouldUseTestFolder)
|
||||
usingTestFolder = shouldUseTestFolder;
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(getConfiguration:(RCTResponseSenderBlock)callback)
|
||||
RCT_EXPORT_METHOD(getConfiguration:(RCTPromiseResolveBlock)resolve
|
||||
rejecter:(RCTPromiseRejectBlock)reject)
|
||||
{
|
||||
callback(@[[NSNull null], [CodePushConfig getConfiguration]]);
|
||||
resolve([CodePushConfig getConfiguration]);
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(installUpdate:(NSDictionary*)updatePackage
|
||||
|
||||
Reference in New Issue
Block a user