2015-03-23 20:28:42 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
#import "RCTDataManager.h"
|
|
|
|
|
|
|
|
#import "RCTAssert.h"
|
2015-04-10 03:18:31 +00:00
|
|
|
#import "RCTConvert.h"
|
2015-06-09 19:25:24 +00:00
|
|
|
#import "RCTDataQuery.h"
|
2015-06-05 22:23:30 +00:00
|
|
|
#import "RCTEventDispatcher.h"
|
2015-06-09 19:25:24 +00:00
|
|
|
#import "RCTHTTPQueryExecutor.h"
|
2015-02-20 04:10:52 +00:00
|
|
|
#import "RCTLog.h"
|
|
|
|
#import "RCTUtils.h"
|
|
|
|
|
|
|
|
@implementation RCTDataManager
|
2015-06-05 22:23:30 +00:00
|
|
|
|
|
|
|
@synthesize bridge = _bridge;
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-04-08 12:42:43 +00:00
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
|
|
|
* Executes a network request.
|
|
|
|
* The responseSender block won't be called on same thread as called.
|
|
|
|
*/
|
2015-04-08 15:52:48 +00:00
|
|
|
RCT_EXPORT_METHOD(queryData:(NSString *)queryType
|
2015-04-10 03:18:31 +00:00
|
|
|
withQuery:(NSDictionary *)query
|
2015-06-05 22:23:30 +00:00
|
|
|
sendIncrementalUpdates:(BOOL)incrementalUpdates
|
2015-04-08 15:52:48 +00:00
|
|
|
responseSender:(RCTResponseSenderBlock)responseSender)
|
2015-02-20 04:10:52 +00:00
|
|
|
{
|
2015-06-09 19:25:24 +00:00
|
|
|
id<RCTDataQueryExecutor> executor = nil;
|
2015-02-20 04:10:52 +00:00
|
|
|
if ([queryType isEqualToString:@"http"]) {
|
2015-06-09 19:25:24 +00:00
|
|
|
executor = [RCTHTTPQueryExecutor sharedInstance];
|
2015-05-26 20:29:41 +00:00
|
|
|
} else {
|
|
|
|
RCTLogError(@"unsupported query type %@", queryType);
|
2015-06-09 19:25:24 +00:00
|
|
|
return;
|
2015-05-26 20:29:41 +00:00
|
|
|
}
|
2015-06-05 22:23:30 +00:00
|
|
|
|
2015-06-09 19:25:24 +00:00
|
|
|
RCTAssert(executor != nil, @"executor must be defined");
|
2015-06-05 22:23:30 +00:00
|
|
|
|
2015-06-09 19:25:24 +00:00
|
|
|
if ([executor respondsToSelector:@selector(setBridge:)]) {
|
|
|
|
executor.bridge = _bridge;
|
2015-06-05 22:23:30 +00:00
|
|
|
}
|
2015-06-09 19:25:24 +00:00
|
|
|
if ([executor respondsToSelector:@selector(setSendIncrementalUpdates:)]) {
|
|
|
|
executor.sendIncrementalUpdates = incrementalUpdates;
|
2015-06-05 22:23:30 +00:00
|
|
|
}
|
2015-06-09 19:25:24 +00:00
|
|
|
[executor addQuery:query responseSender:responseSender];
|
2015-06-05 22:23:30 +00:00
|
|
|
}
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
@end
|