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

Commit b9f3b25

Browse files
committed
feedback
1 parent b21d22c commit b9f3b25

File tree

4 files changed

+70
-70
lines changed

4 files changed

+70
-70
lines changed

CodePushDownloadHandler.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLRespons
4444
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
4545
self.receivedContentLength = self.receivedContentLength + [data length];
4646

47-
NSUInteger bytesLeft = [data length];
47+
NSInteger bytesLeft = [data length];
4848

4949
do {
50-
NSUInteger bytesWritten = [self.outputFileStream write:[data bytes]
50+
NSInteger bytesWritten = [self.outputFileStream write:[data bytes]
5151
maxLength:bytesLeft];
5252
if (bytesWritten == -1) {
5353
break;
@@ -59,21 +59,21 @@ -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
5959
self.progressCallback(self.expectedContentLength, self.receivedContentLength);
6060

6161
if (bytesLeft) {
62-
self.failCallback([self.outputFileStream streamError]);
6362
[self.outputFileStream close];
6463
[connection cancel];
64+
self.failCallback([self.outputFileStream streamError]);
6565
}
6666
}
6767

6868
- (void)connection:(NSURLConnection*)connection didFailWithError:(NSError*)error
6969
{
70-
self.failCallback(error);
7170
[self.outputFileStream close];
71+
self.failCallback(error);
7272
}
7373

7474
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
75-
self.doneCallback();
7675
[self.outputFileStream close];
76+
self.doneCallback();
7777
}
7878

7979
@end

CodePushPackage.m

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ + (void)downloadPackage:(NSDictionary *)updatePackage
154154
failCallback:(void (^)(NSError *err))failCallback
155155
{
156156
NSString *packageFolderPath = [self getPackageFolderPath:updatePackage[@"packageHash"]];
157-
158157
NSError *error;
158+
159159
if (![[NSFileManager defaultManager] fileExistsAtPath:packageFolderPath]) {
160160
[[NSFileManager defaultManager] createDirectoryAtPath:packageFolderPath
161161
withIntermediateDirectories:YES
@@ -167,31 +167,31 @@ + (void)downloadPackage:(NSDictionary *)updatePackage
167167
return failCallback(error);
168168
}
169169

170-
NSString *downloadFilePath = [packageFolderPath stringByAppendingPathComponent:@"app.jsbundle"];
170+
NSString *updateBundleFileName = [packageFolderPath stringByAppendingPathComponent:@"app.jsbundle"];
171171

172172
CodePushDownloadHandler *downloadHandler = [[CodePushDownloadHandler alloc]
173-
init:downloadFilePath
174-
progressCallback:progressCallback
175-
doneCallback:^{
176-
NSError *error;
177-
NSData *updateSerializedData = [NSJSONSerialization
178-
dataWithJSONObject:updatePackage
179-
options:0
180-
error:&error];
181-
NSString *packageJsonString = [[NSString alloc]
182-
initWithData:updateSerializedData encoding:NSUTF8StringEncoding];
183-
184-
[packageJsonString writeToFile:[packageFolderPath stringByAppendingPathComponent:@"app.json"]
185-
atomically:YES
186-
encoding:NSUTF8StringEncoding
187-
error:&error];
188-
if (error) {
189-
failCallback(error);
190-
} else {
191-
doneCallback();
192-
}
193-
}
194-
failCallback:failCallback];
173+
init:updateBundleFileName
174+
progressCallback:progressCallback
175+
doneCallback:^{
176+
NSError *error;
177+
NSData *updateSerializedData = [NSJSONSerialization
178+
dataWithJSONObject:updatePackage
179+
options:0
180+
error:&error];
181+
NSString *packageJsonString = [[NSString alloc]
182+
initWithData:updateSerializedData encoding:NSUTF8StringEncoding];
183+
184+
[packageJsonString writeToFile:[packageFolderPath stringByAppendingPathComponent:@"app.json"]
185+
atomically:YES
186+
encoding:NSUTF8StringEncoding
187+
error:&error];
188+
if (error) {
189+
failCallback(error);
190+
} else {
191+
doneCallback();
192+
}
193+
}
194+
failCallback:failCallback];
195195

196196
[downloadHandler download:updatePackage[@"downloadUrl"]];
197197
}

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?: 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`.
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 until the download completes. Returns a Promise that resolves with the `LocalPackage`.
269269

270270
---
271271

package-mixins.js

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
var extend = require("extend");
2-
var { NativeAppEventEmitter } = require('react-native');
2+
var { NativeAppEventEmitter } = require("react-native");
33

44
module.exports = (NativeCodePush) => {
5-
var remote = {
6-
abortDownload: function abortDownload() {
7-
return NativeCodePush.abortDownload(this);
8-
},
9-
download: function download(progressHandler) {
10-
if (!this.downloadUrl) {
11-
return Promise.reject(new Error("Cannot download an update without a download url"));
12-
}
5+
var remote = {
6+
abortDownload: function abortDownload() {
7+
return NativeCodePush.abortDownload(this);
8+
},
9+
download: function download(progressHandler) {
10+
if (!this.downloadUrl) {
11+
return Promise.reject(new Error("Cannot download an update without a download url"));
12+
}
1313

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

23-
// Use the downloaded package info. Native code will save the package info
24-
// so that the client knows what the current package version is.
25-
return NativeCodePush.downloadUpdate(this)
26-
.then((downloadedPackage) => {
27-
downloadProgressSubscription && downloadProgressSubscription.remove();
28-
return extend({}, downloadedPackage, local);
29-
})
30-
.catch((error) => {
31-
downloadProgressSubscription && downloadProgressSubscription.remove();
32-
// Rethrow the error for subsequent handlers down the promise chain.
33-
throw error;
34-
});
35-
}
36-
};
23+
// Use the downloaded package info. Native code will save the package info
24+
// so that the client knows what the current package version is.
25+
return NativeCodePush.downloadUpdate(this)
26+
.then((downloadedPackage) => {
27+
downloadProgressSubscription && downloadProgressSubscription.remove();
28+
return extend({}, downloadedPackage, local);
29+
})
30+
.catch((error) => {
31+
downloadProgressSubscription && downloadProgressSubscription.remove();
32+
// Rethrow the error for subsequent handlers down the promise chain.
33+
throw error;
34+
});
35+
}
36+
};
3737

38-
var local = {
39-
apply: function apply(rollbackTimeout = 0, restartImmediately = true) {
40-
return NativeCodePush.applyUpdate(this, rollbackTimeout, restartImmediately);
41-
}
42-
};
38+
var local = {
39+
apply: function apply(rollbackTimeout = 0, restartImmediately = true) {
40+
return NativeCodePush.applyUpdate(this, rollbackTimeout, restartImmediately);
41+
}
42+
};
4343

44-
return {
45-
remote: remote,
46-
local: local
47-
};
44+
return {
45+
remote: remote,
46+
local: local
47+
};
4848
};

0 commit comments

Comments
 (0)