Skip to content

Commit

Permalink
fix: getChildren return directly without extra local declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Dec 7, 2020
1 parent 40cfc66 commit 86c1ff7
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,16 @@

/** Get the children of a jsTree (Napi::Object) */
inline std::optional<Napi::Array> getChildren(const Napi::Object &&jsTree, const string &&childrenKey) {
Napi::Array childrenArray;

// determine if it has children
auto hasChildren = false;
if (jsTree.HasOwnProperty(childrenKey)) {
const auto childrenRaw = jsTree.Get(move_const(childrenKey));
if (childrenRaw.IsArray()) {
childrenArray = childrenRaw.As<Napi::Array>();
const auto childrenArray = childrenRaw.As<Napi::Array>();
if (childrenArray.Length() != 0) {
hasChildren = true;
return childrenArray;
}
}
}
if (hasChildren) {
return childrenArray;
}
return {};
}

Expand Down

0 comments on commit 86c1ff7

Please sign in to comment.