-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Promises support #3684
Comments
so this has been already discussed and there is an abandoned or somewhere. it will be done, with the approach:
i did not check all asyncronous functions yet and found possible problematic spots |
Hmm. I searched the issue tracker before posting, and I couldn't find anything. Do you have a link to the previous proposal/issue/PR for me? |
the discussion was a generic possible es6 migration that for now i m pushing forward since the average fabric dev use fabric in simple environments, and i have no time to mess up with babel for now in my free time |
Ah, I see. That seems to be a more involved effort to actually change the code to use Promises internally as well (as opposed to just exposing them on the public API). I do see a few issues with the other PR. Would you prefer I leave some review notes on there, make a proposal for a new (exposed-API-surface-only) implementation, or both? (The benefit of an exposed-API-surface-only implementation would be that, for now, you can support Promises without needing to set up Babel or adding in a polyfill yourself.) |
better here |
Alright. I've written a wrapper implementation this morning that should be suitable for adding provisional Promise support, until a 'proper' code conversion rolls around. If it works as intended, it won't affect the current workings of callbacks (nor will it change their signature), and it should only involve a minimal code change in fabric.js itself. I still need to test it out in a few strange edge cases, though, and I might not get around to finishing that today. If not, I'll finish the testing tomorrow, and post my proposal here then. |
thanks. is mainly a question of code style and code quantity. |
Hi, Any update on this, when could we expect it? Regards, |
I think await would be a better way. It's just cleaner code. |
Well a Promise polyfill is fewer lines of code, and other than that is not just cleaner code, is a different behaviour completely. |
Yes it is. I remembered a video I watch some time ago when I checked a few things for my next project. |
Was this enhancement mothballed? |
i did not work on it. I m alone on the project and bugfixes or fun improvements take precedence. |
Currently, something like
fabric.Image.fromURL
only supports callbacks. Usage example from the tutorial:My request would be to add Promises support out of the box for
fromURL
, and any other asynchronous calls in the library, such that you could instead write the following:... or even something like this, using Bluebird:
(Of course it doesn't make much sense to load the same image three times like this, I'm just translating the tutorial example verbatim for demonstration purposes.)
Reasoning for the feature request: All the usual benefits of Promises; easier composition, more reliable error handling, no chance of accidental double callbacks, and so on, and so forth.
Implementation and consequences: This does not need to be a breaking change; an approach similar to Bluebird's
nodeify
/asCallback
could be taken, where a Promise is returned by default, and a callback is only called if one is specified.I would not recommend actually using Bluebird in this case, for two reasons:
.asCallback
assumes an error-first callback, butfromURL
doesn't use those; there is no firsterrror
argument.As for browser support; there are roughly two options here:
global.Promise
if they want to use Promises in all environments, without affecting non-Promise-using users.The second option is probably preferable from a bundle size and "interference with other users" point of view, but is a bit more complex implementation-wise.
I'd say that overall implementation complexity and work required for somebody who knows the fabric.js codebase would be very low, since it's a generalizable conversion - but one that is much easier and more reliable to do from within the library than on the outside. Unfortunately I don't really know much about the fabric.js codebase, or I would've outright submitted a PR...
(Of course, I'd be happy to answer any questions about the Promises aspect of this, to make implementation go smoother; implementation details, common usage patterns, and so on.)
EDIT: Fixed example to actually be equivalent. More caffeine is required...
The text was updated successfully, but these errors were encountered: