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

Commit 7823807

Browse files
committed
docs
1 parent e42a3c5 commit 7823807

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ The `RemotePackage` inherits all of the same properties as the `LocalPackage`, b
265265
- __downloadUrl__: The URL at which the package is available for download. (String). This property is only needed for advanced usage, since the `download` method will automatically handle the acquisition of updates for you.
266266

267267
##### Methods
268-
- __download(progressHandler): Promise<LocalPackage>__: Downloads the package update from the CodePush service. If a `progressHandler` is specified, it will be called periodically with an object (`{ totalBytes: Number, receivedBytes: Number }`) that reports the progress of the download till the download completes. Returns a Promise that resolves with the `LocalPackage`.
268+
- __download(progressHandler?: Function): Promise<LocalPackage>__: Downloads the package update from the CodePush service. If a `progressHandler` is specified, it will be called periodically with an object (`{ totalBytes: Number, receivedBytes: Number }`) that reports the progress of the download till the download completes. Returns a Promise that resolves with the `LocalPackage`.
269269

270270
---
271271

package-mixins.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,24 @@ module.exports = (NativeCodePush) => {
1111
return Promise.reject(new Error("Cannot download an update without a download url"));
1212
}
1313

14-
// Use event subscription to obtain download progress.
15-
var downloadProgressSubscription = NativeAppEventEmitter.addListener(
16-
'CodePushDownloadProgress',
17-
progressHandler
18-
);
14+
var downloadProgressSubscription;
15+
if (progressHandler) {
16+
// Use event subscription to obtain download progress.
17+
downloadProgressSubscription = NativeAppEventEmitter.addListener(
18+
'CodePushDownloadProgress',
19+
progressHandler
20+
);
21+
}
1922

2023
// Use the downloaded package info. Native code will save the package info
2124
// so that the client knows what the current package version is.
2225
return NativeCodePush.downloadUpdate(this)
2326
.then((downloadedPackage) => {
24-
downloadProgressSubscription.remove();
27+
downloadProgressSubscription && downloadProgressSubscription.remove();
2528
return extend({}, downloadedPackage, local);
2629
})
2730
.catch((error) => {
28-
downloadProgressSubscription.remove();
31+
downloadProgressSubscription && downloadProgressSubscription.remove();
2932
// Rethrow the error for subsequent handlers down the promise chain.
3033
throw error;
3134
});

0 commit comments

Comments
 (0)