@@ -7,39 +7,22 @@ import { shallowEqual } from '../utils/shallow-equal';
7
7
import type { World } from '../world/world' ;
8
8
import { isModifier } from './modifier' ;
9
9
import { setChanged } from './modifiers/changed' ;
10
- import type { Query } from './query' ;
11
10
import type {
12
11
InstancesFromParameters ,
12
+ Query ,
13
13
QueryParameter ,
14
14
QueryResult ,
15
15
QueryResultOptions ,
16
16
StoresFromParameters ,
17
17
} from './types' ;
18
18
19
19
export function createQueryResult < T extends QueryParameter [ ] > (
20
- query : Query ,
21
20
world : World ,
22
- params : T
21
+ entities : Entity [ ] ,
22
+ query : Query
23
23
) : QueryResult < T > {
24
- query . commitRemovals ( world ) ;
25
- const entities = query . entities . dense . slice ( ) as Entity [ ] ;
26
-
27
- // Clear so it can accumulate again.
28
- if ( query . isTracking ) {
29
- query . entities . clear ( ) ;
30
-
31
- // @todo : Need to improve the performance of this loop.
32
- for ( const eid of entities ) {
33
- query . resetTrackingBitmasks ( eid ) ;
34
- }
35
- }
36
-
37
- const stores : Store < any > [ ] = [ ] ;
38
- const traits : Trait [ ] = [ ] ;
39
-
40
- // Get the traits for the query parameters in the order they are defined
41
- // and not the order they are sorted for the query hash.
42
- getQueryStores < T > ( params , traits , stores , world ) ;
24
+ const traits = [ ...query . resultTraits ] ;
25
+ const stores = [ ...query . resultStores ] ;
43
26
44
27
const results = Object . assign ( entities , {
45
28
updateEach (
@@ -236,7 +219,7 @@ export function createQueryResult<T extends QueryParameter[]>(
236
219
}
237
220
}
238
221
239
- /* @inline */ function getQueryStores < T extends QueryParameter [ ] > (
222
+ /* @inline */ export function getQueryStores < T extends QueryParameter [ ] > (
240
223
params : T ,
241
224
traits : Trait [ ] ,
242
225
stores : Store < any > [ ] ,
@@ -262,3 +245,14 @@ export function createQueryResult<T extends QueryParameter[]>(
262
245
}
263
246
}
264
247
}
248
+
249
+ export function createEmptyQueryResult ( ) : QueryResult < QueryParameter [ ] > {
250
+ const results = Object . assign ( [ ] , {
251
+ updateEach : ( ) => results ,
252
+ useStores : ( ) => results ,
253
+ select : ( ) => results ,
254
+ sort : ( ) => results ,
255
+ } ) as QueryResult < QueryParameter [ ] > ;
256
+
257
+ return results ;
258
+ }
0 commit comments