From 4b6fac100d01add4b5fc332410d75bd9d660ec98 Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Tue, 24 Nov 2015 13:57:46 -0800 Subject: [PATCH 1/2] Fixing caching issue with specifying a deployment key --- CodePush.ios.js | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/CodePush.ios.js b/CodePush.ios.js index cf58aa5..8388501 100644 --- a/CodePush.ios.js +++ b/CodePush.ios.js @@ -7,24 +7,20 @@ var requestFetchAdapter = require("./request-fetch-adapter.js"); var Sdk = require("code-push/script/acquisition-sdk").AcquisitionManager; function checkForUpdate(deploymentKey = null) { - var config; - var sdk; + var config, sdk; return getConfiguration() - .then((configResult) => { - config = configResult; - + .then((configResult) => { // If a deployment key was explicitly provided, // then let's override the one we retrieved // from the native-side of the app. if (deploymentKey) { - config.deploymentKey = deploymentKey; + config = Object.assign({}, configResult, { deploymentKey: deploymentKey }); + } else { + config = configResult; } - return getSdk(); - }) - .then((sdkResult) => { - sdk = sdkResult; + sdk = getSDK(config); return getCurrentPackage(); }) .then((localPackage) => { @@ -76,23 +72,6 @@ var getConfiguration = (() => { } })(); -var getSdk = (() => { - var sdk; - return function getSdk() { - if (sdk) { - return Promise.resolve(sdk); - } else if (testSdk) { - return Promise.resolve(testSdk); - } else { - return getConfiguration() - .then((configuration) => { - sdk = new Sdk(requestFetchAdapter, configuration); - return sdk; - }); - } - } -})(); - function getCurrentPackage() { return new Promise((resolve, reject) => { var localPackage; @@ -114,6 +93,14 @@ function getCurrentPackage() { }); } +function getSDK(config) { + if (testSdk) { + return testSdk; + } else { + return new Sdk(requestFetchAdapter, config); + } +} + /* Logs messages to console with the [CodePush] prefix */ function log(message) { console.log(`[CodePush] ${message}`) From 92e4f3d331d9c73452134a9132f7e7fa4f82695c Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Tue, 24 Nov 2015 14:03:40 -0800 Subject: [PATCH 2/2] Removing superfluous key name --- CodePush.ios.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CodePush.ios.js b/CodePush.ios.js index 8388501..d3b316b 100644 --- a/CodePush.ios.js +++ b/CodePush.ios.js @@ -15,7 +15,7 @@ function checkForUpdate(deploymentKey = null) { // then let's override the one we retrieved // from the native-side of the app. if (deploymentKey) { - config = Object.assign({}, configResult, { deploymentKey: deploymentKey }); + config = Object.assign({}, configResult, { deploymentKey }); } else { config = configResult; }