Skip to content

Commit

Permalink
fix: apply event handlers on first render
Browse files Browse the repository at this point in the history
  • Loading branch information
trezy committed Aug 29, 2024
1 parent 1c4e6c3 commit 16b7f7c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/constants/PixiReactIgnoredProps.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const PixiReactIgnoredProps = Object.freeze([
'draw',
]);
import { PixiToReactEventPropNames } from './EventPropNames';

export const PixiReactIgnoredProps = Object.freeze(Object.keys(PixiToReactEventPropNames));
4 changes: 2 additions & 2 deletions src/helpers/applyProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ export function applyProps(
...instanceProps
} = instance;

let typedData: DiffSet;
let typedData;

if (isDiffSet(data))
{
typedData = data;
typedData = data as DiffSet;
}
else
{
Expand Down
15 changes: 13 additions & 2 deletions src/helpers/createInstance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PixiReactIgnoredProps } from '../constants/PixiReactIgnoredProps';
import { ReactToPixiEventPropNames } from '../constants/EventPropNames';
import { applyProps } from './applyProps';
import { catalogue } from './catalogue';
import { convertStringToPascalCase } from './convertStringToPascalCase';
Expand Down Expand Up @@ -30,7 +30,18 @@ export function createInstance(
// Get the class from an imported Pixi.js namespace
const PixiComponent = catalogue[name];

const pixiProps = gentleCloneProps(props, PixiReactIgnoredProps);
const pixiProps = gentleCloneProps(props);

// Clone event props
Object.entries(props).forEach(([key, value]) =>
{
if (key in ReactToPixiEventPropNames)
{
const pixiEventName = ReactToPixiEventPropNames[key as keyof typeof ReactToPixiEventPropNames];

pixiProps[pixiEventName] = value;
}
});

const instance = prepareInstance(new PixiComponent(pixiProps), {
root,
Expand Down
7 changes: 2 additions & 5 deletions src/helpers/diffProps.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
PixiToReactEventPropNames,
ReactToPixiEventPropNames,
} from '../constants/EventPropNames';
import { ReactToPixiEventPropNames } from '../constants/EventPropNames';
import { isEqual } from './compare';
import { gentleCloneProps } from './gentleCloneProps';

Expand Down Expand Up @@ -53,7 +50,7 @@ export function diffProps(
}

// Collect handlers and bail out
if ((key in PixiToReactEventPropNames) || (key in ReactToPixiEventPropNames))
if (key in ReactToPixiEventPropNames)
{
changes.push([key, value, true, []]);

Expand Down
3 changes: 2 additions & 1 deletion src/helpers/gentleCloneProps.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PixiReactIgnoredProps } from '../constants/PixiReactIgnoredProps';
import { ReactIgnoredProps } from '../constants/ReactIgnoredProps';
import { gentleClone } from './gentleClone';

Expand All @@ -7,5 +8,5 @@ export function gentleCloneProps(
additionalIgnoredProps: readonly string[] = [],
)
{
return gentleClone(props, ReactIgnoredProps.concat(additionalIgnoredProps));
return gentleClone(props, ReactIgnoredProps.concat(PixiReactIgnoredProps, additionalIgnoredProps));
}

0 comments on commit 16b7f7c

Please sign in to comment.