Skip to content

Commit

Permalink
Replaced RCTSparseArray with NSDictionary
Browse files Browse the repository at this point in the history
Reviewed By: jspahrsummers

Differential Revision: D2651920

fb-gh-sync-id: 953e2ea33abfc7a3a553da95b13e9ab2bccc5a1c
  • Loading branch information
nicklockwood authored and facebook-github-bot-4 committed Nov 14, 2015
1 parent 5a34a09 commit fa0b45c
Show file tree
Hide file tree
Showing 67 changed files with 338 additions and 547 deletions.
16 changes: 12 additions & 4 deletions Examples/UIExplorer/UIExplorer.xcodeproj/project.pbxproj
Expand Up @@ -32,7 +32,6 @@
1497CFAF1B21F5E400C1F8F2 /* RCTConvert_NSURLTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1497CFA71B21F5E400C1F8F2 /* RCTConvert_NSURLTests.m */; };
1497CFB01B21F5E400C1F8F2 /* RCTConvert_UIFontTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1497CFA81B21F5E400C1F8F2 /* RCTConvert_UIFontTests.m */; };
1497CFB11B21F5E400C1F8F2 /* RCTEventDispatcherTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1497CFA91B21F5E400C1F8F2 /* RCTEventDispatcherTests.m */; };
1497CFB21B21F5E400C1F8F2 /* RCTSparseArrayTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1497CFAA1B21F5E400C1F8F2 /* RCTSparseArrayTests.m */; };
1497CFB31B21F5E400C1F8F2 /* RCTUIManagerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1497CFAB1B21F5E400C1F8F2 /* RCTUIManagerTests.m */; };
14AADF051AC3DBB1002390C9 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 14AADF041AC3DB95002390C9 /* libReact.a */; };
14B6DA821B276C5900BF4DD1 /* libRCTTest.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 58005BEE1ABA80530062E044 /* libRCTTest.a */; };
Expand Down Expand Up @@ -209,7 +208,6 @@
1497CFA71B21F5E400C1F8F2 /* RCTConvert_NSURLTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTConvert_NSURLTests.m; sourceTree = "<group>"; };
1497CFA81B21F5E400C1F8F2 /* RCTConvert_UIFontTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTConvert_UIFontTests.m; sourceTree = "<group>"; };
1497CFA91B21F5E400C1F8F2 /* RCTEventDispatcherTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTEventDispatcherTests.m; sourceTree = "<group>"; };
1497CFAA1B21F5E400C1F8F2 /* RCTSparseArrayTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTSparseArrayTests.m; sourceTree = "<group>"; };
1497CFAB1B21F5E400C1F8F2 /* RCTUIManagerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTUIManagerTests.m; sourceTree = "<group>"; };
14AADEFF1AC3DB95002390C9 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = ../../React/React.xcodeproj; sourceTree = "<group>"; };
14D6D7021B220AE3001FB087 /* NSNotificationCenter+OCMAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSNotificationCenter+OCMAdditions.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -400,7 +398,6 @@
13DF61B51B67A45000EDB188 /* RCTMethodArgumentTests.m */,
1393D0371B68CD1300E1B601 /* RCTModuleMethodTests.m */,
138D6A161B53CD440074A87E /* RCTShadowViewTests.m */,
1497CFAA1B21F5E400C1F8F2 /* RCTSparseArrayTests.m */,
1497CFAB1B21F5E400C1F8F2 /* RCTUIManagerTests.m */,
143BC57E1B21E18100462512 /* Info.plist */,
14D6D7101B220EB3001FB087 /* libOCMock.a */,
Expand Down Expand Up @@ -852,7 +849,6 @@
1497CFB01B21F5E400C1F8F2 /* RCTConvert_UIFontTests.m in Sources */,
144D21241B2204C5006DB32B /* RCTImageUtilTests.m in Sources */,
1393D0381B68CD1300E1B601 /* RCTModuleMethodTests.m in Sources */,
1497CFB21B21F5E400C1F8F2 /* RCTSparseArrayTests.m in Sources */,
1300627F1B59179B0043FE5A /* RCTGzipTests.m in Sources */,
1497CFAF1B21F5E400C1F8F2 /* RCTConvert_NSURLTests.m in Sources */,
1497CFAE1B21F5E400C1F8F2 /* RCTContextExecutorTests.m in Sources */,
Expand Down Expand Up @@ -991,6 +987,12 @@
PRODUCT_BUNDLE_IDENTIFIER = com.facebook.internal.uiexplorer.local;
PRODUCT_NAME = UIExplorer;
TARGETED_DEVICE_FAMILY = "1,2";
WARNING_CFLAGS = (
"-Wextra",
"-Wall",
"-Wincompatible-pointer-types",
"-Wincompatible-pointer-types-discards-qualifiers",
);
};
name = Debug;
};
Expand All @@ -1011,6 +1013,12 @@
PRODUCT_BUNDLE_IDENTIFIER = com.facebook.internal.uiexplorer.local;
PRODUCT_NAME = UIExplorer;
TARGETED_DEVICE_FAMILY = "1,2";
WARNING_CFLAGS = (
"-Wextra",
"-Wall",
"-Wincompatible-pointer-types",
"-Wincompatible-pointer-types-discards-qualifiers",
);
};
name = Release;
};
Expand Down
Expand Up @@ -14,7 +14,6 @@

