Make getConfiguration return a promise

This commit is contained in:
Will Anderson
2015-09-01 14:01:10 -07:00
parent 7adc4085d1
commit 87f0e26571
2 changed files with 11 additions and 16 deletions

View File

@@ -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) {

View File

@@ -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