Skip to content

Commit

Permalink
refactor: move devtools attach into app init
Browse files Browse the repository at this point in the history
  • Loading branch information
trezy committed Jul 5, 2024
1 parent 89cdf11 commit ed9b0fb
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions src/components/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,23 @@ export const ApplicationFunction = (props, forwardedRef) =>
applicationRef.current = application;
updateResizeTo();
onInit?.(application);

if (attachToDevTools)
{
const globalScope = /** @type {*} */ (globalThis);

globalScope.__PIXI_APP__ = application;

import('pixi.js').then((pixi) =>
{
globalScope.__PIXI_DEVTOOLS__ = {
app: application,
pixi,
renderer: application.renderer,
stage: application.stage,
};
});
}
}, [onInit]);

useIsomorphicLayoutEffect(() =>
Expand Down Expand Up @@ -143,28 +160,6 @@ export const ApplicationFunction = (props, forwardedRef) =>
updateResizeTo();
}, [resizeTo]);

useIsomorphicLayoutEffect(() =>
{
const application = applicationRef.current;

if (attachToDevTools && application)
{
const globalScope = /** @type {*} */ (globalThis);

globalScope.__PIXI_APP__ = application;

import('pixi.js').then((pixi) =>
{
globalScope.__PIXI_DEVTOOLS__ = {
app: application,
pixi,
renderer: application.renderer,
stage: application.stage,
};
});
}
}, [attachToDevTools]);

return createElement('canvas', {
ref: canvasRef,
className,
Expand Down

0 comments on commit ed9b0fb

Please sign in to comment.