-
Notifications
You must be signed in to change notification settings - Fork 85
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
Make legacy fileOpen API accept configurable cleanup and rejection #45
Make legacy fileOpen API accept configurable cleanup and rejection #45
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
d29362b
to
e1b18e9
Compare
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
Thanks for opening this PR. I have to admit I'm not a fan of the way this complicates the API. Let me think a bit more if there is a different way. I had more something in mind like the following: import { fileOpen, supported } from 'browser-fs-access';
// … before
let file;
if (supported) {
try {
file = await fileOpen();
} catch (err) {
console.error(err);
}
} else {
file = await fileOpen();
}
// … after I admit this looks not very elegant, but it makes clear that there is no magic. What do you think of this? |
Yeah, it does complicate the API a bit. I'm inclined to think it doesn't complicate things too much, though, especially given the payoff: the only change surfaced to the library user is that you can, if you wish, provide an optional callback that can be used to set up the conditions under which a cancel/rejection is triggered in the legacy API. The callback just sets the rejectionHandler and then returns a method that will be called on "cleanup" (i.e., when success occurs, or when the rejection condition is hit). This is a bit analogous to React's I should've included the example of how it would work here, rather than just in the issue comments for #41, so I'm dropping the example here just for reference (note that I've removed the comments this time, in case that made it look more complicated than it is): const file = await fileOpen({
setupLegacyCleanupAndRejection: (rejectionHandler) => {
const timeoutId = setTimeout(rejectionHandler, 10000);
return (reject) => {
clearTimeout(timeoutId);
if (reject) {
reject('My error message here.');
}
};
},
}); If you don't want to use the option to configure this stuff, you can still of course just do: const file = await fileOpen();
I don't think I understand this part. Wasn't the goal to make rejection behavior configurable, so that the user could control how/when rejection occurs (that's what I took from the last line of this comment)? The example above doesn't seem to do that anywhere, but I could be missing it. Is the example supposed to show that the library itself would handle rejection if and only if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, approval
Thank you! You have convinced me. Let's give it a try…
Here is a rough idea/proposal for handling the later discussion in #41.