Skip to content

Commit

Permalink
feat: add attachToDevTools prop to the <Application> component
Browse files Browse the repository at this point in the history
  • Loading branch information
trezy committed Jun 25, 2024
1 parent 3ad17ce commit fdeaea4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/** @type {import('eslint').Linter.Config} */
module.exports = {
extends: ['@pixi/eslint-config'],
globals: {
globalThis: 'readonly',
},
parserOptions: {
project: './tsconfig.eslint.json',
ecmaVersion: 2020,
Expand Down
10 changes: 10 additions & 0 deletions src/components/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { render } from '../render.js';

/**
* @typedef {object} BaseApplicationProps
* @property {boolean} [attachToDevTools] Whether this application chould be attached to the dev tools. NOTE: This should only be enabled on one application at a time.
* @property {string} [className] CSS classes to be applied to the Pixi Application's canvas element.
*/

Expand All @@ -51,6 +52,7 @@ import { render } from '../render.js';
export const ApplicationFunction = (props, forwardedRef) =>
{
const {
attachToDevTools,
children,
className,
resizeTo,
Expand Down Expand Up @@ -101,6 +103,14 @@ export const ApplicationFunction = (props, forwardedRef) =>
resizeTo,
]);

useEffect(() =>
{
if (attachToDevTools && applicationRef.current)
{
/** @type {*} */ (globalThis).__PIXI_APP__ = applicationRef.current;
}
}, [attachToDevTools]);

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

0 comments on commit fdeaea4

Please sign in to comment.