Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ebcb6f7

Browse files
committed
refactor(theatre): use injectObjectEvents for transform events
1 parent d03e5cd commit ebcb6f7

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

libs/theatre/src/lib/sheet-object/transform.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,7 @@ import { TheatreSheetObject } from './sheet-object';
2626
selector: 'theatre-transform',
2727
template: `
2828
@if (selected()) {
29-
<ngts-transform-controls
30-
[object]="$any(group)"
31-
[options]="options()"
32-
(mouseDown)="onMouseDown()"
33-
(mouseUp)="onMouseUp()"
34-
(change)="onChange()"
35-
/>
29+
<ngts-transform-controls [object]="$any(group)" [options]="options()" />
3630
}
3731
3832
<ngt-group #group>
@@ -51,6 +45,7 @@ export class TheatreSheetObjectTransform<TLabel extends string | undefined> {
5145
);
5246

5347
groupRef = viewChild.required<ElementRef<THREE.Group>>('group');
48+
private controlsRef = viewChild(NgtsTransformControls);
5449

5550
private theatreSheetObject = inject(TheatreSheetObject);
5651
sheetObject = computed(() => this.theatreSheetObject.sheetObject());
@@ -139,6 +134,22 @@ export class TheatreSheetObjectTransform<TLabel extends string | undefined> {
139134
onCleanup(cleanup);
140135
});
141136

137+
// TODO: (chau) use event binding when they no longer trigger change detection
138+
effect((onCleanup) => {
139+
const controls = this.controlsRef();
140+
if (!controls) return;
141+
142+
const subs = [
143+
controls.change.subscribe(this.onChange.bind(this)),
144+
controls.mouseDown.subscribe(this.onMouseDown.bind(this)),
145+
controls.mouseUp.subscribe(this.onMouseUp.bind(this)),
146+
];
147+
148+
onCleanup(() => {
149+
subs.forEach((sub) => sub.unsubscribe());
150+
});
151+
});
152+
142153
inject(DestroyRef).onDestroy(() => {
143154
const key = this.key();
144155
this.theatreSheetObject.removeProps(key ? [key] : ['position', 'rotation', 'scale']);

0 commit comments

Comments
 (0)