#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import "RCTSparseArray.h"
#import "RCTUIManager.h"
#import "UIView+React.h"

Expand All @@ -26,9 +25,9 @@ - (void)_manageChildren:(NSNumber *)containerReactTag
addChildReactTags:(NSArray *)addChildReactTags
addAtIndices:(NSArray *)addAtIndices
removeAtIndices:(NSArray *)removeAtIndices
registry:(RCTSparseArray *)registry;
registry:(NSMutableDictionary<NSNumber *, id<RCTComponent>> *)registry;

@property (nonatomic, readonly) RCTSparseArray *viewRegistry;
@property (nonatomic, readonly) NSMutableDictionary<NSNumber *, UIView *> *viewRegistry;

@end

Expand All @@ -50,13 +49,13 @@ - (void)setUp
for (NSInteger i = 1; i <= 20; i++) {
UIView *registeredView = [UIView new];
registeredView.reactTag = @(i);
_uiManager.viewRegistry[i] = registeredView;
_uiManager.viewRegistry[@(i)] = registeredView;
}
}

- (void)testManagingChildrenToAddViews
{
UIView *containerView = _uiManager.viewRegistry[20];
UIView *containerView = _uiManager.viewRegistry[@20];
NSMutableArray *addedViews = [NSMutableArray array];

NSArray *tagsToAdd = @[@1, @2, @3, @4, @5];
Expand All @@ -72,7 +71,7 @@ - (void)testManagingChildrenToAddViews
addChildReactTags:tagsToAdd
addAtIndices:addAtIndices
removeAtIndices:nil
registry:_uiManager.viewRegistry];
registry:(NSMutableDictionary<NSNumber *, id<RCTComponent>> *)_uiManager.viewRegistry];

XCTAssertTrue([[containerView reactSubviews] count] == 5,
@"Expect to have 5 react subviews after calling manage children \
Expand All @@ -86,7 +85,7 @@ - (void)testManagingChildrenToAddViews

- (void)testManagingChildrenToRemoveViews
{
UIView *containerView = _uiManager.viewRegistry[20];
UIView *containerView = _uiManager.viewRegistry[@20];
NSMutableArray *removedViews = [NSMutableArray array];

NSArray *removeAtIndices = @[@0, @4, @8, @12, @16];
Expand All @@ -95,7 +94,7 @@ - (void)testManagingChildrenToRemoveViews
[removedViews addObject:_uiManager.viewRegistry[reactTag]];
}
for (NSInteger i = 2; i < 20; i++) {
UIView *view = _uiManager.viewRegistry[i];
UIView *view = _uiManager.viewRegistry[@(i)];
[containerView addSubview:view];
}

Expand All @@ -106,7 +105,7 @@ - (void)testManagingChildrenToRemoveViews
addChildReactTags:nil
addAtIndices:nil
removeAtIndices:removeAtIndices
registry:_uiManager.viewRegistry];
registry:(NSMutableDictionary<NSNumber *, id<RCTComponent>> *)_uiManager.viewRegistry];

