Skip to content

Commit

Permalink
fix tests fails
Browse files Browse the repository at this point in the history
  • Loading branch information
capGoblin committed Sep 27, 2023
1 parent fa06c9c commit ff32bbd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/core/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ class p5 {
}

// Function to invoke registered hooks before or after events such as preload, setup, and pre/post draw.
const context = this._isGlobal ? window : this;
function callRegisteredHooksFor(hookName) {
p5.prototype.callRegisteredHooksFor = function (hookName) {
const target = this || p5.prototype;
const context = this._isGlobal ? window : this;
if (target._registeredMethods.hasOwnProperty(hookName)) {
const methods = target._registeredMethods[hookName];
for (const method of methods) {
Expand All @@ -243,7 +243,7 @@ class p5 {
}
}
}
}
};

this._start = () => {
// Find node if id given
Expand All @@ -255,7 +255,7 @@ class p5 {

const context = this._isGlobal ? window : this;
if (context.preload) {
callRegisteredHooksFor('beforePreload');
this.callRegisteredHooksFor('beforePreload');
// Setup loading screen
// Set loading screen into dom if not present
// Otherwise displays and removes user provided loading screen
Expand Down Expand Up @@ -301,7 +301,7 @@ class p5 {
if (loadingScreen) {
loadingScreen.parentNode.removeChild(loadingScreen);
}
callRegisteredHooksFor('afterPreload');
this.callRegisteredHooksFor('afterPreload');
if (!this._setupDone) {
this._lastTargetFrameTime = window.performance.now();
this._lastRealFrameTime = window.performance.now();
Expand Down Expand Up @@ -338,7 +338,7 @@ class p5 {
};

this._setup = () => {
callRegisteredHooksFor('beforeSetup');
this.callRegisteredHooksFor('beforeSetup');
// Always create a default canvas.
// Later on if the user calls createCanvas, this default one
// will be replaced
Expand Down Expand Up @@ -386,7 +386,7 @@ class p5 {
if (this._accessibleOutputs.grid || this._accessibleOutputs.text) {
this._updateAccsOutput();
}
callRegisteredHooksFor('afterSetup');
this.callRegisteredHooksFor('afterSetup');
};

this._draw = () => {
Expand Down
5 changes: 2 additions & 3 deletions src/core/structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import p5 from './main';
import callRegisteredHooksFor from './main';
/**
* Stops p5.js from continuously executing the code within <a href="#/p5/draw">draw()</a>.
* If <a href="#/p5/loop">loop()</a> is called, the code in <a href="#/p5/draw">draw()</a>
Expand Down Expand Up @@ -480,14 +479,14 @@ p5.prototype.redraw = function(n) {
context._renderer._update();
}
context._setProperty('frameCount', context.frameCount + 1);
callRegisteredHooksFor.call(context, 'pre');
this.callRegisteredHooksFor('pre');
this._inUserDraw = true;
try {
context.draw();
} finally {
this._inUserDraw = false;
}
callRegisteredHooksFor.call(context, 'post');
this.callRegisteredHooksFor('post');
}
}
};
Expand Down

0 comments on commit ff32bbd

Please sign in to comment.