mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-19 18:13:46 +08:00
cache sync calls
This commit is contained in:
16
CodePush.js
16
CodePush.js
@@ -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,
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user