XCTAssertEqual(containerView.reactSubviews.count, (NSUInteger)13,
@"Expect to have 13 react subviews after calling manage children\
Expand All @@ -119,7 +118,7 @@ - (void)testManagingChildrenToRemoveViews
_uiManager.viewRegistry[view.reactTag] = view;
}
for (NSInteger i = 2; i < 20; i++) {
UIView *view = _uiManager.viewRegistry[i];
UIView *view = _uiManager.viewRegistry[@(i)];
if (![removedViews containsObject:view]) {
XCTAssertTrue([view superview] == containerView,
@"Should not have removed view with react tag %ld during delete but did", (long)i);
Expand All @@ -138,7 +137,7 @@ - (void)testManagingChildrenToRemoveViews
// [11,5,1,2,7,8,12,10]
- (void)testManagingChildrenToAddRemoveAndMove
{
UIView *containerView = _uiManager.viewRegistry[20];
UIView *containerView = _uiManager.viewRegistry[@20];

NSArray *removeAtIndices = @[@2, @3, @5, @8];
NSArray *addAtIndices = @[@0, @6];
Expand All @@ -155,7 +154,7 @@ - (void)testManagingChildrenToAddRemoveAndMove
}

for (NSInteger i = 1; i < 11; i++) {
UIView *view = _uiManager.viewRegistry[i];
UIView *view = _uiManager.viewRegistry[@(i)];
[containerView addSubview:view];
}

Expand All @@ -165,7 +164,7 @@ - (void)testManagingChildrenToAddRemoveAndMove
addChildReactTags:tagsToAdd
addAtIndices:addAtIndices
removeAtIndices:removeAtIndices
registry:_uiManager.viewRegistry];
registry:(NSMutableDictionary<NSNumber *, id<RCTComponent>> *)_uiManager.viewRegistry];

