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

Allowing onBeforePrint to return a Promise #146

Merged
merged 1 commit into from
Jul 19, 2019
Merged

Allowing onBeforePrint to return a Promise #146

merged 1 commit into from
Jul 19, 2019

Conversation

aviklai
Copy link
Contributor

@aviklai aviklai commented Jul 19, 2019

Copy link
Owner

@MatthewHerbst MatthewHerbst left a comment

Choose a reason for hiding this comment

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

Thanks for jumping on this! Just a few minor things and then I think we'll be good to go (we'll have to release this under a breaking change but I think that's ok)

src/index.tsx Outdated Show resolved Hide resolved
src/index.tsx Outdated Show resolved Hide resolved
src/index.tsx Show resolved Hide resolved
src/index.tsx Outdated Show resolved Hide resolved
@aviklai
Copy link
Contributor Author

aviklai commented Jul 19, 2019

@MatthewHerbst Why is this a breaking change? we still allow the onBeforePrint function to return void.

@MatthewHerbst
Copy link
Owner

MatthewHerbst commented Jul 19, 2019

This line:

onBeforePrintOutput instanceof Promise

will break if Promise does not exist. Specifically, if you run that on a browser (I tested on IE10 via Browserstack) without Promise, you will get the error:

var x = {}
x instanceof Promise
// Error: "'Promise' is undefined"

So the implementation as it would still require users to polyfill Promise for environments it doesn't exist in, which is not currently a library requirement, which is why it would require a breaking change.

Maybe there is another way to check if something is a Promise?

@aviklai
Copy link
Contributor Author

aviklai commented Jul 19, 2019

Apparently, there is no standardized way:
https://stackoverflow.com/questions/27746304/how-do-i-tell-if-an-object-is-a-promise

This is the es5 answer that we can use (and graphql-js use):
https://github.com/graphql/graphql-js/blob/master/src/jsutils/isPromise.js

So it would look like this:
if (onBeforePrintOutput && typeof onBeforePrintOutput.then === 'function')

What do you think?

@MatthewHerbst
Copy link
Owner

I'm ok with that. It's not 100% perfect (as some commenters in the accepted answer of that SO post point out) but I think it's good enough

@aviklai
Copy link
Contributor Author

aviklai commented Jul 19, 2019

@MatthewHerbst Done - changed the way to check if it's a promise.

@MatthewHerbst
Copy link
Owner

Awesome! One last request: can you please squash the commits together?

Squashed commit:

[5c7b3cf] es5 way of checking promise

[fdd233e] Removed the catch from onBeforePrintOutput, added onBeforePrint returns promise to the readme

[f2076dc] Allowing onBeforePrint to return a Promise
@aviklai
Copy link
Contributor Author

aviklai commented Jul 19, 2019

@MatthewHerbst Done.

Copy link
Owner

@MatthewHerbst MatthewHerbst left a comment

Choose a reason for hiding this comment

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

Awesome, thanks! I'll get a new version with this published in a little bit

@MatthewHerbst MatthewHerbst merged commit 90c7831 into MatthewHerbst:master Jul 19, 2019
@MatthewHerbst
Copy link
Owner

Published as v2.2.0. Thanks again!

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.

2 participants