mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add RawValue support for arrays of arrays
Summary: Adds support for dynamic value that are `std::vector<std::vector<RawValue>>` Reviewed By: shergin, mdvacca Differential Revision: D16936932 fbshipit-source-id: fc8d087f9705af9da56ccc1bd9a0537b2bfeb50d
This commit is contained in:
committed by
Facebook Github Bot
parent
c232b5ae3b
commit
91d59eb20b
@@ -250,6 +250,19 @@ class RawValue {
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static std::vector<std::vector<T>> castValue(
|
||||
const folly::dynamic &dynamic,
|
||||
std::vector<std::vector<T>> *type) noexcept {
|
||||
assert(dynamic.isArray());
|
||||
auto result = std::vector<std::vector<T>>{};
|
||||
result.reserve(dynamic.size());
|
||||
for (const auto &item : dynamic) {
|
||||
result.push_back(castValue(item, (std::vector<T> *)nullptr));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static better::map<std::string, T> castValue(
|
||||
const folly::dynamic &dynamic,
|
||||
|
||||
@@ -46,6 +46,31 @@ void fromRawValue(RawValue const &rawValue, std::vector<T> &result) {
|
||||
result.push_back(itemResult);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void fromRawValue(
|
||||
RawValue const &rawValue,
|
||||
std::vector<std::vector<T>> &result) {
|
||||
if (rawValue.hasType<std::vector<std::vector<RawValue>>>()) {
|
||||
auto items = (std::vector<std::vector<RawValue>>)rawValue;
|
||||
auto length = items.size();
|
||||
result.clear();
|
||||
result.reserve(length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
T itemResult;
|
||||
fromRawValue(items.at(i), itemResult);
|
||||
result.push_back(itemResult);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// The case where `value` is not an array.
|
||||
result.clear();
|
||||
result.reserve(1);
|
||||
T itemResult;
|
||||
fromRawValue(rawValue, itemResult);
|
||||
result.push_back(itemResult);
|
||||
}
|
||||
|
||||
template <typename T, typename U = T>
|
||||
T convertRawProp(
|
||||
RawProps const &rawProps,
|
||||
|
||||
Reference in New Issue
Block a user