Skip to content

Commit

Permalink
Fabric: Introduced ComponentDescriptorRegistry::at() method family
Browse files Browse the repository at this point in the history
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
  • Loading branch information
shergin authored and facebook-github-bot committed Nov 6, 2018
1 parent ee50618 commit 6c5b8c6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ReactCommon/fabric/uimanager/ComponentDescriptorRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions ReactCommon/fabric/uimanager/ComponentDescriptorRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[](
Expand Down

0 comments on commit 6c5b8c6

Please sign in to comment.