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

Hook just before global mode instantiation #4204

Open
2 of 14 tasks
limzykenneth opened this issue Dec 21, 2019 · 4 comments
Open
2 of 14 tasks

Hook just before global mode instantiation #4204

limzykenneth opened this issue Dec 21, 2019 · 4 comments

Comments

@limzykenneth
Copy link
Member

Nature of issue?

  • Found a bug
  • Existing feature enhancement
  • New feature request

Most appropriate sub-area of p5.js?

  • Color
  • Core/Environment/Rendering
  • Data
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Other (specify if possible)

New feature details:

For addon libraries, is there a hook that will execute before global mode p5 is instantiated? If not can one be added?

The use case is that I'm fiddling around with some async code that when resolve will attach functions to the p5.prototype but since it is async the global mode p5 will have instantiated before it is completed so the global mode p5 sketch won't have that function attached yet.

I can use instance mode and delay the call to new p5(sketch) but for an addon library it should work out of the box, so I'm thinking can an optional hook be added just before global mode is instantiated that the async addon library can call when it is done loading to trigger global mode?

One idea comes from core/init.js

// if the page is ready, initialize p5 immediately
if (document.readyState === 'complete') {
  _globalInit();
  // if the page is still loading, add an event listener
  // and initialize p5 as soon as it finishes loading
} else {
  window.addEventListener('load', _globalInit, false);
}

Instead of checking for readyState, check for a static function on the p5 object and if it's null check readyState as usual, if not wait for it to resolve (assuming it should return a Promise) then run _globalInit().

@singhvisha
Copy link
Contributor

@limzykenneth @stalgiag ,
Can I work on this issue?Could you please tell how to approach to implement this new feature?

@singhvisha
Copy link
Contributor

@limzykenneth @stalgiag ,
Can I work on this issue?Could you please tell how to approach to implement this new feature?

@limzykenneth
Copy link
Member Author

I'm gauging interest and potential problems of this feature with this issue so I'm not looking for someone in particular to implement this as I have a pretty good idea of how to implement this myself. Thanks for the interest though.

PS. It's the holiday period so it may take longer for us to reply to a message, there's no need to ping us again.

@outofambit
Copy link
Contributor

small note that i think some work in #4233 will help set the stage for this infrastructure

@limzykenneth limzykenneth moved this to Proposal in p5.js 2.0 May 28, 2024
@limzykenneth limzykenneth moved this from Proposal to Out of Scope in p5.js 2.0 Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Out of Scope
Development

No branches or pull requests

5 participants