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

Commit 3e34394

Browse files
committed
Updated the sync method's API reference in the README.md
Signed-off-by: Clovis Durand <cd.clovel19@gmail.com>
1 parent a0b1877 commit 3e34394

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

README.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ While the `sync` method tries to make it easy to perform silent and active updat
415415

416416
- __updateTitle__ *(String)* - The text used as the header of an update notification that is displayed to the end user. Defaults to `"Update available"`.
417417

418+
- __onSyncStatusChanged__ *(`SuccessCallback<SyncStatus>`)* - A custom callback that is called when the `SyncStatus` changes.
419+
420+
- __onSyncError__ *(`ErrorCallback`)* - A custom callback that is called on a sync process error.
421+
418422
Example Usage:
419423

420424
```javascript
@@ -441,26 +445,29 @@ codePush.sync({
441445
installMode: InstallMode.IMMEDIATE
442446
});
443447

444-
// Silently check for the update, but
445-
// display a custom downloading UI
446-
// via the SyncStatus and DownloadProgress callbacks
447-
codePush.sync(null, downloadProgress).then(status => {
448-
switch (status) {
449-
case SyncStatus.DOWNLOADING_PACKAGE:
450-
// Show "downloading" modal
451-
break;
452-
case SyncStatus.INSTALLING_UPDATE:
453-
// Hide "downloading" modal
454-
break;
455-
}
456-
});
457-
458-
function downloadProgress(downloadProgress) {
448+
const downloadProgress = (downloadProgress) => {
459449
if (downloadProgress) {
460450
// Update "downloading" modal with current download %
461451
//console.log("Downloading " + downloadProgress.receivedBytes + " of " + downloadProgress.totalBytes);
462452
}
463453
}
454+
455+
// Silently check for the update, but
456+
// display a custom downloading UI
457+
// via the SyncStatus and DownloadProgress callbacks
458+
codePush.sync(null, downloadProgress)
459+
.then(
460+
(status) => {
461+
switch (status) {
462+
case SyncStatus.DOWNLOADING_PACKAGE:
463+
// Show "downloading" modal
464+
break;
465+
case SyncStatus.INSTALLING_UPDATE:
466+
// Hide "downloading" modal
467+
break;
468+
}
469+
}
470+
);
464471
```
465472

466473
The `sync` method can be called anywhere you'd like to check for an update. That could be in the `deviceready` event handler, the `click` event of a button, in the callback of a periodic timer, or whatever else makes sense for your needs. Just like the `checkForUpdate` method, it will perform the network request to check for an update in the background, so it won't impact your UI thread and/or JavaScript thread's responsiveness.

0 commit comments

Comments
 (0)