hyperapp: Actions break when returning null

In app.js:77 hyperapp will crash if an action returns a value that is neither undefined nor typeof object (also for null). null.

Reason is that it tries to access result.then which is only possible for objects.

Also what should be the expected behavior if a function returns null? I used that in a previous version to get around return without any parameters. This lead me to discover this crash upon upgrading to v0.7.1.

E.g.

// abort if mode is `off`
if (mode.toLowerCase() === 'off') return
someFunctionCall()
// without semicolons this looks like it would return the next line
// similar to
const example = () =>
someFunctionCall()
// which would return the result of `someFunctionCall`
// just because you're aware that `return` terminates on newline doesn't mean that it doesn't look like it wouldn't/shouldn't

For now I’ll use undefined, but it’d be good to have a defined behavior for null and other primitives.

Maybe we should introduce environment-specific errors like React does? They’d be amazing for development and can just get stripped away in production environments. There could be an error or warning in the case of null etc.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 18 (9 by maintainers)

Commits related to this issue

Most upvoted comments

plus you cannot redefine null, but you can redefine undefined in javascript (wtf, right?). if you want to explicitly test against undefined you have to use typeof x == "undefined". but == null should cover both cases since it will internally test against the built-in undefined as well as null. i use it everywhere internally in domvm, and it works well & is fast.

@jbucaran That should work, yes. It’d lead to a defined behavior.

If the minifier supports it I’d suggest to use the more explicit result === null || result === undefined though, since it makes it obvious that the == is no mistake (it usually is).