File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -180,6 +180,12 @@ export class World {
180180 // Create new world entity.
181181 ctx . worldEntity = createEntity ( this , IsExcluded ) ;
182182
183+ // Restore cached queries.
184+ for ( const [ hash , parameters ] of universe . cachedQueries ) {
185+ const query = createQuery ( this , parameters ) ;
186+ ctx . queriesHashMap . set ( hash , query ) ;
187+ }
188+
183189 for ( const sub of ctx . resetSubscriptions ) {
184190 sub ( this ) ;
185191 }
Original file line number Diff line number Diff line change @@ -424,4 +424,24 @@ describe('Query', () => {
424424 expect ( entities [ i ] . id ( ) ) . toBe ( i + 1 ) ;
425425 }
426426 } ) ;
427+
428+ it ( 'cached query should return values after reset' , ( ) => {
429+ const movementQuery = cacheQuery ( Foo ) ;
430+
431+ const spawnEntities = ( ) => {
432+ for ( let i = 0 ; i < 100 ; i ++ ) {
433+ world . spawn ( Foo ) ;
434+ }
435+ } ;
436+
437+ spawnEntities ( ) ;
438+ const resultsBefore = world . query ( movementQuery ) ;
439+
440+ world . reset ( ) ;
441+ spawnEntities ( ) ;
442+
443+ const resultsAfter = world . query ( movementQuery ) ;
444+
445+ expect ( resultsAfter . length ) . toBe ( resultsBefore . length ) ;
446+ } ) ;
427447} ) ;
You can’t perform that action at this time.
0 commit comments