Skip to content

Commit a74cfcc

Browse files
mdvaccafacebook-github-bot
authored andcommitted
Refactor ComponentDescriptorConstructor to use a Function instead of a pointer to a method
Summary: This diff refactors ComponentDescriptorConstructor to use a Function instead of a pointer to a method. changelog: [internal] internal Differential Revision: D88960360
1 parent 28d6ba1 commit a74cfcc

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

packages/react-native/ReactCommon/react/renderer/componentregistry/ComponentDescriptorProvider.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ namespace facebook::react {
1818
* constructor. The callable returns a unique pointer conveniently represents an
1919
* abstract type and ownership of the newly created object.
2020
*/
21-
using ComponentDescriptorConstructor = ComponentDescriptor::Unique(const ComponentDescriptorParameters &parameters);
21+
using ComponentDescriptorConstructor =
22+
std::function<ComponentDescriptor::Unique(const ComponentDescriptorParameters &parameters)>;
2223

2324
/*
2425
* Represents a unified way to construct an instance of a particular stored
@@ -35,7 +36,7 @@ class ComponentDescriptorProvider final {
3536
ComponentHandle handle;
3637
ComponentName name;
3738
ComponentDescriptor::Flavor flavor;
38-
ComponentDescriptorConstructor *constructor;
39+
ComponentDescriptorConstructor constructor;
3940
};
4041

4142
/*

packages/react-native/ReactCommon/react/renderer/componentregistry/ComponentDescriptorRegistry.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ void ComponentDescriptorRegistry::add(
3232
const ComponentDescriptorProvider& componentDescriptorProvider) const {
3333
std::unique_lock lock(mutex_);
3434

35-
auto componentDescriptor = componentDescriptorProvider.constructor(
36-
{.eventDispatcher = parameters_.eventDispatcher,
37-
.contextContainer = parameters_.contextContainer,
38-
.flavor = componentDescriptorProvider.flavor});
35+
auto args = ComponentDescriptorParameters{
36+
.eventDispatcher = parameters_.eventDispatcher,
37+
.contextContainer = parameters_.contextContainer,
38+
.flavor = componentDescriptorProvider.flavor};
39+
auto componentDescriptor = componentDescriptorProvider.constructor(args);
3940
react_native_assert(
4041
componentDescriptor->getComponentHandle() ==
4142
componentDescriptorProvider.handle);
@@ -45,6 +46,7 @@ void ComponentDescriptorRegistry::add(
4546

4647
auto sharedComponentDescriptor = std::shared_ptr<const ComponentDescriptor>(
4748
std::move(componentDescriptor));
49+
4850
_registryByHandle[componentDescriptorProvider.handle] =
4951
sharedComponentDescriptor;
5052
_registryByName[componentDescriptorProvider.name] = sharedComponentDescriptor;

0 commit comments

Comments
 (0)