@@ -12,12 +12,16 @@ export type NgtsAnimationClips<TAnimationNames extends string> = {
12
12
[ Name in TAnimationNames ] : Omit < NgtsAnimationClip , 'name' > & { name : Name } ;
13
13
} [ TAnimationNames ] ;
14
14
export type NgtsAnimationApi < T extends NgtsAnimationClip > = {
15
+ /**
16
+ * Whether or not the animations finishes initialized
17
+ *
18
+ * @deprecated 3.5.0 - use `isReady` getter for better type-narrow instead. Will be removed in 4.0.0
19
+ */
15
20
ready : Signal < boolean > ;
16
21
clips : T [ ] ;
17
22
mixer : AnimationMixer ;
18
23
names : T [ 'name' ] [ ] ;
19
- actions : { [ key in T [ 'name' ] ] : AnimationAction | null } ;
20
- } ;
24
+ } & ( { get isReady ( ) : true ; actions : { [ key in T [ 'name' ] ] : AnimationAction } } | { get isReady ( ) : false } ) ;
21
25
22
26
export type NgtsAnimation < TAnimation extends NgtsAnimationClip = NgtsAnimationClip > =
23
27
| TAnimation [ ]
@@ -30,7 +34,7 @@ export function injectAnimations<TAnimation extends NgtsAnimationClip>(
30
34
animations : ( ) => NgtsAnimation < TAnimation > | undefined | null ,
31
35
object : ElementRef < Object3D > | Object3D | ( ( ) => ElementRef < Object3D > | Object3D | undefined | null ) ,
32
36
{ injector } : { injector ?: Injector } = { } ,
33
- ) {
37
+ ) : NgtsAnimationApi < TAnimation > {
34
38
return assertInjector ( injectAnimations , injector , ( ) => {
35
39
const mixer = new AnimationMixer ( null ! ) ;
36
40
injectBeforeRender ( ( { delta } ) => {
@@ -39,7 +43,7 @@ export function injectAnimations<TAnimation extends NgtsAnimationClip>(
39
43
} ) ;
40
44
41
45
let cached = { } as Record < string , AnimationAction > ;
42
- const actions = { } as NgtsAnimationApi < TAnimation > [ 'actions' ] ;
46
+ const actions = { } as { [ key in TAnimation [ 'name' ] ] : AnimationAction } ;
43
47
const clips = [ ] as NgtsAnimationApi < TAnimation > [ 'clips' ] ;
44
48
const names = [ ] as NgtsAnimationApi < TAnimation > [ 'names' ] ;
45
49
@@ -99,6 +103,10 @@ export function injectAnimations<TAnimation extends NgtsAnimationClip>(
99
103
} ) ;
100
104
} ) ;
101
105
102
- return { clips, mixer, actions, names, ready } ;
106
+ const result = { ready, clips, mixer, actions, names } as unknown as NgtsAnimationApi < TAnimation > ;
107
+
108
+ Object . defineProperty ( result , 'isReady' , { get : ready } ) ;
109
+
110
+ return result ;
103
111
} ) ;
104
112
}
0 commit comments