cache sync calls

This commit is contained in:
Geoffrey Goh
2016-02-05 15:52:25 -08:00
parent e70516b6c6
commit 35201d1640
3 changed files with 26 additions and 8 deletions

View File

@@ -170,8 +170,20 @@ function setUpTestDependencies(testSdk, providedTestConfig, testNativeBridge) {
if (testNativeBridge) NativeCodePush = testNativeBridge;
}
// This function allows sync operations to be chained on to each other so that they do not
// interleave in the event that sync() is called multiple times.
const sync = (() => {
let syncPromiseChain = Promise.resolve();
return (options = {}, syncStatusChangeCallback, downloadProgressCallback) => {
syncPromiseChain = syncPromiseChain
.catch(() => {})
.then(() => syncOperation(options, syncStatusChangeCallback, downloadProgressCallback));
return syncPromiseChain;
};
})();
/*
* The sync method provides a simple, one-line experience for
* The syncOperation method provides a simple, one-line experience for
* incorporating the check, download and application of an update.
*
* It simply composes the existing API methods together and adds additional
@@ -179,7 +191,7 @@ function setUpTestDependencies(testSdk, providedTestConfig, testNativeBridge) {
* releases, and displaying a standard confirmation UI to the end-user
* when an update is available.
*/
async function sync(options = {}, syncStatusChangeCallback, downloadProgressCallback) {
async function syncOperation(options = {}, syncStatusChangeCallback, downloadProgressCallback) {
const syncOptions = {
deploymentKey: null,

View File

@@ -449,7 +449,7 @@ NSString * const UnzippedFolderName = @"unzipped";
}
+ (void)installPackage:(NSDictionary *)updatePackage
error:(NSError **)error
error:(NSError **)error
{
NSString *packageHash = updatePackage[@"packageHash"];
NSMutableDictionary *info = [self getCurrentPackageInfo:error];

View File

@@ -92,16 +92,22 @@ let CodePushDemoApp = React.createClass({
render() {
let syncView, syncButton, progressView;
if (this.state.syncMessage) {
syncView = (
<Text style={styles.messages}>{this.state.syncMessage}</Text>
);
} else {
syncButton = (
<Button style={{color: 'green'}} onPress={this.sync}>
Start Sync!
</Button>
);
if (this.state.syncMessage) {
syncView = (
<Text style={styles.messages}>{this.state.syncMessage}</Text>
);
} else {
/*syncButton = (
<Button style={{color: 'green'}} onPress={this.sync}>
Start Sync!
</Button>
);*/
}
if (this.state.progress) {