Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fabric: Unification of registration process of
ComponentView
s and `…
…ComponentDescriptor`s Summary: Registries, providers, providers of registries, registres of providers. All that can be really confusing, but that represents best the constraints and desires that we have: * We need to be able to register components on-the-fly (so we need a mechanism that will propagate changes); * We don't want to register ComponentDescriptors separately from ComponentView classes; * C++ not always gives us abstractions that we want (e.g. pointers to constructors). After the change, we can remove the whole Buck target that has a bunch of handwritten boilerplate code. There is a still room for polish and removing some concepts, types or classes but this diff is already huge. Reviewed By: JoshuaGross Differential Revision: D14983906 fbshipit-source-id: ce536ebea0c905059c7a4d644dc25233e2809761
- Loading branch information
1 parent
00eab3d
commit 8321641
Showing
11 changed files
with
266 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
ReactCommon/fabric/uimanager/ComponentDescriptorProviderRegistry.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
#include "ComponentDescriptorProviderRegistry.h" | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
void ComponentDescriptorProviderRegistry::add( | ||
ComponentDescriptorProvider provider) const { | ||
std::unique_lock<better::shared_mutex> lock(mutex_); | ||
componentDescriptorProviders_.insert({provider.handle, provider}); | ||
|
||
for (auto const &weakRegistry : componentDescriptorRegistries_) { | ||
auto registry = weakRegistry.lock(); | ||
if (!registry) { | ||
continue; | ||
} | ||
|
||
registry->add(provider); | ||
} | ||
} | ||
|
||
void ComponentDescriptorProviderRegistry::remove( | ||
ComponentDescriptorProvider provider) const { | ||
std::unique_lock<better::shared_mutex> lock(mutex_); | ||
componentDescriptorProviders_.erase(provider.handle); | ||
|
||
for (auto const &weakRegistry : componentDescriptorRegistries_) { | ||
auto registry = weakRegistry.lock(); | ||
if (!registry) { | ||
continue; | ||
} | ||
|
||
registry->remove(provider); | ||
} | ||
} | ||
|
||
ComponentDescriptorRegistry::Shared | ||
ComponentDescriptorProviderRegistry::createComponentDescriptorRegistry( | ||
ComponentDescriptorParameters const ¶meters) const { | ||
std::shared_lock<better::shared_mutex> lock(mutex_); | ||
|
||
auto registry = | ||
std::make_shared<ComponentDescriptorRegistry const>(parameters); | ||
|
||
for (auto const &pair : componentDescriptorProviders_) { | ||
registry->add(pair.second); | ||
} | ||
|
||
return registry; | ||
} | ||
|
||
} // namespace react | ||
} // namespace facebook |
50 changes: 50 additions & 0 deletions
50
ReactCommon/fabric/uimanager/ComponentDescriptorProviderRegistry.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* 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 <better/mutex.h> | ||
|
||
#include <react/core/ComponentDescriptor.h> | ||
#include <react/uimanager/ComponentDescriptorProvider.h> | ||
#include <react/uimanager/ComponentDescriptorRegistry.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
/* | ||
* Registry of `ComponentDescriptorProvider`s (and managed | ||
* `ComponentDescriptorRegistry`s). The class maintains a list of | ||
* `ComponentDescriptorRegistry`s (retaining pointers weakly) and update them | ||
* accordingly to changes in the provider registry. | ||
*/ | ||
class ComponentDescriptorProviderRegistry final { | ||
public: | ||
/* | ||
* Adds (or removes) a `ComponentDescriptorProvider`s and update the managed | ||
* `ComponentDescriptorRegistry`s accordingly. | ||
*/ | ||
void add(ComponentDescriptorProvider provider) const; | ||
void remove(ComponentDescriptorProvider provider) const; | ||
|
||
/* | ||
* Creates managed `ComponentDescriptorRegistry` based on a stored list of | ||
* `ComponentDescriptorProvider`s and given `ComponentDescriptorParameters`. | ||
*/ | ||
ComponentDescriptorRegistry::Shared createComponentDescriptorRegistry( | ||
ComponentDescriptorParameters const ¶meters) const; | ||
|
||
private: | ||
mutable better::shared_mutex mutex_; | ||
mutable std::vector<std::weak_ptr<ComponentDescriptorRegistry const>> | ||
componentDescriptorRegistries_; | ||
mutable better::map<ComponentHandle, ComponentDescriptorProvider const> | ||
componentDescriptorProviders_; | ||
}; | ||
|
||
} // namespace react | ||
} // namespace facebook |
Oops, something went wrong.