XCTAssertTrue([[containerView reactSubviews] count] == 8,
@"Expect to have 8 react subviews after calling manage children,\
Expand All @@ -180,7 +179,7 @@ - (void)testManagingChildrenToAddRemoveAndMove

// Clean up after ourselves
for (NSInteger i = 1; i < 13; i++) {
UIView *view = _uiManager.viewRegistry[i];
UIView *view = _uiManager.viewRegistry[@(i)];
[view removeFromSuperview];
}
for (UIView *view in viewsToRemove) {
Expand Down
8 changes: 4 additions & 4 deletions Examples/UIExplorer/UIExplorerUnitTests/RCTBridgeTests.m
Expand Up @@ -31,7 +31,7 @@ - (void)setUp;

@interface TestExecutor : NSObject <RCTJavaScriptExecutor>

@property (nonatomic, readonly, copy) NSMutableDictionary *injectedStuff;
@property (nonatomic, readonly, copy) NSMutableDictionary<NSString *, id> *injectedStuff;

@end

Expand Down Expand Up @@ -137,7 +137,7 @@ - (void)testHookRegistration
RUN_RUNLOOP_WHILE(!(injectedStuff = executor.injectedStuff[@"__fbBatchedBridgeConfig"]));

__block NSNumber *testModuleID = nil;
__block NSDictionary *testConstants = nil;
__block NSDictionary<NSString *, id> *testConstants = nil;
__block NSNumber *testMethodID = nil;

NSArray *remoteModuleConfig = RCTJSONParse(injectedStuff, NULL)[@"remoteModuleConfig"];
Expand Down Expand Up @@ -165,7 +165,7 @@ - (void)testCallNativeMethod
RUN_RUNLOOP_WHILE(!(injectedStuff = executor.injectedStuff[@"__fbBatchedBridgeConfig"]));

__block NSNumber *testModuleID = nil;
__block NSDictionary *testConstants = nil;
__block NSDictionary<NSString *, id> *testConstants = nil;
__block NSNumber *testMethodID = nil;

NSArray *remoteModuleConfig = RCTJSONParse(injectedStuff, NULL)[@"remoteModuleConfig"];
Expand Down Expand Up @@ -211,7 +211,7 @@ - (void)DISABLED_testBadArgumentsCount
XCTAssertNotNil(callback);
}

- (NSDictionary *)constantsToExport
- (NSDictionary<NSString *, id> *)constantsToExport
{
return @{@"eleventyMillion": @42};
}
Expand Down
Expand Up @@ -26,7 +26,7 @@ @interface RCTTestEvent : RCTBaseEvent

@implementation RCTTestEvent

- (instancetype)initWithViewTag:(NSNumber *)viewTag eventName:(NSString *)eventName body:(NSDictionary *)body
- (instancetype)initWithViewTag:(NSNumber *)viewTag eventName:(NSString *)eventName body:(NSDictionary<NSString *, id> *)body
{
if (self = [super initWithViewTag:viewTag eventName:eventName body:body]) {
self.canCoalesce = YES;
Expand All @@ -50,7 +50,7 @@ @implementation RCTEventDispatcherTests
RCTEventDispatcher *_eventDispatcher;

NSString *_eventName;
NSDictionary *_body;
NSDictionary<NSString *, id> *_body;
RCTTestEvent *_testEvent;
NSString *_JSMethod;
}
Expand Down
2 changes: 1 addition & 1 deletion Examples/UIExplorer/UIExplorerUnitTests/RCTGzipTests.m
Expand Up @@ -20,7 +20,7 @@

@interface RCTNetworking (Private)

- (void)buildRequest:(NSDictionary *)query
- (void)buildRequest:(NSDictionary<NSString *, id> *)query
completionBlock:(void (^)(NSURLRequest *request))block;

@end
Expand Down
12 changes: 6 additions & 6 deletions Examples/UIExplorer/UIExplorerUnitTests/RCTJSONTests.m
Expand Up @@ -23,14 +23,14 @@ @implementation RCTJSONTests

- (void)testEncodingObject
{
NSDictionary *obj = @{@"foo": @"bar"};
NSDictionary<NSString *, id> *obj = @{@"foo": @"bar"};
NSString *json = @"{\"foo\":\"bar\"}";
XCTAssertEqualObjects(json, RCTJSONStringify(obj, NULL));
}

- (void)testEncodingArray
{
NSArray *array = @[@"foo", @"bar"];
NSArray<id> *array = @[@"foo", @"bar"];
NSString *json = @"[\"foo\",\"bar\"]";
XCTAssertEqualObjects(json, RCTJSONStringify(array, NULL));
}
Expand All @@ -44,14 +44,14 @@ - (void)testEncodingString

- (void)testDecodingObject
{
NSDictionary *obj = @{@"foo": @"bar"};
NSDictionary<NSString *, id> *obj = @{@"foo": @"bar"};
NSString *json = @"{\"foo\":\"bar\"}";
XCTAssertEqualObjects(obj, RCTJSONParse(json, NULL));
}

- (void)testDecodingArray
{
NSArray *array = @[@"foo", @"bar"];
NSArray<id> *array = @[@"foo", @"bar"];
NSString *json = @"[\"foo\",\"bar\"]";
XCTAssertEqualObjects(array, RCTJSONParse(json, NULL));
}
Expand All @@ -66,14 +66,14 @@ - (void)testDecodingString
- (void)testDecodingMutableArray
{
NSString *json = @"[1,2,3]";
NSMutableArray *array = RCTJSONParseMutable(json, NULL);
NSMutableArray<id> *array = RCTJSONParseMutable(json, NULL);
XCTAssertNoThrow([array addObject:@4]);
XCTAssertEqualObjects(array, (@[@1, @2, @3, @4]));
}

- (void)testLeadingWhitespace
{
NSDictionary *obj = @{@"foo": @"bar"};
NSDictionary<NSString *, id> *obj = @{@"foo": @"bar"};
NSString *json = @" \r\n\t{\"foo\":\"bar\"}";
XCTAssertEqualObjects(obj, RCTJSONParse(json, NULL));
}
Expand Down
55 changes: 0 additions & 55 deletions Examples/UIExplorer/UIExplorerUnitTests/RCTSparseArrayTests.m

This file was deleted.

0 comments on commit fa0b45c

Please sign in to comment.