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

Add onError prop to LiveProvider #163

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Add onError prop to LiveProvider #163

wants to merge 10 commits into from

Conversation

pajter
Copy link

@pajter pajter commented Sep 11, 2019

I need a way to get the Error object instead of just rendering it through <LiveError />. I couldn't find a way to do this so I thought I'd add simple onError + onRender props to LiveProvider. Devs can then set these handlers if they want to do some custom error handling.

Please let me know if I missed anything or if you don't feel this is a good addition.

@sofiapoh
Copy link
Contributor

I think onError is a good addition! What was the use case for the onRender prop? It seems like you didn't add documentation for it. I'm wondering if there's something we already have that might cover that added functionality?

@pajter
Copy link
Author

pajter commented Sep 25, 2019

Just added some more fixes. Forgot about this PR for a while, sorry!

The onRender prop will be called when the error is cleared. You'd need to have some way to know when there is no longer an error. Maybe another name could be better.

I do need to add documentation, agreed!

README.md Outdated
@@ -156,6 +156,8 @@ It supports these props, while passing any others through to the `children`:
|scope|PropTypes.object|Accepts custom globals that the `code` can use
|noInline|PropTypes.bool|Doesn’t evaluate and mount the inline code (Default: `false`). Note: when using `noInline` whatever code you write must be a single expression (function, class component or some `jsx`) that can be returned immediately. If you'd like to render multiple components, use `noInline={true}`
|transformCode|PropTypes.func|Accepts and returns the code to be transpiled, affording an opportunity to first transform it
|onError|PropTypes.func|Called with `Error` object when render fails. Allows you to listen for errors and implement custom logic.|
|onRender|PropTypes.func|Called when component is rendered successfully. Can be used alongside `onError` to clear own error state.|
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we could use onError for this same purpose? If onRender is called really only when render is called successfully (presumably after error) could we instead just call onError again with the default state such as { error: undefined }. If I understand the point of this prop correctly I could imagine just resetting the error state would be sufficient for clearing any external error states?

Copy link
Author

Choose a reason for hiding this comment

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

Sure, that's definitely doable!

I'm thinking it might be a tad confusing to call it onError when it doesn't explicitly emit errors though. Maybe having the function signature be onRender(error?: Error) => void would make more sense? From first glance you'd be able to see what the event is about, and that it can emit both error and non-error state.

Let me know what you'd prefer and I'll make the updates. 🙂

Choose a reason for hiding this comment

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

How about onChange(code: string, error?: Error)

@pajter
Copy link
Author

pajter commented Oct 21, 2019

@sofiapoh I removed onError and changed onRender to include an optional Error argument. I'd love to get your thoughts on this.

@pajter pajter requested a review from sofiapoh October 29, 2019 15:36
@S33G
Copy link

S33G commented Mar 11, 2022

This is a great addition. Any update here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants