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[]) {
@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
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
NSDictionary *responseJSON;
NSArray *responseJSON;
if (connectionError == nil) {
NSStringEncoding encoding = NSUTF8StringEncoding;
if (response.textEncodingName) {
CFStringEncoding cfEncoding = CFStringConvertIANACharSetNameToEncoding((CFStringRef)response.textEncodingName);
encoding = CFStringConvertEncodingToNSStringEncoding(cfEncoding);
}
NSHTTPURLResponse *httpResponse = nil;
if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
// Might be a local file request
httpResponse = (NSHTTPURLResponse *)response;
}
responseJSON = @{
@"status": @([httpResponse statusCode] ?: 200),
@"responseHeaders": [httpResponse allHeaderFields] ?: @{},
@"responseText": [[NSString alloc] initWithData:data encoding:encoding] ?: @""
};
responseJSON = @[
@(httpResponse.statusCode ?: 200),
httpResponse.allHeaderFields ?: @{},
[[NSString alloc] initWithData:data encoding:encoding] ?: @"",
];
} else {
responseJSON = @{
@"status": @0,
@"responseHeaders": @{},
@"responseText": [connectionError localizedDescription] ?: [NSNull null]
};
responseJSON = @[
@(httpResponse.statusCode),
httpResponse.allHeaderFields ?: @{},
connectionError.localizedDescription ?: [NSNull null],
];
}
// 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?
'h' + crc32(method + '|' + url + '|' + data),
(result) => {
result = JSON.parse(result);
this.callback(result.status, result.responseHeaders, result.responseText);
}
this.callback.bind(this)
);
}