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

Commit 35201d1

Browse files
committed
cache sync calls
1 parent e70516b commit 35201d1

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

CodePush.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,28 @@ function setUpTestDependencies(testSdk, providedTestConfig, testNativeBridge) {
170170
if (testNativeBridge) NativeCodePush = testNativeBridge;
171171
}
172172

173+
// This function allows sync operations to be chained on to each other so that they do not
174+
// interleave in the event that sync() is called multiple times.
175+
const sync = (() => {
176+
let syncPromiseChain = Promise.resolve();
177+
return (options = {}, syncStatusChangeCallback, downloadProgressCallback) => {
178+
syncPromiseChain = syncPromiseChain
179+
.catch(() => {})
180+
.then(() => syncOperation(options, syncStatusChangeCallback, downloadProgressCallback));
181+
return syncPromiseChain;
182+
};
183+
})();
184+
173185
/*
174-
* The sync method provides a simple, one-line experience for
186+
* The syncOperation method provides a simple, one-line experience for
175187
* incorporating the check, download and application of an update.
176188
*
177189
* It simply composes the existing API methods together and adds additional
178190
* support for respecting mandatory updates, ignoring previously failed
179191
* releases, and displaying a standard confirmation UI to the end-user
180192
* when an update is available.
181193
*/
182-
async function sync(options = {}, syncStatusChangeCallback, downloadProgressCallback) {
194+
async function syncOperation(options = {}, syncStatusChangeCallback, downloadProgressCallback) {
183195
const syncOptions = {
184196

185197
deploymentKey: null,

CodePushPackage.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ + (void)copyEntriesInFolder:(NSString *)sourceFolder
449449
}
450450

451451
+ (void)installPackage:(NSDictionary *)updatePackage
452-
error:(NSError **)error
452+
error:(NSError **)error
453453
{
454454
NSString *packageHash = updatePackage[@"packageHash"];
455455
NSMutableDictionary *info = [self getCurrentPackageInfo:error];

Examples/CodePushDemoApp/crossplatformdemo.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,22 @@ let CodePushDemoApp = React.createClass({
9292
render() {
9393
let syncView, syncButton, progressView;
9494

95+
syncButton = (
96+
<Button style={{color: 'green'}} onPress={this.sync}>
97+
Start Sync!
98+
</Button>
99+
);
100+
95101
if (this.state.syncMessage) {
96102
syncView = (
97103
<Text style={styles.messages}>{this.state.syncMessage}</Text>
98104
);
99105
} else {
100-
syncButton = (
106+
/*syncButton = (
101107
<Button style={{color: 'green'}} onPress={this.sync}>
102108
Start Sync!
103109
</Button>
104-
);
110+
);*/
105111
}
106112

107113
if (this.state.progress) {

0 commit comments

Comments
 (0)