-
Notifications
You must be signed in to change notification settings - Fork 24
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
Rewrite p5 preload logic to support instance mode #81
Conversation
Thank you @lindapaiste for this work, it's really great to see this effort into supporting |
FYI I didn't put in any unit tests because there is no |
I'm happy to merge this @lindapaiste could you take a look at the conflicts! Apologies, this may have occured due to some of the other branches I've been merging and it might even just be formatting related to #80 |
Apologies for not jumping earlier on this - things are a bit busy here because of midterms 🙂 I'd love to review, or rather try to wrap my head around these changes to understand @lindapaiste - could do this mid-next week, but I don't want to hold this up, so also happy to do so after this has been already merged. Thank you for working on this so essential component! |
@shiffman I fixed the conflicts so this is good to go. |
Thank you! It looks great! I'm going to test it manually locally later today and then will merge! |
src/utils/p5Utils.js
Outdated
const self = this; | ||
|
||
// Function to be called when a sketch is created, either in global or instance mode. | ||
p5.prototype.myLibInit = function () { |
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.
Just realized that I should rename this to ml5Init
or something along those lines. I was calling this myLibInit
when I was working on the setup in a very generic context for a myLib
library.
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.
@lindapaiste I've tested this and am ready to merge it! Do you want to make this change before I do?
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.
Just fixed it!
I'll note I'm getting an error with the body segmentation examples, but I think that is not related to this branch, will investigate separately. |
This fixes the body segmentation examples in #81.
This fixes the body segmentation examples in #81.
This fixes the body segmentation examples in #81.
# Conflicts: # src/index.js
Here we go, merging! Thank you again @lindapaiste! |
@lindapaiste Thank you for adding support for instance mode. I was able to preload most models ( I'm also getting an error for preloading |
Fixes #29
withPreload
dictionary in theindex.js
file.P5Util
class to introduce a distinction between the p5 environment/namespace/extensions (this.p5Extensions
) and the p5 object/constructor (this.p5Constructor
). This distinction was super confusing to me and the current code comingles the two concepts in a way that is incorrect. In considers both the object with the.loadImage
method and the object with the.Image
constructor to be "p5", but those are very different objects which have different methods and properties. They are not interchangeable.isP5Constructor
andisP5Extensions
to check for p5 in a more specific way.this.p5Extensions
from thethis.p5Instance
getter to match the current usagethis.p5Instance.loadImage
.ml5.setP5(p5)
.p5.prototype.registerMethod
, which allows us to access thethis
of the specific p5 instance where the method was called.ml5
object with a wrapped version that calls the_incrementPreload()
and_decrementPreload()
functions for this specific p5 instance.ready
property which is aPromise
. This is the pattern which we are already using in all of our models (despite confusing documentation). Using the.ready
property is a lot cleaner and easier than manipulating the arguments of the method. All we have to do isresult.ready.then(() => { decrement(); });
to call the decrement function when the loading is done.