From 87f0e265715505a6d96fc4982c7fbb2b89f236f2 Mon Sep 17 00:00:00 2001 From: Will Anderson Date: Tue, 1 Sep 2015 14:01:10 -0700 Subject: [PATCH] Make getConfiguration return a promise --- CodePush.ios.js | 22 ++++++++-------------- CodePush.m | 5 +++-- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/CodePush.ios.js b/CodePush.ios.js index 7f99fe7..2673ad2 100644 --- a/CodePush.ios.js +++ b/CodePush.ios.js @@ -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) { diff --git a/CodePush.m b/CodePush.m index 33483e1..17b4815 100644 --- a/CodePush.m +++ b/CodePush.m @@ -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