koota 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -3
- package/dist/{chunk-ZHBGFPP2.js → chunk-G375UJC5.js} +123 -131
- package/dist/index.cjs +123 -129
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1 -1
- package/dist/react.cjs +122 -140
- package/dist/react.d.cts +2 -4
- package/dist/react.d.ts +2 -4
- package/dist/react.js +7 -14
- package/dist/{world-CHO2npCL.d.cts → world-BFj5O4_U.d.cts} +13 -3
- package/dist/{world-CHO2npCL.d.ts → world-BFj5O4_U.d.ts} +13 -3
- package/package.json +2 -2
- package/react/index.cjs +122 -140
- package/react/index.d.cts +2 -4
- package/react/index.d.ts +2 -4
- package/react/index.js +7 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koota",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "🌎 Performant real-time state management for React and TypeScript",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"type": "module",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"react": ">=18.0.0",
|
|
36
36
|
"react-dom": ">=18.0.0",
|
|
37
37
|
"tsup": "^8.3.0",
|
|
38
|
-
"@koota/core": "0.0.1",
|
|
39
38
|
"tsconfig": "0.1.0",
|
|
39
|
+
"@koota/core": "0.0.1",
|
|
40
40
|
"@koota/react": "0.0.1"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
package/react/index.cjs
CHANGED
|
@@ -3,10 +3,6 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __typeError = (msg) => {
|
|
7
|
-
throw TypeError(msg);
|
|
8
|
-
};
|
|
9
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
6
|
var __export = (target, all) => {
|
|
11
7
|
for (var name in all)
|
|
12
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -20,25 +16,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
20
16
|
return to;
|
|
21
17
|
};
|
|
22
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
24
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
25
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
26
|
-
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
27
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
28
|
-
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
29
|
-
set _(value) {
|
|
30
|
-
__privateSet(obj, member, value, setter);
|
|
31
|
-
},
|
|
32
|
-
get _() {
|
|
33
|
-
return __privateGet(obj, member, getter);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
19
|
|
|
37
20
|
// src/react.ts
|
|
38
21
|
var react_exports = {};
|
|
39
22
|
__export(react_exports, {
|
|
40
23
|
WorldProvider: () => WorldProvider,
|
|
41
|
-
getDefaultWorld: () => getDefaultWorld,
|
|
42
24
|
useActions: () => useActions,
|
|
43
25
|
useQuery: () => useQuery,
|
|
44
26
|
useQueryFirst: () => useQueryFirst,
|
|
@@ -103,7 +85,7 @@ var universe = {
|
|
|
103
85
|
cachedQueries: /* @__PURE__ */ new Map(),
|
|
104
86
|
worldIndex: createWorldIndex(),
|
|
105
87
|
reset: () => {
|
|
106
|
-
universe.worlds = new Array(WORLD_ID_BITS ** 2);
|
|
88
|
+
universe.worlds = new Array(WORLD_ID_BITS ** 2).fill(null);
|
|
107
89
|
universe.cachedQueries = /* @__PURE__ */ new Map();
|
|
108
90
|
universe.worldIndex = createWorldIndex();
|
|
109
91
|
}
|
|
@@ -115,9 +97,9 @@ var ModifierData = class {
|
|
|
115
97
|
this.type = type;
|
|
116
98
|
this.id = id;
|
|
117
99
|
this.traits = traits;
|
|
118
|
-
__publicField(this, "traitIds");
|
|
119
100
|
this.traitIds = traits.map((trait2) => trait2[$internal].id);
|
|
120
101
|
}
|
|
102
|
+
traitIds;
|
|
121
103
|
};
|
|
122
104
|
|
|
123
105
|
// ../core/src/query/utils/tracking-cursor.ts
|
|
@@ -198,8 +180,9 @@ function getRelationTrait(relation2, traitFactory, pairsMap, target) {
|
|
|
198
180
|
}
|
|
199
181
|
var getRelationTargets = (world, relation2, entity) => {
|
|
200
182
|
const ctx = world[$internal];
|
|
201
|
-
const traits = ctx.entityTraits.get(entity)
|
|
183
|
+
const traits = ctx.entityTraits.get(entity);
|
|
202
184
|
const targets = [];
|
|
185
|
+
if (!traits) return targets;
|
|
203
186
|
for (const trait2 of traits) {
|
|
204
187
|
const traitCtx = trait2[$internal];
|
|
205
188
|
if (traitCtx.relation === relation2 && traitCtx.pairTarget !== Wildcard) {
|
|
@@ -231,15 +214,15 @@ var incrementWorldBitflag = (world) => {
|
|
|
231
214
|
|
|
232
215
|
// ../core/src/trait/trait-data.ts
|
|
233
216
|
var TraitData = class {
|
|
217
|
+
generationId;
|
|
218
|
+
bitflag;
|
|
219
|
+
trait;
|
|
220
|
+
store;
|
|
221
|
+
queries;
|
|
222
|
+
notQueries;
|
|
223
|
+
schema;
|
|
224
|
+
changedSubscriptions;
|
|
234
225
|
constructor(world, trait2) {
|
|
235
|
-
__publicField(this, "generationId");
|
|
236
|
-
__publicField(this, "bitflag");
|
|
237
|
-
__publicField(this, "trait");
|
|
238
|
-
__publicField(this, "store");
|
|
239
|
-
__publicField(this, "queries");
|
|
240
|
-
__publicField(this, "notQueries");
|
|
241
|
-
__publicField(this, "schema");
|
|
242
|
-
__publicField(this, "changedSubscriptions");
|
|
243
226
|
const ctx = world[$internal];
|
|
244
227
|
const traitCtx = trait2[$internal];
|
|
245
228
|
this.generationId = ctx.entityMasks.length - 1;
|
|
@@ -572,47 +555,47 @@ var getAliveEntities = (index) => {
|
|
|
572
555
|
// ../core/src/entity/entity-methods-patch.ts
|
|
573
556
|
Number.prototype.add = function(...traits) {
|
|
574
557
|
const worldId = this >>> WORLD_ID_SHIFT;
|
|
575
|
-
const world = universe.worlds[worldId];
|
|
558
|
+
const world = universe.worlds[worldId].deref();
|
|
576
559
|
return addTrait(world, this, ...traits);
|
|
577
560
|
};
|
|
578
561
|
Number.prototype.remove = function(...traits) {
|
|
579
562
|
const worldId = this >>> WORLD_ID_SHIFT;
|
|
580
|
-
const world = universe.worlds[worldId];
|
|
563
|
+
const world = universe.worlds[worldId].deref();
|
|
581
564
|
return removeTrait(world, this, ...traits);
|
|
582
565
|
};
|
|
583
566
|
Number.prototype.has = function(trait2) {
|
|
584
567
|
const worldId = this >>> WORLD_ID_SHIFT;
|
|
585
|
-
const world = universe.worlds[worldId];
|
|
568
|
+
const world = universe.worlds[worldId].deref();
|
|
586
569
|
return hasTrait(world, this, trait2);
|
|
587
570
|
};
|
|
588
571
|
Number.prototype.destroy = function() {
|
|
589
572
|
const worldId = this >>> WORLD_ID_SHIFT;
|
|
590
|
-
const world = universe.worlds[worldId];
|
|
573
|
+
const world = universe.worlds[worldId].deref();
|
|
591
574
|
return destroyEntity(world, this);
|
|
592
575
|
};
|
|
593
576
|
Number.prototype.changed = function(trait2) {
|
|
594
577
|
const worldId = this >>> WORLD_ID_SHIFT;
|
|
595
|
-
const world = universe.worlds[worldId];
|
|
578
|
+
const world = universe.worlds[worldId].deref();
|
|
596
579
|
return setChanged(world, this, trait2);
|
|
597
580
|
};
|
|
598
581
|
Number.prototype.get = function(trait2) {
|
|
599
582
|
const worldId = this >>> WORLD_ID_SHIFT;
|
|
600
|
-
const world = universe.worlds[worldId];
|
|
583
|
+
const world = universe.worlds[worldId].deref();
|
|
601
584
|
return getTrait(world, this, trait2);
|
|
602
585
|
};
|
|
603
586
|
Number.prototype.set = function(trait2, value, triggerChanged = true) {
|
|
604
587
|
const worldId = this >>> WORLD_ID_SHIFT;
|
|
605
|
-
const world = universe.worlds[worldId];
|
|
588
|
+
const world = universe.worlds[worldId].deref();
|
|
606
589
|
setTrait(world, this, trait2, value, triggerChanged);
|
|
607
590
|
};
|
|
608
591
|
Number.prototype.targetsFor = function(relation2) {
|
|
609
592
|
const worldId = this >>> WORLD_ID_SHIFT;
|
|
610
|
-
const world = universe.worlds[worldId];
|
|
593
|
+
const world = universe.worlds[worldId].deref();
|
|
611
594
|
return getRelationTargets(world, relation2, this);
|
|
612
595
|
};
|
|
613
596
|
Number.prototype.targetFor = function(relation2) {
|
|
614
597
|
const worldId = this >>> WORLD_ID_SHIFT;
|
|
615
|
-
const world = universe.worlds[worldId];
|
|
598
|
+
const world = universe.worlds[worldId].deref();
|
|
616
599
|
return getRelationTargets(world, relation2, this)[0];
|
|
617
600
|
};
|
|
618
601
|
Number.prototype.id = function() {
|
|
@@ -621,7 +604,7 @@ Number.prototype.id = function() {
|
|
|
621
604
|
};
|
|
622
605
|
Number.prototype.isAlive = function() {
|
|
623
606
|
const worldId = this >>> WORLD_ID_SHIFT;
|
|
624
|
-
const world = universe.worlds[worldId];
|
|
607
|
+
const world = universe.worlds[worldId].deref();
|
|
625
608
|
return isEntityAlive(world[$internal].entityIndex, this);
|
|
626
609
|
};
|
|
627
610
|
|
|
@@ -687,57 +670,51 @@ function destroyEntity(world, entity) {
|
|
|
687
670
|
}
|
|
688
671
|
|
|
689
672
|
// ../core/src/utils/sparse-set.ts
|
|
690
|
-
var _dense, _sparse, _cursor;
|
|
691
673
|
var SparseSet = class {
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
__privateAdd(this, _cursor, 0);
|
|
696
|
-
}
|
|
674
|
+
#dense = [];
|
|
675
|
+
#sparse = [];
|
|
676
|
+
#cursor = 0;
|
|
697
677
|
has(val) {
|
|
698
|
-
const index =
|
|
699
|
-
return index <
|
|
678
|
+
const index = this.#sparse[val];
|
|
679
|
+
return index < this.#cursor && this.#dense[index] === val;
|
|
700
680
|
}
|
|
701
681
|
add(val) {
|
|
702
682
|
if (this.has(val)) return;
|
|
703
|
-
|
|
704
|
-
|
|
683
|
+
this.#sparse[val] = this.#cursor;
|
|
684
|
+
this.#dense[this.#cursor++] = val;
|
|
705
685
|
}
|
|
706
686
|
remove(val) {
|
|
707
687
|
if (!this.has(val)) return;
|
|
708
|
-
const index =
|
|
709
|
-
|
|
710
|
-
const swapped =
|
|
688
|
+
const index = this.#sparse[val];
|
|
689
|
+
this.#cursor--;
|
|
690
|
+
const swapped = this.#dense[this.#cursor];
|
|
711
691
|
if (swapped !== val) {
|
|
712
|
-
|
|
713
|
-
|
|
692
|
+
this.#dense[index] = swapped;
|
|
693
|
+
this.#sparse[swapped] = index;
|
|
714
694
|
}
|
|
715
695
|
}
|
|
716
696
|
clear() {
|
|
717
|
-
for (let i = 0; i <
|
|
718
|
-
|
|
697
|
+
for (let i = 0; i < this.#cursor; i++) {
|
|
698
|
+
this.#sparse[this.#dense[i]] = 0;
|
|
719
699
|
}
|
|
720
|
-
|
|
700
|
+
this.#cursor = 0;
|
|
721
701
|
}
|
|
722
702
|
sort() {
|
|
723
|
-
|
|
724
|
-
for (let i = 0; i <
|
|
725
|
-
|
|
703
|
+
this.#dense.sort((a, b) => a - b);
|
|
704
|
+
for (let i = 0; i < this.#dense.length; i++) {
|
|
705
|
+
this.#sparse[this.#dense[i]] = i;
|
|
726
706
|
}
|
|
727
707
|
}
|
|
728
708
|
getIndex(val) {
|
|
729
|
-
return
|
|
709
|
+
return this.#sparse[val];
|
|
730
710
|
}
|
|
731
711
|
get dense() {
|
|
732
|
-
return
|
|
712
|
+
return this.#dense.slice(0, this.#cursor);
|
|
733
713
|
}
|
|
734
714
|
get sparse() {
|
|
735
|
-
return
|
|
715
|
+
return this.#sparse;
|
|
736
716
|
}
|
|
737
717
|
};
|
|
738
|
-
_dense = new WeakMap();
|
|
739
|
-
_sparse = new WeakMap();
|
|
740
|
-
_cursor = new WeakMap();
|
|
741
718
|
|
|
742
719
|
// ../core/src/query/utils/create-query-hash.ts
|
|
743
720
|
var sortedIDs = new Float32Array(1024);
|
|
@@ -767,22 +744,22 @@ var createQueryHash = (parameters) => {
|
|
|
767
744
|
// ../core/src/query/query.ts
|
|
768
745
|
var IsExcluded = trait();
|
|
769
746
|
var Query = class {
|
|
747
|
+
version = 0;
|
|
748
|
+
world;
|
|
749
|
+
parameters;
|
|
750
|
+
hash;
|
|
751
|
+
traits = [];
|
|
752
|
+
traitData = { required: [], forbidden: [], or: [], added: [], removed: [], changed: [], all: [] };
|
|
753
|
+
bitmasks = [];
|
|
754
|
+
generations;
|
|
755
|
+
entities = new SparseSet();
|
|
756
|
+
isTracking = false;
|
|
757
|
+
hasChangedModifiers = false;
|
|
758
|
+
changedTraits = /* @__PURE__ */ new Set();
|
|
759
|
+
toRemove = new SparseSet();
|
|
760
|
+
addSubscriptions = /* @__PURE__ */ new Set();
|
|
761
|
+
removeSubscriptions = /* @__PURE__ */ new Set();
|
|
770
762
|
constructor(world, parameters = []) {
|
|
771
|
-
__publicField(this, "version", 0);
|
|
772
|
-
__publicField(this, "world");
|
|
773
|
-
__publicField(this, "parameters");
|
|
774
|
-
__publicField(this, "hash");
|
|
775
|
-
__publicField(this, "traits", []);
|
|
776
|
-
__publicField(this, "traitData", { required: [], forbidden: [], or: [], added: [], removed: [], changed: [], all: [] });
|
|
777
|
-
__publicField(this, "bitmasks", []);
|
|
778
|
-
__publicField(this, "generations");
|
|
779
|
-
__publicField(this, "entities", new SparseSet());
|
|
780
|
-
__publicField(this, "isTracking", false);
|
|
781
|
-
__publicField(this, "hasChangedModifiers", false);
|
|
782
|
-
__publicField(this, "changedTraits", /* @__PURE__ */ new Set());
|
|
783
|
-
__publicField(this, "toRemove", new SparseSet());
|
|
784
|
-
__publicField(this, "addSubscriptions", /* @__PURE__ */ new Set());
|
|
785
|
-
__publicField(this, "removeSubscriptions", /* @__PURE__ */ new Set());
|
|
786
763
|
this.world = world;
|
|
787
764
|
this.parameters = parameters;
|
|
788
765
|
const ctx = world[$internal];
|
|
@@ -1192,6 +1169,10 @@ function createQueryResult(query, world, params) {
|
|
|
1192
1169
|
stores.length = 0;
|
|
1193
1170
|
getQueryStores(params2, traits, stores, world);
|
|
1194
1171
|
return results;
|
|
1172
|
+
},
|
|
1173
|
+
sort(callback = (a, b) => getEntityId(a) - getEntityId(b)) {
|
|
1174
|
+
Array.prototype.sort.call(entities, callback);
|
|
1175
|
+
return results;
|
|
1195
1176
|
}
|
|
1196
1177
|
});
|
|
1197
1178
|
return results;
|
|
@@ -1216,46 +1197,44 @@ function getQueryStores(params, traits, stores, world) {
|
|
|
1216
1197
|
}
|
|
1217
1198
|
|
|
1218
1199
|
// ../core/src/world/world.ts
|
|
1219
|
-
var _a, _id, _isInitialized;
|
|
1220
|
-
_a = $internal;
|
|
1221
1200
|
var World = class {
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
});
|
|
1241
|
-
__privateAdd(this, _isInitialized, false);
|
|
1242
|
-
__publicField(this, "traits", /* @__PURE__ */ new Set());
|
|
1243
|
-
this.init(...traits);
|
|
1244
|
-
}
|
|
1201
|
+
#id = allocateWorldId(universe.worldIndex);
|
|
1202
|
+
[$internal] = {
|
|
1203
|
+
entityIndex: createEntityIndex(this.#id),
|
|
1204
|
+
entityMasks: [[]],
|
|
1205
|
+
entityTraits: /* @__PURE__ */ new Map(),
|
|
1206
|
+
bitflag: 1,
|
|
1207
|
+
traitData: /* @__PURE__ */ new Map(),
|
|
1208
|
+
queries: /* @__PURE__ */ new Set(),
|
|
1209
|
+
queriesHashMap: /* @__PURE__ */ new Map(),
|
|
1210
|
+
notQueries: /* @__PURE__ */ new Set(),
|
|
1211
|
+
dirtyQueries: /* @__PURE__ */ new Set(),
|
|
1212
|
+
relationTargetEntities: /* @__PURE__ */ new Set(),
|
|
1213
|
+
dirtyMasks: /* @__PURE__ */ new Map(),
|
|
1214
|
+
trackingSnapshots: /* @__PURE__ */ new Map(),
|
|
1215
|
+
changedMasks: /* @__PURE__ */ new Map(),
|
|
1216
|
+
worldEntity: null,
|
|
1217
|
+
trackedTraits: /* @__PURE__ */ new Set()
|
|
1218
|
+
};
|
|
1245
1219
|
get id() {
|
|
1246
|
-
return
|
|
1220
|
+
return this.#id;
|
|
1247
1221
|
}
|
|
1222
|
+
#isInitialized = false;
|
|
1248
1223
|
get isInitialized() {
|
|
1249
|
-
return
|
|
1224
|
+
return this.#isInitialized;
|
|
1250
1225
|
}
|
|
1251
1226
|
get entities() {
|
|
1252
1227
|
return getAliveEntities(this[$internal].entityIndex);
|
|
1253
1228
|
}
|
|
1229
|
+
traits = /* @__PURE__ */ new Set();
|
|
1230
|
+
constructor(...traits) {
|
|
1231
|
+
this.init(...traits);
|
|
1232
|
+
}
|
|
1254
1233
|
init(...traits) {
|
|
1255
1234
|
const ctx = this[$internal];
|
|
1256
|
-
if (
|
|
1257
|
-
|
|
1258
|
-
universe.worlds[
|
|
1235
|
+
if (this.#isInitialized) return;
|
|
1236
|
+
this.#isInitialized = true;
|
|
1237
|
+
universe.worlds[this.#id] = new WeakRef(this);
|
|
1259
1238
|
const cursor2 = getTrackingCursor();
|
|
1260
1239
|
for (let i = 0; i < cursor2; i++) {
|
|
1261
1240
|
setTrackingMasks(this, i);
|
|
@@ -1289,22 +1268,28 @@ var World = class {
|
|
|
1289
1268
|
this[$internal].worldEntity = null;
|
|
1290
1269
|
this.entities.forEach((entity) => destroyEntity(this, entity));
|
|
1291
1270
|
this.reset();
|
|
1292
|
-
|
|
1293
|
-
releaseWorldId(universe.worldIndex,
|
|
1294
|
-
universe.worlds
|
|
1271
|
+
this.#isInitialized = false;
|
|
1272
|
+
releaseWorldId(universe.worldIndex, this.#id);
|
|
1273
|
+
universe.worlds[this.#id] = null;
|
|
1295
1274
|
}
|
|
1296
|
-
reset() {
|
|
1275
|
+
reset(options = {}) {
|
|
1297
1276
|
const ctx = this[$internal];
|
|
1298
|
-
|
|
1277
|
+
const shouldPreserveTraits = options.preserveTraits || options.preserveSubscriptions;
|
|
1278
|
+
const shouldPreserveQueries = options.preserveQueries || options.preserveSubscriptions;
|
|
1279
|
+
ctx.entityIndex = createEntityIndex(this.#id);
|
|
1299
1280
|
ctx.entityTraits.clear();
|
|
1300
|
-
ctx.notQueries.clear();
|
|
1301
1281
|
ctx.entityMasks = [[]];
|
|
1302
1282
|
ctx.bitflag = 1;
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1283
|
+
if (!shouldPreserveTraits) {
|
|
1284
|
+
ctx.traitData.clear();
|
|
1285
|
+
this.traits.clear();
|
|
1286
|
+
}
|
|
1287
|
+
if (!shouldPreserveQueries) {
|
|
1288
|
+
ctx.queries.clear();
|
|
1289
|
+
ctx.queriesHashMap.clear();
|
|
1290
|
+
ctx.dirtyQueries.clear();
|
|
1291
|
+
ctx.notQueries.clear();
|
|
1292
|
+
}
|
|
1308
1293
|
ctx.relationTargetEntities.clear();
|
|
1309
1294
|
ctx.trackingSnapshots.clear();
|
|
1310
1295
|
ctx.dirtyMasks.clear();
|
|
@@ -1366,17 +1351,17 @@ var World = class {
|
|
|
1366
1351
|
};
|
|
1367
1352
|
}
|
|
1368
1353
|
};
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
}
|
|
1354
|
+
var worldFinalizer = new FinalizationRegistry((worldId) => {
|
|
1355
|
+
universe.worlds[worldId] = null;
|
|
1356
|
+
releaseWorldId(universe.worldIndex, worldId);
|
|
1357
|
+
});
|
|
1374
1358
|
|
|
1375
1359
|
// ../core/src/query/utils/cache-query.ts
|
|
1376
1360
|
function cacheQuery(...parameters) {
|
|
1377
1361
|
const hash = createQueryHash(parameters);
|
|
1378
|
-
for (const
|
|
1379
|
-
if (!
|
|
1362
|
+
for (const worldRef of universe.worlds) {
|
|
1363
|
+
if (!worldRef) continue;
|
|
1364
|
+
const world = worldRef.deref();
|
|
1380
1365
|
const ctx = world[$internal];
|
|
1381
1366
|
if (!ctx.queriesHashMap.has(hash)) {
|
|
1382
1367
|
const query = new Query(world, parameters);
|
|
@@ -1387,6 +1372,9 @@ function cacheQuery(...parameters) {
|
|
|
1387
1372
|
return hash;
|
|
1388
1373
|
}
|
|
1389
1374
|
|
|
1375
|
+
// ../core/src/query/types.ts
|
|
1376
|
+
var $parameters = Symbol();
|
|
1377
|
+
|
|
1390
1378
|
// ../react/src/hooks/use-query.ts
|
|
1391
1379
|
var import_react3 = require("react");
|
|
1392
1380
|
|
|
@@ -1397,14 +1385,9 @@ var import_react2 = require("react");
|
|
|
1397
1385
|
var import_react = require("react");
|
|
1398
1386
|
var WorldContext = (0, import_react.createContext)(null);
|
|
1399
1387
|
|
|
1400
|
-
// ../react/src/world/default-world.ts
|
|
1401
|
-
var defaultWorld = createWorld();
|
|
1402
|
-
var getDefaultWorld = () => defaultWorld;
|
|
1403
|
-
|
|
1404
1388
|
// ../react/src/world/use-world.ts
|
|
1405
1389
|
function useWorld() {
|
|
1406
|
-
|
|
1407
|
-
return world;
|
|
1390
|
+
return (0, import_react2.useContext)(WorldContext);
|
|
1408
1391
|
}
|
|
1409
1392
|
|
|
1410
1393
|
// ../react/src/hooks/use-query.ts
|
|
@@ -1415,17 +1398,17 @@ function useQuery(...parameters) {
|
|
|
1415
1398
|
const query = world[$internal].queriesHashMap.get(hash2);
|
|
1416
1399
|
return [hash2, query.version];
|
|
1417
1400
|
}, [parameters]);
|
|
1418
|
-
const [entities, setEntities] = (0, import_react3.useState)(() => world.query(hash));
|
|
1401
|
+
const [entities, setEntities] = (0, import_react3.useState)(() => world.query(hash).sort());
|
|
1419
1402
|
(0, import_react3.useEffect)(() => {
|
|
1420
1403
|
const unsubAdd = world.onAdd(parameters, () => {
|
|
1421
|
-
setEntities(world.query(hash));
|
|
1404
|
+
setEntities(world.query(hash).sort());
|
|
1422
1405
|
});
|
|
1423
1406
|
const unsubRemove = world.onRemove(parameters, () => {
|
|
1424
|
-
setEntities(world.query(hash));
|
|
1407
|
+
setEntities(world.query(hash).sort());
|
|
1425
1408
|
});
|
|
1426
1409
|
const query = world[$internal].queriesHashMap.get(hash);
|
|
1427
1410
|
if (query.version !== initialVersion) {
|
|
1428
|
-
setEntities(world.query(hash));
|
|
1411
|
+
setEntities(world.query(hash).sort());
|
|
1429
1412
|
}
|
|
1430
1413
|
return () => {
|
|
1431
1414
|
unsubAdd();
|
|
@@ -1532,7 +1515,6 @@ function useTraitEffect(target, trait2, callback) {
|
|
|
1532
1515
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1533
1516
|
0 && (module.exports = {
|
|
1534
1517
|
WorldProvider,
|
|
1535
|
-
getDefaultWorld,
|
|
1536
1518
|
useActions,
|
|
1537
1519
|
useQuery,
|
|
1538
1520
|
useQueryFirst,
|
package/react/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Q as QueryParameter,
|
|
1
|
+
import { Q as QueryParameter, p as QueryResult, W as World, T as Trait, l as Entity, h as TraitInstance } from '../dist/world-BFj5O4_U.cjs';
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
|
|
4
4
|
declare function useQuery<T extends QueryParameter[]>(...parameters: T): QueryResult<T>;
|
|
@@ -18,6 +18,4 @@ declare function useQueryFirst<T extends QueryParameter[]>(...parameters: T): En
|
|
|
18
18
|
|
|
19
19
|
declare function useTraitEffect<T extends Trait>(target: Entity | World, trait: T, callback: (value: TraitInstance<T> | undefined) => void): void;
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export { WorldProvider, getDefaultWorld, useActions, useQuery, useQueryFirst, useTrait, useTraitEffect, useWorld };
|
|
21
|
+
export { WorldProvider, useActions, useQuery, useQueryFirst, useTrait, useTraitEffect, useWorld };
|
package/react/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Q as QueryParameter,
|
|
1
|
+
import { Q as QueryParameter, p as QueryResult, W as World, T as Trait, l as Entity, h as TraitInstance } from '../dist/world-BFj5O4_U.js';
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
|
|
4
4
|
declare function useQuery<T extends QueryParameter[]>(...parameters: T): QueryResult<T>;
|
|
@@ -18,6 +18,4 @@ declare function useQueryFirst<T extends QueryParameter[]>(...parameters: T): En
|
|
|
18
18
|
|
|
19
19
|
declare function useTraitEffect<T extends Trait>(target: Entity | World, trait: T, callback: (value: TraitInstance<T> | undefined) => void): void;
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export { WorldProvider, getDefaultWorld, useActions, useQuery, useQueryFirst, useTrait, useTraitEffect, useWorld };
|
|
21
|
+
export { WorldProvider, useActions, useQuery, useQueryFirst, useTrait, useTraitEffect, useWorld };
|
package/react/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
$internal,
|
|
3
|
-
cacheQuery
|
|
4
|
-
|
|
5
|
-
} from "../dist/chunk-ZHBGFPP2.js";
|
|
3
|
+
cacheQuery
|
|
4
|
+
} from "../dist/chunk-G375UJC5.js";
|
|
6
5
|
|
|
7
6
|
// ../react/src/hooks/use-query.ts
|
|
8
7
|
import { useEffect, useMemo, useState } from "react";
|
|
@@ -14,14 +13,9 @@ import { useContext } from "react";
|
|
|
14
13
|
import { createContext } from "react";
|
|
15
14
|
var WorldContext = createContext(null);
|
|
16
15
|
|
|
17
|
-
// ../react/src/world/default-world.ts
|
|
18
|
-
var defaultWorld = createWorld();
|
|
19
|
-
var getDefaultWorld = () => defaultWorld;
|
|
20
|
-
|
|
21
16
|
// ../react/src/world/use-world.ts
|
|
22
17
|
function useWorld() {
|
|
23
|
-
|
|
24
|
-
return world;
|
|
18
|
+
return useContext(WorldContext);
|
|
25
19
|
}
|
|
26
20
|
|
|
27
21
|
// ../react/src/hooks/use-query.ts
|
|
@@ -32,17 +26,17 @@ function useQuery(...parameters) {
|
|
|
32
26
|
const query = world[$internal].queriesHashMap.get(hash2);
|
|
33
27
|
return [hash2, query.version];
|
|
34
28
|
}, [parameters]);
|
|
35
|
-
const [entities, setEntities] = useState(() => world.query(hash));
|
|
29
|
+
const [entities, setEntities] = useState(() => world.query(hash).sort());
|
|
36
30
|
useEffect(() => {
|
|
37
31
|
const unsubAdd = world.onAdd(parameters, () => {
|
|
38
|
-
setEntities(world.query(hash));
|
|
32
|
+
setEntities(world.query(hash).sort());
|
|
39
33
|
});
|
|
40
34
|
const unsubRemove = world.onRemove(parameters, () => {
|
|
41
|
-
setEntities(world.query(hash));
|
|
35
|
+
setEntities(world.query(hash).sort());
|
|
42
36
|
});
|
|
43
37
|
const query = world[$internal].queriesHashMap.get(hash);
|
|
44
38
|
if (query.version !== initialVersion) {
|
|
45
|
-
setEntities(world.query(hash));
|
|
39
|
+
setEntities(world.query(hash).sort());
|
|
46
40
|
}
|
|
47
41
|
return () => {
|
|
48
42
|
unsubAdd();
|
|
@@ -148,7 +142,6 @@ function useTraitEffect(target, trait, callback) {
|
|
|
148
142
|
}
|
|
149
143
|
export {
|
|
150
144
|
WorldProvider,
|
|
151
|
-
getDefaultWorld,
|
|
152
145
|
useActions,
|
|
153
146
|
useQuery,
|
|
154
147
|
useQueryFirst,
|