1
1
import {
2
+ ChangeDetectionStrategy ,
2
3
Component ,
3
4
EventEmitter ,
4
5
Input ,
@@ -18,11 +19,13 @@ import { isDisposable } from './util';
18
19
export interface ThWrapperEventMap < T = Object3D > extends Object3DEventMap {
19
20
changes : { changes : SimpleChanges } ;
20
21
loaded : { object : T } ;
22
+ removed : { object : T } ;
21
23
}
22
24
23
25
@Component ( {
24
26
selector : 'th-abs-wrapper' ,
25
27
template : '' ,
28
+ changeDetection : ChangeDetectionStrategy . OnPush ,
26
29
} )
27
30
// eslint-disable-next-line @angular-eslint/component-class-suffix
28
31
export class ThWrapperBase < T , ARGS = unknown > implements ThWrapperLifeCycle , OnChanges , OnInit , OnDestroy {
@@ -149,6 +152,7 @@ export class ThWrapperBase<T, ARGS = unknown> implements ThWrapperLifeCycle, OnC
149
152
if ( this . autoDispose ) {
150
153
this . disposeObjRef ( ) ;
151
154
}
155
+ this . emitRemoveEvent ( ) ;
152
156
}
153
157
154
158
protected applyObjRef ( objRef : T | undefined ) {
@@ -176,6 +180,20 @@ export class ThWrapperBase<T, ARGS = unknown> implements ThWrapperLifeCycle, OnC
176
180
}
177
181
}
178
182
183
+ protected emitRemoveEvent ( ) {
184
+ // only emit change if _objRef is no proxy,
185
+ // and trigger emit over objRef event emitter
186
+ if ( this . _objRef && ! isLazyObject3dProxy ( this . _objRef as any ) ) {
187
+ ( this . _objRef as unknown as Object3D < ThWrapperEventMap < T > > ) . dispatchEvent ?.( {
188
+ type : 'removed' ,
189
+ object : this . _objRef ,
190
+ } ) ;
191
+ if ( this . _objRef$ ) {
192
+ this . _objRef$ . next ( this . _objRef ) ;
193
+ }
194
+ }
195
+ }
196
+
179
197
protected emitPropertyChanges ( changes : SimpleChanges ) {
180
198
if ( this . _objRef ) {
181
199
( this . _objRef as unknown as EventDispatcher < ThWrapperEventMap < T > > ) . dispatchEvent ?.( { type : 'changes' , changes } ) ;
0 commit comments