From 78238071fe1ee7b725b81ed1871d64607a081908 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Thu, 12 Nov 2015 22:14:49 -0800 Subject: [PATCH] docs --- README.md | 2 +- package-mixins.js | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a19fae5..e16df2b 100644 --- a/README.md +++ b/README.md @@ -265,7 +265,7 @@ The `RemotePackage` inherits all of the same properties as the `LocalPackage`, b - __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. ##### Methods -- __download(progressHandler): Promise__: 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`. +- __download(progressHandler?: Function): Promise__: 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`. --- diff --git a/package-mixins.js b/package-mixins.js index 1bdb07b..5e8116b 100644 --- a/package-mixins.js +++ b/package-mixins.js @@ -11,21 +11,24 @@ module.exports = (NativeCodePush) => { return Promise.reject(new Error("Cannot download an update without a download url")); } - // Use event subscription to obtain download progress. - var downloadProgressSubscription = NativeAppEventEmitter.addListener( - 'CodePushDownloadProgress', - progressHandler - ); + var downloadProgressSubscription; + if (progressHandler) { + // Use event subscription to obtain download progress. + downloadProgressSubscription = NativeAppEventEmitter.addListener( + 'CodePushDownloadProgress', + progressHandler + ); + } // Use the downloaded package info. Native code will save the package info // so that the client knows what the current package version is. return NativeCodePush.downloadUpdate(this) .then((downloadedPackage) => { - downloadProgressSubscription.remove(); + downloadProgressSubscription && downloadProgressSubscription.remove(); return extend({}, downloadedPackage, local); }) .catch((error) => { - downloadProgressSubscription.remove(); + downloadProgressSubscription && downloadProgressSubscription.remove(); // Rethrow the error for subsequent handlers down the promise chain. throw error; });