diff --git a/ComponentKit/Core/ComponentTree/Protocols/CKRenderComponentProtocol.h b/ComponentKit/Core/ComponentTree/Protocols/CKRenderComponentProtocol.h index 1d9a11ccd..7adf70e21 100644 --- a/ComponentKit/Core/ComponentTree/Protocols/CKRenderComponentProtocol.h +++ b/ComponentKit/Core/ComponentTree/Protocols/CKRenderComponentProtocol.h @@ -25,13 +25,13 @@ + (id)initialStateWithComponent:(id)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)component; +- (BOOL)shouldComponentUpdate:(id)component; /* This method is being called when the infrasturcture reuses the previous generation of the component. diff --git a/ComponentKit/Core/Render/CKRenderComponent.mm b/ComponentKit/Core/Render/CKRenderComponent.mm index 7dde104bc..9e4215605 100644 --- a/ComponentKit/Core/Render/CKRenderComponent.mm +++ b/ComponentKit/Core/Render/CKRenderComponent.mm @@ -94,9 +94,9 @@ + (id)initialState return [CKTreeNodeEmptyState emptyState]; } -- (BOOL)isEqualToComponent:(id)component +- (BOOL)shouldComponentUpdate:(id)component { - return NO; + return YES; } - (void)didReuseComponent:(id)component {} diff --git a/ComponentKit/Core/Render/CKRenderLayoutComponent.mm b/ComponentKit/Core/Render/CKRenderLayoutComponent.mm index 4200038ca..d93790b2c 100644 --- a/ComponentKit/Core/Render/CKRenderLayoutComponent.mm +++ b/ComponentKit/Core/Render/CKRenderLayoutComponent.mm @@ -42,9 +42,9 @@ + (id)initialState return [CKTreeNodeEmptyState emptyState]; } -- (BOOL)isEqualToComponent:(id)component +- (BOOL)shouldComponentUpdate:(id)component { - return NO; + return YES; } - (void)didReuseComponent:(id)component {} diff --git a/ComponentKit/Core/Render/CKRenderLayoutWithChildrenComponent.mm b/ComponentKit/Core/Render/CKRenderLayoutWithChildrenComponent.mm index 74a1cde6a..f2a55ddfd 100644 --- a/ComponentKit/Core/Render/CKRenderLayoutWithChildrenComponent.mm +++ b/ComponentKit/Core/Render/CKRenderLayoutWithChildrenComponent.mm @@ -44,9 +44,9 @@ + (id)initialState return [CKTreeNodeEmptyState emptyState]; } -- (BOOL)isEqualToComponent:(id)component +- (BOOL)shouldComponentUpdate:(id)component { - return NO; + return YES; } - (void)didReuseComponent:(id)component {} diff --git a/ComponentKit/Core/Render/CKRenderWithChildrenComponent.mm b/ComponentKit/Core/Render/CKRenderWithChildrenComponent.mm index e3e8bec99..a72f34051 100644 --- a/ComponentKit/Core/Render/CKRenderWithChildrenComponent.mm +++ b/ComponentKit/Core/Render/CKRenderWithChildrenComponent.mm @@ -55,9 +55,9 @@ + (id)initialState return [CKTreeNodeEmptyState emptyState]; } -- (BOOL)isEqualToComponent:(id)component +- (BOOL)shouldComponentUpdate:(id)component { - return NO; + return YES; } - (void)didReuseComponent:(id)component {} diff --git a/ComponentKit/Core/Render/CKRenderWithSizeSpecComponent.mm b/ComponentKit/Core/Render/CKRenderWithSizeSpecComponent.mm index 445ecbc07..ed9fcaac9 100644 --- a/ComponentKit/Core/Render/CKRenderWithSizeSpecComponent.mm +++ b/ComponentKit/Core/Render/CKRenderWithSizeSpecComponent.mm @@ -156,9 +156,9 @@ + (id)initialState return [CKTreeNodeEmptyState emptyState]; } -- (BOOL)isEqualToComponent:(id)component +- (BOOL)shouldComponentUpdate:(id)component { - return NO; + return YES; } - (void)didReuseComponent:(id)component {} diff --git a/ComponentKit/Utilities/CKRenderHelpers.mm b/ComponentKit/Utilities/CKRenderHelpers.mm index cdf9e330d..883efe2e6 100644 --- a/ComponentKit/Utilities/CKRenderHelpers.mm +++ b/ComponentKit/Utilities/CKRenderHelpers.mm @@ -55,7 +55,7 @@ static auto reusePreviousComponentIfComponentsAreEqual(id previousParent) -> BOOL { auto const previousChild = (CKRenderTreeNodeWithChild *)[previousParent childForComponentKey:node.componentKey]; auto const previousComponent = (id)previousChild.component; - if (previousComponent && [component isEqualToComponent:previousComponent]) { + if (previousComponent && ![component shouldComponentUpdate:previousComponent]) { CKRenderInternal::reusePreviousComponent(component, childComponent, node, previousChild); return YES; } diff --git a/ComponentKitTests/CKRenderComponentTests.mm b/ComponentKitTests/CKRenderComponentTests.mm index 6f50eb24a..71f403b66 100644 --- a/ComponentKitTests/CKRenderComponentTests.mm +++ b/ComponentKitTests/CKRenderComponentTests.mm @@ -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]]; @@ -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