Fabric: Introduced ComponentDescriptorRegistry::at() method family

Summary: This is more usable (because it allows to use `->` operator) and safe (const-style) methods replacing old `operator[]` methods.

Reviewed By: mdvacca

Differential Revision: D12876744

fbshipit-source-id: 8ea7398c9777f8be3e88db873ec00915d0761615
This commit is contained in:
Valentin Shergin 2018-11-06 10:58:51 -08:00 committed by Facebook Github Bot
parent ee5061886e
commit 6c5b8c603b
2 changed files with 21 additions and 0 deletions

View File

@ -81,6 +81,24 @@ static const std::string componentNameByReactViewName(std::string viewName) {
return viewName;
}
const ComponentDescriptor &ComponentDescriptorRegistry::at(
ComponentName componentName) const {
auto unifiedComponentName = componentNameByReactViewName(componentName);
auto it = _registryByName.find(unifiedComponentName);
if (it == _registryByName.end()) {
throw std::invalid_argument(
("Unable to find componentDescriptor for " + unifiedComponentName)
.c_str());
}
return *it->second;
}
const ComponentDescriptor &ComponentDescriptorRegistry::at(
ComponentHandle componentHandle) const {
return *_registryByHandle.at(componentHandle);
}
SharedShadowNode ComponentDescriptorRegistry::createNode(
Tag tag,
const std::string &viewName,

View File

@ -25,6 +25,9 @@ class ComponentDescriptorRegistry {
void registerComponentDescriptor(
SharedComponentDescriptor componentDescriptor);
const ComponentDescriptor &at(ComponentName componentName) const;
const ComponentDescriptor &at(ComponentHandle componentHandle) const;
const SharedComponentDescriptor operator[](
const SharedShadowNode &shadowNode) const;
const SharedComponentDescriptor operator[](