mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add logic to generate recursive TM members (#41768)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41768 Changelog: [Internal] Reviewed By: rshest Differential Revision: D51572375 fbshipit-source-id: e4ce0726c457ea02a7710ea1d21bbd697e35848a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
09b110fef8
commit
749b8dd2d4
@@ -91,84 +91,18 @@ struct CustomHostObjectRef {
|
||||
using CustomHostObject = HostObjectWrapper<CustomHostObjectRef>;
|
||||
|
||||
#pragma mark - recursive objects
|
||||
struct BinaryTreeNode {
|
||||
std::unique_ptr<BinaryTreeNode> left;
|
||||
int32_t value;
|
||||
std::unique_ptr<BinaryTreeNode> right;
|
||||
};
|
||||
|
||||
using BinaryTreeNode = NativeCxxModuleExampleCxxBinaryTreeNode<int32_t>;
|
||||
|
||||
template <>
|
||||
struct Bridging<BinaryTreeNode> {
|
||||
static BinaryTreeNode fromJs(
|
||||
jsi::Runtime& rt,
|
||||
const jsi::Object& value,
|
||||
const std::shared_ptr<CallInvoker>& jsInvoker) {
|
||||
BinaryTreeNode result{
|
||||
value.hasProperty(rt, "left")
|
||||
? std::make_unique<BinaryTreeNode>(bridging::fromJs<BinaryTreeNode>(
|
||||
rt, value.getProperty(rt, "left"), jsInvoker))
|
||||
: nullptr,
|
||||
bridging::fromJs<int32_t>(
|
||||
rt, value.getProperty(rt, "value"), jsInvoker),
|
||||
value.hasProperty(rt, "right")
|
||||
? std::make_unique<BinaryTreeNode>(bridging::fromJs<BinaryTreeNode>(
|
||||
rt, value.getProperty(rt, "right"), jsInvoker))
|
||||
: nullptr};
|
||||
return result;
|
||||
}
|
||||
struct Bridging<BinaryTreeNode>
|
||||
: NativeCxxModuleExampleCxxBinaryTreeNodeBridging<BinaryTreeNode> {};
|
||||
|
||||
static jsi::Object toJs(
|
||||
jsi::Runtime& rt,
|
||||
const BinaryTreeNode& value,
|
||||
const std::shared_ptr<CallInvoker>& jsInvoker) {
|
||||
auto result = facebook::jsi::Object(rt);
|
||||
if (value.left) {
|
||||
result.setProperty(
|
||||
rt, "left", bridging::toJs(rt, *value.left, jsInvoker));
|
||||
}
|
||||
result.setProperty(rt, "value", bridging::toJs(rt, value.value, jsInvoker));
|
||||
if (value.right) {
|
||||
result.setProperty(
|
||||
rt, "right", bridging::toJs(rt, *value.right, jsInvoker));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
struct GraphNode {
|
||||
std::string label;
|
||||
std::optional<std::vector<GraphNode>> neighbors;
|
||||
};
|
||||
using GraphNode = NativeCxxModuleExampleCxxGraphNode<std::string>;
|
||||
|
||||
template <>
|
||||
struct Bridging<GraphNode> {
|
||||
static GraphNode fromJs(
|
||||
jsi::Runtime& rt,
|
||||
const jsi::Object& value,
|
||||
const std::shared_ptr<CallInvoker>& jsInvoker) {
|
||||
GraphNode result{
|
||||
bridging::fromJs<std::string>(
|
||||
rt, value.getProperty(rt, "label"), jsInvoker),
|
||||
bridging::fromJs<std::optional<std::vector<GraphNode>>>(
|
||||
rt, value.getProperty(rt, "neighbors"), jsInvoker)};
|
||||
return result;
|
||||
}
|
||||
|
||||
static jsi::Object toJs(
|
||||
jsi::Runtime& rt,
|
||||
const GraphNode value,
|
||||
const std::shared_ptr<CallInvoker>& jsInvoker) {
|
||||
auto result = facebook::jsi::Object(rt);
|
||||
result.setProperty(rt, "label", bridging::toJs(rt, value.label, jsInvoker));
|
||||
if (value.neighbors) {
|
||||
result.setProperty(
|
||||
rt,
|
||||
"neighbors",
|
||||
bridging::toJs(rt, value.neighbors.value(), jsInvoker));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
struct Bridging<GraphNode>
|
||||
: NativeCxxModuleExampleCxxGraphNodeBridging<GraphNode> {};
|
||||
|
||||
#pragma mark - implementation
|
||||
class NativeCxxModuleExample
|
||||
|
||||
Reference in New Issue
Block a user