Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 868952e

Browse files
committed
Adding local config cache invalidation
1 parent 3030c63 commit 868952e

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

CodePush.ios.js

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
'use strict';
22

3+
var { AlertIOS } = require("react-native");
34
var NativeCodePush = require("react-native").NativeModules.CodePush;
5+
var packageMixins = require("./package-mixins")(NativeCodePush);
46
var requestFetchAdapter = require("./request-fetch-adapter.js");
57
var Sdk = require("code-push/script/acquisition-sdk").AcquisitionManager;
6-
var packageMixins = require("./package-mixins")(NativeCodePush);
7-
8-
var { AlertIOS } = require("react-native");
9-
10-
// This function is only used for tests. Replaces the default SDK, configuration and native bridge
11-
function setUpTestDependencies(providedTestSdk, providedTestConfig, testNativeBridge){
12-
if (providedTestSdk) testSdk = providedTestSdk;
13-
if (providedTestConfig) testConfig = providedTestConfig;
14-
if (testNativeBridge) NativeCodePush = testNativeBridge;
15-
}
16-
var testConfig;
17-
var testSdk;
188

199
function checkForUpdate() {
2010
var config;
@@ -61,10 +51,12 @@ function checkForUpdate() {
6151
});
6252
}
6353

54+
var isConfigValid = true;
55+
6456
var getConfiguration = (() => {
6557
var config;
6658
return function getConfiguration() {
67-
if (config) {
59+
if (config && isConfigValid) {
6860
return Promise.resolve(config);
6961
} else if (testConfig) {
7062
return Promise.resolve(testConfig);
@@ -125,6 +117,26 @@ function restartApp(rollbackTimeout = 0) {
125117
NativeCodePush.restartApp(rollbackTimeout);
126118
}
127119

120+
function setDeploymentKey(deploymentKey) {
121+
return NativeCodePush.setDeploymentKey(deploymentKey)
122+
.then(() => {
123+
// Mark the local copy of the config data
124+
// as invalid since we just modified it
125+
// on the native end.
126+
isConfigValid = false;
127+
});
128+
}
129+
130+
var testConfig;
131+
var testSdk;
132+
133+
// This function is only used for tests. Replaces the default SDK, configuration and native bridge
134+
function setUpTestDependencies(providedTestSdk, providedTestConfig, testNativeBridge) {
135+
if (providedTestSdk) testSdk = providedTestSdk;
136+
if (providedTestConfig) testConfig = providedTestConfig;
137+
if (testNativeBridge) NativeCodePush = testNativeBridge;
138+
}
139+
128140
/**
129141
* The sync method provides a simple, one-line experience for
130142
* incorporating the check, download and application of an update.
@@ -276,7 +288,7 @@ var CodePush = {
276288
log: log,
277289
notifyApplicationReady: NativeCodePush.notifyApplicationReady,
278290
restartApp: restartApp,
279-
setDeploymentKey: NativeCodePush.setDeploymentKey,
291+
setDeploymentKey: setDeploymentKey,
280292
setUpTestDependencies: setUpTestDependencies,
281293
sync: sync,
282294
InstallMode: {

0 commit comments

Comments
 (0)