mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
fb39d45ed5
Summary: Renaming the `better` utilities to `butter`: - to prevent claims that this library is superior to others - it really depends on use cases - to indicate ease of use throughout the codebase, easily spread like butter Changelog: [C++][Changed] Renaming C++ better util to butter, used by Fabric internals Reviewed By: JoshuaGross Differential Revision: D33242764 fbshipit-source-id: 26dc95d9597c61ce8e66708e44ed545e0fc5cff5
85 lines
2.5 KiB
C++
85 lines
2.5 KiB
C++
/*
|
|
* 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<butter::shared_mutex> lock(mutex_);
|
|
|
|
/*
|
|
// TODO: T57583139
|
|
The assert is temporarily disabled to reduce the volume of the signal.
|
|
assert(
|
|
componentDescriptorProviders_.find(provider.handle) ==
|
|
componentDescriptorProviders_.end() &&
|
|
"Attempt to register an already registered ComponentDescriptorProvider.");
|
|
*/
|
|
|
|
if (componentDescriptorProviders_.find(provider.handle) !=
|
|
componentDescriptorProviders_.end()) {
|
|
// Re-registering a provider makes no sense because it's copyable: already
|
|
// registered one is as good as any new can be.
|
|
return;
|
|
}
|
|
|
|
componentDescriptorProviders_.insert({provider.handle, provider});
|
|
|
|
for (auto const &weakRegistry : componentDescriptorRegistries_) {
|
|
auto registry = weakRegistry.lock();
|
|
if (!registry) {
|
|
continue;
|
|
}
|
|
|
|
registry->add(provider);
|
|
}
|
|
}
|
|
|
|
void ComponentDescriptorProviderRegistry::setComponentDescriptorProviderRequest(
|
|
ComponentDescriptorProviderRequest componentDescriptorProviderRequest)
|
|
const {
|
|
std::shared_lock<butter::shared_mutex> lock(mutex_);
|
|
componentDescriptorProviderRequest_ = componentDescriptorProviderRequest;
|
|
}
|
|
|
|
void ComponentDescriptorProviderRegistry::request(
|
|
ComponentName componentName) const {
|
|
ComponentDescriptorProviderRequest componentDescriptorProviderRequest;
|
|
|
|
{
|
|
std::shared_lock<butter::shared_mutex> lock(mutex_);
|
|
componentDescriptorProviderRequest = componentDescriptorProviderRequest_;
|
|
}
|
|
|
|
if (componentDescriptorProviderRequest) {
|
|
componentDescriptorProviderRequest(componentName);
|
|
}
|
|
}
|
|
|
|
ComponentDescriptorRegistry::Shared
|
|
ComponentDescriptorProviderRegistry::createComponentDescriptorRegistry(
|
|
ComponentDescriptorParameters const ¶meters) const {
|
|
std::shared_lock<butter::shared_mutex> lock(mutex_);
|
|
|
|
auto registry = std::make_shared<ComponentDescriptorRegistry const>(
|
|
parameters, *this, parameters.contextContainer);
|
|
|
|
for (auto const &pair : componentDescriptorProviders_) {
|
|
registry->add(pair.second);
|
|
}
|
|
|
|
componentDescriptorRegistries_.push_back(registry);
|
|
|
|
return registry;
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|