Skip to content

Commit

Permalink
Throw exception if children result is not array or object (#210)
Browse files Browse the repository at this point in the history
Related to #67
  • Loading branch information
web-padawan authored and Viktor Lukashov committed Jun 29, 2018
1 parent c65f79d commit 5f28a9b
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 205 deletions.
9 changes: 6 additions & 3 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ function amend(amendmentFunction, context, route) {
}

function processNewChildren(newChildren, route, context) {
if (isResultNotEmpty(newChildren) && !isObject(newChildren)) {
throw new Error(log(`Expected 'children' method of the route with path '${route.path}' `
+ `to return an object, but got: '${newChildren}'`));
if (!Array.isArray(newChildren) && !isObject(newChildren)) {
throw new Error(
log(
`Incorrect "children" value for the route ${route.path}: expected array or object, but got ${newChildren}`
)
);
}

route.__children = [];
Expand Down
3 changes: 2 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ export function fireRouterEvent(type, detail) {
}

export function isObject(o) {
return typeof o === 'object';
// guard against null passing the typeof check
return typeof o === 'object' && !!o;
}

export function isFunction(f) {
Expand Down
Loading

0 comments on commit 5f28a9b

Please # to comment.