@@ -59,13 +59,9 @@ export class HitTest extends Emitter {
5959 ( ) => {
6060 const items = [ ] ;
6161 for ( const [ item , bbox ] of this . queue ) {
62- if ( bbox === null ) {
63- // Remove operation
64- this . tree . remove ( item ) ;
65- } else {
66- // Add/update operation
67- this . tree . remove ( item ) ;
68- // item.updateRect(bbox);
62+ this . tree . remove ( item ) ;
63+ if ( bbox ) {
64+ item . updateRect ( bbox ) ;
6965 items . push ( item ) ;
7066 }
7167 }
@@ -76,7 +72,7 @@ export class HitTest extends Emitter {
7672 } ,
7773 {
7874 priority : ESchedulerPriority . LOWEST ,
79- frameTimeout : 100 ,
75+ frameInterval : 1 ,
8076 }
8177 ) ;
8278
@@ -98,24 +94,22 @@ export class HitTest extends Emitter {
9894 }
9995
10096 public add ( item : HitBox ) {
101- this . queue . set ( item , {
102- minX : item . minX ,
103- minY : item . minY ,
104- maxX : item . maxX ,
105- maxY : item . maxY ,
106- x : item . x ,
107- y : item . y ,
108- } ) ;
97+ if ( item . destroyed ) {
98+ return ;
99+ }
100+ this . queue . set ( item , item ) ;
109101 this . processQueue ( ) ;
110102 }
111103
112104 public waitUsableRectUpdate ( callback : ( rect : TRect ) => void ) {
113105 if ( this . isUnstable ) {
114- const fn = ( ) => {
115- this . waitUsableRectUpdate ( callback ) ;
116- } ;
117- this . once ( "update" , fn ) ;
118- return ( ) => this . off ( "update" , fn ) ;
106+ const removeListener = this . $usableRect . subscribe ( ( ) => {
107+ if ( ! this . isUnstable ) {
108+ removeListener ( ) ;
109+ callback ( this . $usableRect . value ) ;
110+ }
111+ } ) ;
112+ return removeListener ;
119113 }
120114 callback ( this . $usableRect . value ) ;
121115 return noop ;
@@ -173,8 +167,8 @@ export class HitTest extends Emitter {
173167 }
174168
175169 public destroy ( ) : void {
170+ this . clear ( ) ;
176171 super . destroy ( ) ;
177- this . processQueue . cancel ( ) ;
178172 }
179173
180174 public testHitBox ( item : HitBoxData ) : Component [ ] {
@@ -201,7 +195,7 @@ export class HitTest extends Emitter {
201195}
202196
203197export class HitBox implements IHitBox {
204- private destroyed = false ;
198+ public destroyed = false ;
205199
206200 public maxX : number ;
207201
@@ -217,6 +211,8 @@ export class HitBox implements IHitBox {
217211
218212 private rect : [ number , number , number , number ] = [ 0 , 0 , 0 , 0 ] ;
219213
214+ protected unstable = true ;
215+
220216 constructor (
221217 public item : { zIndex : number } & Component & IWithHitTest ,
222218 protected hitTest : HitTest
@@ -230,12 +226,14 @@ export class HitBox implements IHitBox {
230226 this . x = rect . x ;
231227 this . y = rect . y ;
232228 this . rect = [ this . minX , this . minY , this . maxX - this . minX , this . maxY - this . minY ] ;
229+ this . unstable = false ;
233230 }
234231
235232 public update = ( minX : number , minY : number , maxX : number , maxY : number , force ?: boolean ) : void => {
236233 if ( this . destroyed ) return ;
237234 if ( minX === this . minX && minY === this . minY && maxX === this . maxX && maxY === this . maxY && ! force ) return ;
238- this . updateRect ( { minX, minY, maxX, maxY, x : this . x , y : this . y } ) ;
235+ this . unstable = true ;
236+ this . rect = [ minX , minY , maxX - minX , maxY - minY ] ;
239237 this . hitTest . update ( this , { minX, minY, maxX, maxY, x : this . x , y : this . y } , force ) ;
240238 } ;
241239
0 commit comments