Fabric: `fromDynamic`: Parsing vector type when source has no array

Summary:
@public
If some prop has `std::vector` type, it possible that on JS side we want to pass just one element of the array.
And in this case we sometimes drop array initialization (`[]`) part, so instead of passing `[{x:1, y:1}]` we pass `{x:1, y:1}`.
This diff adds support for that.

Reviewed By: mdvacca

Differential Revision: D8526572

fbshipit-source-id: 33d4369ac48cac3eb1c534f477d8259e76e0c547
This commit is contained in:
Valentin Shergin 2018-06-22 07:28:44 -07:00 committed by Facebook Github Bot
parent f6aa5db0e4
commit 8ef539e0c2
1 changed files with 7 additions and 0 deletions

View File

@ -26,6 +26,13 @@ inline void fromDynamic(const folly::dynamic &value, std::string &result) { resu
template <typename T>
inline void fromDynamic(const folly::dynamic &value, std::vector<T> &result) {
if (!value.isArray()) {
T itemResult;
fromDynamic(value, itemResult);
result = {itemResult};
return;
}
result.clear();
T itemResult;
for (auto &itemValue : value) {