@@ -5,24 +5,20 @@ var Sdk = require("code-push/script/acquisition-sdk").AcquisitionManager;
5
5
var { NativeCodePush, PackageMixins, Alert } = require ( "./CodePushNativePlatformAdapter" ) ;
6
6
7
7
function checkForUpdate ( deploymentKey = null ) {
8
- var config ;
9
- var sdk ;
8
+ var config , sdk ;
10
9
11
10
return getConfiguration ( )
12
- . then ( ( configResult ) => {
13
- config = configResult ;
14
-
11
+ . then ( ( configResult ) => {
15
12
// If a deployment key was explicitly provided,
16
13
// then let's override the one we retrieved
17
14
// from the native-side of the app.
18
15
if ( deploymentKey ) {
19
- config . deploymentKey = deploymentKey ;
16
+ config = Object . assign ( { } , configResult , { deploymentKey } ) ;
17
+ } else {
18
+ config = configResult ;
20
19
}
21
20
22
- return getSdk ( ) ;
23
- } )
24
- . then ( ( sdkResult ) => {
25
- sdk = sdkResult ;
21
+ sdk = getSDK ( config ) ;
26
22
// Allow dynamic overwrite of function. This is only to be used for tests.
27
23
return module . exports . getCurrentPackage ( ) ;
28
24
} )
@@ -74,23 +70,6 @@ var getConfiguration = (() => {
74
70
}
75
71
} ) ( ) ;
76
72
77
- var getSdk = ( ( ) => {
78
- var sdk ;
79
- return function getSdk ( ) {
80
- if ( sdk ) {
81
- return Promise . resolve ( sdk ) ;
82
- } else if ( testSdk ) {
83
- return Promise . resolve ( testSdk ) ;
84
- } else {
85
- return getConfiguration ( )
86
- . then ( ( configuration ) => {
87
- sdk = new Sdk ( requestFetchAdapter , configuration ) ;
88
- return sdk ;
89
- } ) ;
90
- }
91
- }
92
- } ) ( ) ;
93
-
94
73
function getCurrentPackage ( ) {
95
74
return new Promise ( ( resolve , reject ) => {
96
75
var localPackage ;
@@ -112,6 +91,14 @@ function getCurrentPackage() {
112
91
} ) ;
113
92
}
114
93
94
+ function getSDK ( config ) {
95
+ if ( testSdk ) {
96
+ return testSdk ;
97
+ } else {
98
+ return new Sdk ( requestFetchAdapter , config ) ;
99
+ }
100
+ }
101
+
115
102
/* Logs messages to console with the [CodePush] prefix */
116
103
function log ( message ) {
117
104
console . log ( `[CodePush] ${ message } ` )
0 commit comments