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

Commit 81fef19

Browse files
author
Will Anderson
committed
Encapsulate/isolate getConfiguration and getSdk stored state
1 parent e22010e commit 81fef19

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

CodePush.ios.js

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ var NativeCodePush = require('react-native').NativeModules.CodePush;
99
var requestFetchAdapter = require("./request-fetch-adapter.js");
1010
var semver = require('semver');
1111
var Sdk = require("code-push/script/acquisition-sdk").AcquisitionManager;
12-
var sdk;
13-
var config;
1412

1513
// This function is only used for tests. Replaces the default SDK, configuration and native bridge
1614
function setUpTestDependencies(testSdk, testConfiguration, testNativeBridge){
@@ -19,29 +17,35 @@ function setUpTestDependencies(testSdk, testConfiguration, testNativeBridge){
1917
if (testNativeBridge) NativeCodePush = testNativeBridge;
2018
}
2119

22-
function getConfiguration() {
23-
if (config) {
24-
return Promise.resolve(config);
25-
} else {
26-
return NativeCodePush.getConfiguration()
27-
.then((configuration) => {
28-
if (!config) config = configuration;
29-
return config;
30-
});
20+
var getConfiguration = (() => {
21+
var config;
22+
return function getConfiguration() {
23+
if (config) {
24+
return Promise.resolve(config);
25+
} else {
26+
return NativeCodePush.getConfiguration()
27+
.then((configuration) => {
28+
if (!config) config = configuration;
29+
return config;
30+
});
31+
}
3132
}
32-
}
33+
})();
3334

34-
function getSdk() {
35-
if (sdk) {
36-
return Promise.resolve(sdk);
37-
} else {
38-
return getConfiguration()
39-
.then((configuration) => {
40-
sdk = new Sdk(requestFetchAdapter, configuration);
41-
return sdk;
42-
});
35+
var getSdk = (() => {
36+
var sdk;
37+
return function getSdk() {
38+
if (sdk) {
39+
return Promise.resolve(sdk);
40+
} else {
41+
return getConfiguration()
42+
.then((configuration) => {
43+
sdk = new Sdk(requestFetchAdapter, configuration);
44+
return sdk;
45+
});
46+
}
4347
}
44-
}
48+
})();
4549

4650
function checkForUpdate(callback) {
4751
getConfiguration().then(function(configuration) {

0 commit comments

Comments
 (0)