Unexpected behaviour when using registerPreloadMethod()
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 24k
- Forks
- 3.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 25
Description
Most appropriate sub-area of p5.js?
- Accessibility (Web Accessibility)
- Build tools and processes
- Color
- Core/Environment/Rendering
- Data
- DOM
- Events
- Friendly error system
- Image
- IO (Input/Output)
- Localization
- Math
- Unit Testing
- Typography
- Utilities
- WebGL
- Other (specify if possible)
Details about the bug:
- p5.js version: v1.3.1
- Web browser and version: Firefox 88.0.1
- Operating System: Windows 10
- Steps to reproduce this: p5.js sketch
Basically the documentation here for registerPreloadMethod() is a bit outdated. When registering a function using registerPreloadMethod() and calling that function from preload() will leave the sketch stuck on the loading screen. The reason for this is that a preload()-suitable function is expected to call _decrementPreload() at some point which will then start off the main part of the sketch.
Relevant code snippet:
p5.prototype.loadStuffPromise = function() {
return new Promise(function(resolve) {
setTimeout(resolve, 1000);
});
}
p5.prototype.loadStuff = function () {
this.loadStuffPromise().then(function(data) {
console.log("Data loaded.");
// Uncommenting this makes it work:
// this._decrementPreload();
});
}
p5.prototype.registerPreloadMethod("loadStuff", p5.prototype);
// Using this also makes it work:
// p5.prototype.registerPromisePreload({
// target: p5.prototype,
// method: "loadStuffPromise",
// })
The _ in _decrementPreload() suggests to me that this is not considered a public function. Personally I see to ways of addressing this issue:
- Add a public implementation for
_decrementPreload()and update the contributer's docs on how it should be used in conjunction withregisterPreloadMethod().
Or
- Deprecate
registerPreloadMethod()in favour ofregisterPromisePreload(), which has slightly different semantics (the function is required to return a promise) but does correctly handle_decrementPreload()
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with contributor_docs/creating_libraries.md and the registerPreloadMethod(), registerPromisePreload(), and _decrementPreload() entry points on p5.prototype. Reproduce the linked p5.js sketch to compare the two preload approaches. Done means resolving the preload behavior and aligning the contributor documentation with the chosen API semantics.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100