Files
react-native/ReactCommon/fabric/uimanager/ComponentDescriptorProviderRegistry.cpp
Valentin Shergin 832164169d Fabric: Unification of registration process of ComponentViews and ComponentDescriptors
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
2019-04-17 22:44:20 -07:00

60 lines
1.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<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 &parameters) 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