Skip to content

Commit

Permalink
Prevent unnecessary method calls and allow number or array property
Browse files Browse the repository at this point in the history
  • Loading branch information
Drulokia committed Dec 10, 2024
1 parent 5a3bcb4 commit 31a6a6b
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions src/core/CoreNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,12 @@ export interface CoreNodeProps {
* @default `false`
*/
autosize: boolean;
boundsMargin: [number, number, number, number] | null;
/**
* Margin around the Node's bounds for preloading
*
* @default `null`
*/
boundsMargin: number | [number, number, number, number] | null;
/**
* Clipping Mode
*
Expand Down Expand Up @@ -761,21 +766,6 @@ export class CoreNode extends EventEmitter {
this.src = props.src;
this.rtt = props.rtt;

let bm = this.stage.boundsMargin;
if (props.boundsMargin) {
bm = Array.isArray(props.boundsMargin)
? props.boundsMargin
: [
props.boundsMargin,
props.boundsMargin,
props.boundsMargin,
props.boundsMargin,
];
} else if (this.parent !== null && this.parent.boundsMargin !== undefined) {
bm = this.parent.boundsMargin;
}
this.boundsMargin = bm;

this.setUpdateType(
UpdateType.ScaleRotate |
UpdateType.Local |
Expand Down Expand Up @@ -1137,6 +1127,7 @@ export class CoreNode extends EventEmitter {
this.props.strictBounds === true &&
this.renderState === CoreNodeRenderState.OutOfBounds
) {
this.updateType &= ~UpdateType.RenderBounds; // remove render bounds update
return;
}

Expand Down Expand Up @@ -1329,7 +1320,7 @@ export class CoreNode extends EventEmitter {

this.preloadBound = createPreloadBounds(
this.strictBound,
this.boundsMargin,
this.boundsMargin as [number, number, number, number],
);
} else {
// no parent or parent does not have a bound, take the stage boundaries
Expand Down Expand Up @@ -1808,13 +1799,11 @@ export class CoreNode extends EventEmitter {
this.props.autosize = value;
}

get boundsMargin(): [number, number, number, number] {
return (
this.props.boundsMargin ??
this.parent?.boundsMargin ??
this.stage.boundsMargin ??
null
);
get boundsMargin(): number | [number, number, number, number] {
const value = this.props.boundsMargin;
return Array.isArray(value)
? value
: this.parent?.boundsMargin ?? this.stage.boundsMargin;
}

set boundsMargin(value: number | [number, number, number, number]) {
Expand All @@ -1827,7 +1816,8 @@ export class CoreNode extends EventEmitter {
: [value, value, value, value];

this.props.boundsMargin = bm;
this.setUpdateType(UpdateType.RenderBounds);
this.setUpdateType(UpdateType.RenderBounds | UpdateType.Children);
this.childUpdateType |= UpdateType.RenderBounds | UpdateType.Children;
}

get clipping(): boolean {
Expand Down

0 comments on commit 31a6a6b

Please sign in to comment.