mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
0f4f917663
Reviewed By: igorsugak Differential Revision: D25861683 fbshipit-source-id: 616afca13ae64c76421053ce49286035e0687e36
79 lines
1.9 KiB
C++
79 lines
1.9 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.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <better/map.h>
|
|
#include <better/small_vector.h>
|
|
#include <react/renderer/core/Props.h>
|
|
#include <react/renderer/core/RawProps.h>
|
|
#include <react/renderer/core/RawPropsKey.h>
|
|
#include <react/renderer/core/RawPropsKeyMap.h>
|
|
#include <react/renderer/core/RawPropsPrimitives.h>
|
|
#include <react/renderer/core/RawValue.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
/*
|
|
* Specialized (to a particular type of Props) parser that provides the most
|
|
* efficient access to `RawProps` content.
|
|
*/
|
|
class RawPropsParser final {
|
|
public:
|
|
/*
|
|
* Default constructor.
|
|
* To be used by `ConcreteComponentDescriptor` only.
|
|
*/
|
|
RawPropsParser() = default;
|
|
|
|
/*
|
|
* To be used by `ConcreteComponentDescriptor` only.
|
|
*/
|
|
template <typename PropsT>
|
|
void prepare() noexcept {
|
|
static_assert(
|
|
std::is_base_of<Props, PropsT>::value,
|
|
"PropsT must be a descendant of Props");
|
|
RawProps emptyRawProps{};
|
|
emptyRawProps.parse(*this);
|
|
PropsT({}, emptyRawProps);
|
|
postPrepare();
|
|
}
|
|
|
|
private:
|
|
friend class ComponentDescriptor;
|
|
template <class ShadowNodeT>
|
|
friend class ConcreteComponentDescriptor;
|
|
friend class RawProps;
|
|
|
|
/*
|
|
* To be used by `RawProps` only.
|
|
*/
|
|
void preparse(RawProps const &rawProps) const noexcept;
|
|
|
|
/*
|
|
* Non-generic part of `prepare`.
|
|
*/
|
|
void postPrepare() noexcept;
|
|
|
|
/*
|
|
* To be used by `RawProps` only.
|
|
*/
|
|
RawValue const *at(RawProps const &rawProps, RawPropsKey const &key)
|
|
const noexcept;
|
|
|
|
mutable better::small_vector<RawPropsKey, kNumberOfPropsPerComponentSoftCap>
|
|
keys_{};
|
|
mutable RawPropsKeyMap nameToIndex_{};
|
|
mutable int size_{0};
|
|
mutable bool ready_{false};
|
|
};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|