mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-02 09:21:44 +08:00
encapsulate JS source in RCTSource object
Reviewed By: alexeylang Differential Revision: D5669734 fbshipit-source-id: 60c798afa2115510a17acf9e970e8ba52507724f
This commit is contained in:
committed by
Facebook Github Bot
parent
b7096c1136
commit
abe7a2a9f1
@@ -22,6 +22,29 @@
|
||||
|
||||
NSString *const RCTJavaScriptLoaderErrorDomain = @"RCTJavaScriptLoaderErrorDomain";
|
||||
|
||||
@interface RCTSource()
|
||||
{
|
||||
@public
|
||||
NSURL *_url;
|
||||
NSData *_data;
|
||||
NSUInteger _length;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RCTSource
|
||||
|
||||
static RCTSource *RCTSourceCreate(NSURL *url, NSData *data, int64_t length) NS_RETURNS_RETAINED
|
||||
{
|
||||
RCTSource *source = [RCTSource new];
|
||||
source->_url = url;
|
||||
source->_data = data;
|
||||
source->_length = length;
|
||||
return source;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RCTLoadingProgress
|
||||
|
||||
- (NSString *)description
|
||||
@@ -51,7 +74,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
sourceLength:&sourceLength
|
||||
error:&error];
|
||||
if (data) {
|
||||
onComplete(nil, data, sourceLength);
|
||||
onComplete(nil, RCTSourceCreate(scriptURL, data, sourceLength));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -62,7 +85,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
if (isCannotLoadSyncError) {
|
||||
attemptAsynchronousLoadOfBundleAtURL(scriptURL, onProgress, onComplete);
|
||||
} else {
|
||||
onComplete(error, nil, 0);
|
||||
onComplete(error, nil);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +216,7 @@ static void attemptAsynchronousLoadOfBundleAtURL(NSURL *scriptURL, RCTSourceLoad
|
||||
NSData *source = [NSData dataWithContentsOfFile:scriptURL.path
|
||||
options:NSDataReadingMappedIfSafe
|
||||
error:&error];
|
||||
onComplete(error, source, source.length);
|
||||
onComplete(error, RCTSourceCreate(scriptURL, source, source.length));
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -224,7 +247,7 @@ static void attemptAsynchronousLoadOfBundleAtURL(NSURL *scriptURL, RCTSourceLoad
|
||||
NSUnderlyingErrorKey: error,
|
||||
}];
|
||||
}
|
||||
onComplete(error, nil, 0);
|
||||
onComplete(error, nil);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -239,7 +262,7 @@ static void attemptAsynchronousLoadOfBundleAtURL(NSURL *scriptURL, RCTSourceLoad
|
||||
error = [NSError errorWithDomain:@"JSServer"
|
||||
code:statusCode
|
||||
userInfo:userInfoForRawResponse([[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding])];
|
||||
onComplete(error, nil, 0);
|
||||
onComplete(error, nil);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -255,11 +278,11 @@ static void attemptAsynchronousLoadOfBundleAtURL(NSURL *scriptURL, RCTSourceLoad
|
||||
@"headers": headers,
|
||||
@"data": data
|
||||
}];
|
||||
onComplete(error, nil, 0);
|
||||
onComplete(error, nil);
|
||||
return;
|
||||
}
|
||||
|
||||
onComplete(nil, data, data.length);
|
||||
onComplete(nil, RCTSourceCreate(scriptURL, data, data.length));
|
||||
} progressHandler:^(NSDictionary *headers, NSNumber *loaded, NSNumber *total) {
|
||||
// Only care about download progress events for the javascript bundle part.
|
||||
if ([headers[@"Content-Type"] isEqualToString:@"application/javascript"]) {
|
||||
|
||||
Reference in New Issue
Block a user