Removed redundant JSON encode/decode from RCTDataManager

Summary:
@public

For some reason we were manually JSON-encoding the RCTDataManager responses, and then decoding them again on the JS side. Since all data sent over the bridge is JSON-encoded anyway, this is pretty pointless.

Test Plan:
* Test Movies app in OSS, which uses RCTDataManager
* Test any code that uses RKHTTPQueryGenericExecutor to make network requests (e.g. Groups)
* Test the Groups photo upload feature, which uses RKHTTPQueryWithImageUploadExecutor
This commit is contained in:
Nick Lockwood 2015-06-01 08:28:31 -07:00
Родитель b03446e27e
Коммит a2db4a4a5b
3 изменённых файлов: 20 добавлений и 22 удалений

Просмотреть файл

@ -17,6 +17,6 @@
int main(int argc, char * argv[]) { int main(int argc, char * argv[]) {
@autoreleasepool { @autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
} }
} }

Просмотреть файл

@ -39,34 +39,35 @@ RCT_EXPORT_METHOD(queryData:(NSString *)queryType
// Build data task // Build data task
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *connectionError) { NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *connectionError) {
NSHTTPURLResponse *httpResponse = nil;
if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
// Might be a local file request
httpResponse = (NSHTTPURLResponse *)response;
}
// Build response // Build response
NSDictionary *responseJSON; NSArray *responseJSON;
if (connectionError == nil) { if (connectionError == nil) {
NSStringEncoding encoding = NSUTF8StringEncoding; NSStringEncoding encoding = NSUTF8StringEncoding;
if (response.textEncodingName) { if (response.textEncodingName) {
CFStringEncoding cfEncoding = CFStringConvertIANACharSetNameToEncoding((CFStringRef)response.textEncodingName); CFStringEncoding cfEncoding = CFStringConvertIANACharSetNameToEncoding((CFStringRef)response.textEncodingName);
encoding = CFStringConvertEncodingToNSStringEncoding(cfEncoding); encoding = CFStringConvertEncodingToNSStringEncoding(cfEncoding);
} }
NSHTTPURLResponse *httpResponse = nil; responseJSON = @[
if ([response isKindOfClass:[NSHTTPURLResponse class]]) { @(httpResponse.statusCode ?: 200),
// Might be a local file request httpResponse.allHeaderFields ?: @{},
httpResponse = (NSHTTPURLResponse *)response; [[NSString alloc] initWithData:data encoding:encoding] ?: @"",
} ];
responseJSON = @{
@"status": @([httpResponse statusCode] ?: 200),
@"responseHeaders": [httpResponse allHeaderFields] ?: @{},
@"responseText": [[NSString alloc] initWithData:data encoding:encoding] ?: @""
};
} else { } else {
responseJSON = @{ responseJSON = @[
@"status": @0, @(httpResponse.statusCode),
@"responseHeaders": @{}, httpResponse.allHeaderFields ?: @{},
@"responseText": [connectionError localizedDescription] ?: [NSNull null] connectionError.localizedDescription ?: [NSNull null],
}; ];
} }
// Send response (won't be sent on same thread as caller) // Send response (won't be sent on same thread as caller)
responseSender(@[RCTJSONStringify(responseJSON, NULL)]); responseSender(responseJSON);
}]; }];

Просмотреть файл

@ -30,10 +30,7 @@ class XMLHttpRequest extends XMLHttpRequestBase {
}, },
// TODO: Do we need this? is it used anywhere? // TODO: Do we need this? is it used anywhere?
'h' + crc32(method + '|' + url + '|' + data), 'h' + crc32(method + '|' + url + '|' + data),
(result) => { this.callback.bind(this)
result = JSON.parse(result);
this.callback(result.status, result.responseHeaders, result.responseText);
}
); );
} }