Skip to content

Hook just before global mode instantiation #4204

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

Closed
2 of 14 tasks
limzykenneth opened this issue Dec 21, 2019 · 5 comments
Closed
2 of 14 tasks

Hook just before global mode instantiation #4204

limzykenneth opened this issue Dec 21, 2019 · 5 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.x 🌱🌳 May 28, 2024
@limzykenneth limzykenneth moved this from Proposal to Out of Scope in p5.js 2.x 🌱🌳 Jun 18, 2024
@ksen0
Copy link
Member

ksen0 commented Apr 16, 2025

Closing, as with the current implementation of p5.js 2.0 this is no longer necessary.

PS: This message is part of cleaning up the p5.js 2.0 roadmap prior to release, to make outstanding more more approachable for new contributors. You can join the conversation about this new version on this Discourse thread or this GitHub thread!

@ksen0 ksen0 closed this as completed Apr 16, 2025
@github-project-automation github-project-automation bot moved this from Out of Scope to Completed in p5.js 2.x 🌱🌳 Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Completed
Development

No branches or pull requests

6 participants