q5.js icon indicating copy to clipboard operation
q5.js copied to clipboard

async `load` function

Open quinton-ashley opened this issue 1 year ago • 1 comments

An async function simply named load could be used to load any file or multiple files asynchronously and return a promise.

This will be implemented in q5-util.js The q5 setup function is already async.

This idea was suggested by @mattdesl and iterated on by @mvicky2592 in this p5.js issue discussion. I also think keeping the preload system for backwards compatibility and ease of use for beginners is the right idea though. https://github.com/processing/p5.js/issues/6767

quinton-ashley avatar Jun 19 '24 13:06 quinton-ashley

@DipakKhade Thanks for the PR! But please comment on an issue before trying to implement a feature though.

The implementation of load(...args) should use Promise.all. Also it should be able to load many types of files, not just text and json. It would need to be a function added to instances of Q5 not Q5 itself, in order to access other loading functions.

After examining the p5 feature request again more closely, I'm a bit confused myself about how they plan to support loading images, video, and sounds with this one method. I suppose it could wrap preload functions like loadImage and loadSound in a promise. What do you think of that idea?

I also think we need to figure out a way for addon developers to add support to q5 load for loading additional file types but that could be added after an initial implementation is done.

quinton-ashley avatar Jul 24 '24 19:07 quinton-ashley

I had an idea on how to do this by having each preload function like loadSound make the returned object include a property storing a promise that resolves when it's loaded.

quinton-ashley avatar Jan 19 '25 04:01 quinton-ashley

Whatever you decide, please, don't get rid of the classic loading functions like p5js is doing for its version 2! 🙏

GoToLoop avatar Jan 19 '25 04:01 GoToLoop

@GoToLoop oh for sure I won't. That's crazy, are they actually committing to that?

quinton-ashley avatar Jan 19 '25 05:01 quinton-ashley

Well, this already merged commit have all preload-related code removed! https://github.com/processing/p5.js/pull/7203

IMO, Processing flavors should strive to be more similar to the original Java Processing than trying to strictly adhere to the syntax of its target language.

Getting rid of callback loading syntax, and therefore completely breaking old code, just b/c JS pro devs prefer async + await syntax is totally unwise!

AFAIK, Processing's target public isn't professional programmers! And JS promise syntax is considered hard to learn!

I'm all in favor of including support for async/await syntax in JS Processing flavors, but not as a replacement of an easier to understand callback loading syntax!

GoToLoop avatar Jan 19 '25 06:01 GoToLoop

implemented in v2.16

quinton-ashley avatar Jan 26 '25 05:01 quinton-ashley