Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clarify onMount return functions when combined with non-synchronous handlers #5053

Merged
merged 4 commits into from
Jun 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions site/content/docs/03-run-time.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ If a function is returned from `onMount`, it will be called when the component i
</script>
```

> This behaviour will only work when the function passed to `onMount` *synchronously* returns a value. `async` functions always return a `Promise`, and as such cannot *synchronously* return a function.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to maybe say "returns a function" rather than "returns a value"? The only thing I'd worry with about that is the ends of the two sentences sounding a bit repetitive.

Copy link
Member Author

@antony antony Jun 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I've said value in the first instance, is that I wouldn't consider this:

const myOnDestroy = function () { disposeStuff() } 
onMount(async () => new Promise(r => r(myOnDestroy))

as returning a function, more returning a value. I'd want to cover people literally using promises as return values within async functions.

The second sentence refers to a concrete example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair. This seems like a good explanation then, and there'll at least be some place in the docs to point people to about this now.


#### `beforeUpdate`

```js
Expand Down