Skip to content

Commit

Permalink
Rename isEqualToComponent: to shouldComponentUpdate: to align it with…
Browse files Browse the repository at this point in the history
… React

Summary: Align our Reuse components API with React to make it clearer.

Reviewed By: fabiomassimo

Differential Revision: D9920055

fbshipit-source-id: 91bcdb973c59aeb09bede968752255db71fd098e
  • Loading branch information
kfirapps authored and facebook-github-bot committed Sep 19, 2018
1 parent e03a61f commit 281ae39
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
+ (id)initialStateWithComponent:(id<CKRenderComponentProtocol>)component;

/*
Override this method in order to allow the infrastructure to reuse previous components.
Override this method in order to allow ComopnentKit to reuse the previous components.
You can always assume that the `component` parameter is the same type as your component.
The default value is `NO`
The default value is `YES`.
*/
- (BOOL)isEqualToComponent:(id<CKRenderComponentProtocol>)component;
- (BOOL)shouldComponentUpdate:(id<CKRenderComponentProtocol>)component;

/*
This method is being called when the infrasturcture reuses the previous generation of the component.
Expand Down
4 changes: 2 additions & 2 deletions ComponentKit/Core/Render/CKRenderComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ + (id)initialState
return [CKTreeNodeEmptyState emptyState];
}

- (BOOL)isEqualToComponent:(id<CKRenderComponentProtocol>)component
- (BOOL)shouldComponentUpdate:(id<CKRenderComponentProtocol>)component
{
return NO;
return YES;
}

- (void)didReuseComponent:(id<CKRenderComponentProtocol>)component {}
Expand Down
4 changes: 2 additions & 2 deletions ComponentKit/Core/Render/CKRenderLayoutComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ + (id)initialState
return [CKTreeNodeEmptyState emptyState];
}

- (BOOL)isEqualToComponent:(id<CKRenderComponentProtocol>)component
- (BOOL)shouldComponentUpdate:(id<CKRenderComponentProtocol>)component
{
return NO;
return YES;
}

- (void)didReuseComponent:(id<CKRenderComponentProtocol>)component {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ + (id)initialState
return [CKTreeNodeEmptyState emptyState];
}

- (BOOL)isEqualToComponent:(id<CKRenderComponentProtocol>)component
- (BOOL)shouldComponentUpdate:(id<CKRenderComponentProtocol>)component
{
return NO;
return YES;
}

- (void)didReuseComponent:(id<CKRenderComponentProtocol>)component {}
Expand Down
4 changes: 2 additions & 2 deletions ComponentKit/Core/Render/CKRenderWithChildrenComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ + (id)initialState
return [CKTreeNodeEmptyState emptyState];
}

- (BOOL)isEqualToComponent:(id<CKRenderComponentProtocol>)component
- (BOOL)shouldComponentUpdate:(id<CKRenderComponentProtocol>)component
{
return NO;
return YES;
}

- (void)didReuseComponent:(id<CKRenderComponentProtocol>)component {}
Expand Down
4 changes: 2 additions & 2 deletions ComponentKit/Core/Render/CKRenderWithSizeSpecComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ + (id)initialState
return [CKTreeNodeEmptyState emptyState];
}

- (BOOL)isEqualToComponent:(id<CKRenderComponentProtocol>)component
- (BOOL)shouldComponentUpdate:(id<CKRenderComponentProtocol>)component
{
return NO;
return YES;
}

- (void)didReuseComponent:(id<CKRenderComponentProtocol>)component {}
Expand Down
2 changes: 1 addition & 1 deletion ComponentKit/Utilities/CKRenderHelpers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static auto reusePreviousComponentIfComponentsAreEqual(id<CKRenderComponentProto
id<CKTreeNodeWithChildrenProtocol> previousParent) -> BOOL {
auto const previousChild = (CKRenderTreeNodeWithChild *)[previousParent childForComponentKey:node.componentKey];
auto const previousComponent = (id<CKRenderComponentProtocol>)previousChild.component;
if (previousComponent && [component isEqualToComponent:previousComponent]) {
if (previousComponent && ![component shouldComponentUpdate:previousComponent]) {
CKRenderInternal::reusePreviousComponent(component, childComponent, node, previousChild);
return YES;
}
Expand Down
6 changes: 3 additions & 3 deletions ComponentKitTests/CKRenderComponentTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ - (void)test_fasterPropsUpdate_componentIsNotBeingReused_whenPropsAreNotEqual
- (void)test_fasterPropsUpdate_componentIsBeingReusedWhenPropsAreEqual
{
// Use the same componentIdentifier for both components.
// isEqualToComponent: will return YES in this case and we can reuse the component.
// shouldComponentUpdate: will return NO in this case and we can reuse the component.
NSUInteger componentIdentifier = 1;
[self setUpForFasterPropsUpdates:[CKTestRenderComponent newWithIdentifier:componentIdentifier]];

Expand Down Expand Up @@ -471,9 +471,9 @@ + (id)initialState
return nil;
}

- (BOOL)isEqualToComponent:(CKTestRenderComponent *)component
- (BOOL)shouldComponentUpdate:(CKTestRenderComponent *)component
{
return _identifier == component->_identifier;
return _identifier != component->_identifier;
}

- (void)didReuseComponent:(CKTestRenderComponent *)component
Expand Down

0 comments on commit 281ae39

Please sign in to comment.