From 42be1aad8288bf1751e70116cfeb5d37ffac17ab Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Thu, 30 Jan 2020 19:43:33 -0800 Subject: [PATCH] Fabric: Making ComponentBuilder copyable and movable Summary: It's useful property to have. Changelog: [Internal] Fabric-specific internal change. Reviewed By: sammy-SC Differential Revision: D19596280 fbshipit-source-id: 5b60cc4f7c65c3458ff35ffa2dfaafce79dc985a --- ReactCommon/fabric/element/ComponentBuilder.h | 8 +++++ ReactCommon/fabric/element/testUtils.h | 34 +++++++++++++++++++ .../fabric/element/tests/ElementTest.cpp | 12 ++----- 3 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 ReactCommon/fabric/element/testUtils.h diff --git a/ReactCommon/fabric/element/ComponentBuilder.h b/ReactCommon/fabric/element/ComponentBuilder.h index aa9b9d13b5a..d33a3934c2a 100644 --- a/ReactCommon/fabric/element/ComponentBuilder.h +++ b/ReactCommon/fabric/element/ComponentBuilder.h @@ -29,6 +29,14 @@ class ComponentBuilder final { ComponentBuilder( ComponentDescriptorRegistry::Shared const &componentDescriptorRegistry); + /* + * Copyable and movable. + */ + ComponentBuilder(ComponentBuilder const &componentBuilder) = default; + ComponentBuilder(ComponentBuilder &&componentBuilder) noexcept = default; + ComponentBuilder &operator=(ComponentBuilder const &other) = default; + ComponentBuilder &operator=(ComponentBuilder &&other) = default; + /* * Builds a `ShadowNode` tree with given `Element` tree using stored * `ComponentDescriptorRegistry`. diff --git a/ReactCommon/fabric/element/testUtils.h b/ReactCommon/fabric/element/testUtils.h new file mode 100644 index 00000000000..cb29e91afb9 --- /dev/null +++ b/ReactCommon/fabric/element/testUtils.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include +#include +#include + +namespace facebook { +namespace react { + +extern ComponentBuilder simpleComponentBuilder() { + ComponentDescriptorProviderRegistry componentDescriptorProviderRegistry{}; + auto eventDispatcher = EventDispatcher::Shared{}; + auto componentDescriptorRegistry = + componentDescriptorProviderRegistry.createComponentDescriptorRegistry( + ComponentDescriptorParameters{eventDispatcher, nullptr, nullptr}); + + componentDescriptorProviderRegistry.add( + concreteComponentDescriptorProvider()); + componentDescriptorProviderRegistry.add( + concreteComponentDescriptorProvider()); + + return ComponentBuilder{componentDescriptorRegistry}; +} + +} // namespace react +} // namespace facebook diff --git a/ReactCommon/fabric/element/tests/ElementTest.cpp b/ReactCommon/fabric/element/tests/ElementTest.cpp index 8c838eb5c74..790759f3876 100644 --- a/ReactCommon/fabric/element/tests/ElementTest.cpp +++ b/ReactCommon/fabric/element/tests/ElementTest.cpp @@ -12,21 +12,13 @@ #include #include #include +#include #include using namespace facebook::react; TEST(ElementTest, testNormalCases) { - ComponentDescriptorProviderRegistry componentDescriptorProviderRegistry{}; - auto eventDispatcher = EventDispatcher::Shared{}; - auto componentDescriptorRegistry = - componentDescriptorProviderRegistry.createComponentDescriptorRegistry( - ComponentDescriptorParameters{eventDispatcher, nullptr, nullptr}); - - componentDescriptorProviderRegistry.add( - concreteComponentDescriptorProvider()); - - auto builder = ComponentBuilder{componentDescriptorRegistry}; + auto builder = simpleComponentBuilder(); auto shadowNodeA = std::shared_ptr{}; auto shadowNodeAA = std::shared_ptr{};