mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-06-15 14:27:33 +08:00
Summary: Our long-term plan is to completely illuminate `jsi::Value`-to-`folly::dynamic` serialization step in prop parsing process improving performance and memory pressure. At the same time, we don't want to introduce a hard dependency in application code to JSI because it exposes direct access to VM and prevents parsing some data that come *NOT* from JSVM. RawValue is an extremely light-weight (hopefully fully optimized-out) abstraction that provides limited JSON-like and C++-idiomatic interface. The current particular implementation is still using `folly::dynamic` inside, but I have fully JSI-powered one which will replace the current one right after we figure out how to deal with folly::dynamic-specific callsites. Or we can implement RawValue in a hybrid manner if a code-size implication of that will be minimal. Reviewed By: JoshuaGross, mdvacca Differential Revision: D13962466 fbshipit-source-id: e848522fd242f21e9e771773f2103f1c1d9d7f21
62 lines
1.5 KiB
C++
62 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.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
|
|
#include <folly/dynamic.h>
|
|
#include <react/core/ConcreteComponentDescriptor.h>
|
|
#include <react/core/ConcreteShadowNode.h>
|
|
#include <react/core/LocalData.h>
|
|
#include <react/core/RawProps.h>
|
|
#include <react/core/ShadowNode.h>
|
|
|
|
using namespace facebook::react;
|
|
|
|
/**
|
|
* This defines a set of TestComponent classes: Props, ShadowNode,
|
|
* ComponentDescriptor. To be used for testing purpose.
|
|
*/
|
|
|
|
class TestLocalData : public LocalData {
|
|
public:
|
|
void setNumber(const int &number) {
|
|
number_ = number;
|
|
}
|
|
|
|
int getNumber() const {
|
|
return number_;
|
|
}
|
|
|
|
private:
|
|
int number_{0};
|
|
};
|
|
|
|
static const char TestComponentName[] = "Test";
|
|
|
|
class TestProps : public Props {
|
|
public:
|
|
using Props::Props;
|
|
TestProps()
|
|
: Props(Props(), RawProps(folly::dynamic::object("nativeID", "testNativeID"))) {}
|
|
};
|
|
using SharedTestProps = std::shared_ptr<const TestProps>;
|
|
|
|
class TestShadowNode;
|
|
using SharedTestShadowNode = std::shared_ptr<const TestShadowNode>;
|
|
class TestShadowNode : public ConcreteShadowNode<TestComponentName, TestProps> {
|
|
public:
|
|
using ConcreteShadowNode::ConcreteShadowNode;
|
|
};
|
|
|
|
class TestComponentDescriptor
|
|
: public ConcreteComponentDescriptor<TestShadowNode> {
|
|
public:
|
|
using ConcreteComponentDescriptor::ConcreteComponentDescriptor;
|
|
};
|