Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply events on first render #532

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}