Skip to content

Commit 94834a6

Browse files
committed
fix(core): remove autoEffect in canvas
1 parent 63d6e74 commit 94834a6

File tree

1 file changed

+38
-36
lines changed

1 file changed

+38
-36
lines changed

libs/core/src/lib/canvas.ts

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
computed,
88
createEnvironmentInjector,
99
DestroyRef,
10+
effect,
1011
ElementRef,
1112
EnvironmentInjector,
1213
inject,
@@ -21,7 +22,6 @@ import {
2122
ViewContainerRef,
2223
} from '@angular/core';
2324
import { outputFromObservable } from '@angular/core/rxjs-interop';
24-
import { injectAutoEffect } from 'ngxtension/auto-effect';
2525
import { NgxResize, provideResizeOptions, ResizeOptions, ResizeResult } from 'ngxtension/resize';
2626
import { Raycaster, Scene, Vector3 } from 'three';
2727
import { createPointerEvents } from './dom/events';
@@ -58,7 +58,6 @@ import { is } from './utils/is';
5858
export class NgtCanvas {
5959
private store = injectStore();
6060
private initRoot = injectCanvasRootInitializer();
61-
private autoEffect = injectAutoEffect();
6261

6362
private host = inject<ElementRef<HTMLElement>>(ElementRef);
6463
private zone = inject(NgZone);
@@ -112,7 +111,12 @@ export class NgtCanvas {
112111
afterNextRender(() => {
113112
this.zone.runOutsideAngular(() => {
114113
this.configurator = this.initRoot(this.glCanvas().nativeElement);
115-
this.noZoneResizeEffect();
114+
effect(
115+
() => {
116+
this.noZoneResizeEffect();
117+
},
118+
{ injector: this.injector },
119+
);
116120
});
117121
});
118122

@@ -124,39 +128,37 @@ export class NgtCanvas {
124128
}
125129

126130
private noZoneResizeEffect() {
127-
this.autoEffect(() => {
128-
const resizeResult = this.resizeResult();
129-
if (resizeResult.width > 0 && resizeResult.height > 0) {
130-
if (!this.configurator) this.configurator = this.initRoot(this.glCanvas().nativeElement);
131-
this.configurator.configure({
132-
gl: this.gl(),
133-
shadows: this.shadows(),
134-
legacy: this.legacy(),
135-
linear: this.linear(),
136-
flat: this.flat(),
137-
orthographic: this.orthographic(),
138-
frameloop: this.frameloop(),
139-
performance: this.performance(),
140-
dpr: this.dpr(),
141-
raycaster: this.raycaster(),
142-
scene: this.scene(),
143-
camera: this.camera(),
144-
events: this.events(),
145-
eventSource: this.eventSource(),
146-
eventPrefix: this.eventPrefix(),
147-
lookAt: this.lookAt(),
148-
size: resizeResult,
149-
});
150-
151-
untracked(() => {
152-
if (this.glRef) {
153-
this.glRef.changeDetectorRef.detectChanges();
154-
} else {
155-
this.noZoneRender();
156-
}
157-
});
158-
}
159-
});
131+
const resizeResult = this.resizeResult();
132+
if (resizeResult.width > 0 && resizeResult.height > 0) {
133+
if (!this.configurator) this.configurator = this.initRoot(this.glCanvas().nativeElement);
134+
this.configurator.configure({
135+
gl: this.gl(),
136+
shadows: this.shadows(),
137+
legacy: this.legacy(),
138+
linear: this.linear(),
139+
flat: this.flat(),
140+
orthographic: this.orthographic(),
141+
frameloop: this.frameloop(),
142+
performance: this.performance(),
143+
dpr: this.dpr(),
144+
raycaster: this.raycaster(),
145+
scene: this.scene(),
146+
camera: this.camera(),
147+
events: this.events(),
148+
eventSource: this.eventSource(),
149+
eventPrefix: this.eventPrefix(),
150+
lookAt: this.lookAt(),
151+
size: resizeResult,
152+
});
153+
154+
untracked(() => {
155+
if (this.glRef) {
156+
this.glRef.changeDetectorRef.detectChanges();
157+
} else {
158+
this.noZoneRender();
159+
}
160+
});
161+
}
160162
}
161163

162164
private noZoneRender() {

0 commit comments

Comments
 (0)