Skip to content

Commit c52b925

Browse files
committed
fix(soba): clean up injectAnimations
1 parent 47dba57 commit c52b925

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

libs/soba/misc/src/lib/animations.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ElementRef, Injector, afterNextRender, computed, isSignal, signal, untracked } from '@angular/core';
2-
import { injectBeforeRender, is } from 'angular-three';
2+
import { injectBeforeRender, resolveRef } from 'angular-three';
33
import { assertInjector } from 'ngxtension/assert-injector';
44
import { injectAutoEffect } from 'ngxtension/auto-effect';
55
import { AnimationAction, AnimationClip, AnimationMixer, Object3D } from 'three';
@@ -15,6 +15,9 @@ export type NgtsAnimation<TAnimation extends AnimationClip = AnimationClip> =
1515
| TAnimation[]
1616
| { animations: TAnimation[] };
1717

18+
/**
19+
* Use afterNextRender
20+
*/
1821
export function injectAnimations<TAnimation extends AnimationClip>(
1922
animations: () => NgtsAnimation<TAnimation> | undefined | null,
2023
object: ElementRef<Object3D> | Object3D | (() => ElementRef<Object3D> | Object3D | undefined | null),
@@ -32,26 +35,18 @@ export function injectAnimations<TAnimation extends AnimationClip>(
3235
const names = [] as NgtsAnimationApi<TAnimation>['names'];
3336

3437
const actualObject = computed(() => {
35-
if (is.ref(object)) {
36-
return object.nativeElement;
37-
}
38-
3938
if (isSignal(object) || typeof object === 'function') {
40-
const value = object();
41-
if (is.ref(value)) {
42-
return value.nativeElement;
43-
}
44-
return value;
39+
return resolveRef(object());
4540
}
4641

47-
return object;
42+
return resolveRef(object);
4843
});
4944

5045
const ready = signal(false);
5146

5247
afterNextRender(() => {
5348
autoEffect(() => {
54-
const obj = actualObject();
49+
const obj = actualObject() as Object3D | undefined;
5550
if (!obj) return;
5651
Object.assign(mixer, { _root: obj });
5752

0 commit comments

Comments
 (0)