koota 0.4.0 → 0.4.2
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 +2 -2
- package/dist/{chunk-HKEOEIY2.js → chunk-IOZKRHDY.js} +22 -5
- package/dist/index.cjs +20 -5
- package/dist/index.js +2 -1
- package/dist/react.cjs +20 -5
- package/dist/react.js +2 -1
- package/package.json +3 -3
- package/react/index.cjs +20 -5
- package/react/index.js +2 -1
package/README.md
CHANGED
|
@@ -447,7 +447,7 @@ These are more like notes for docs. Take a look around, ask questions. Eventuall
|
|
|
447
447
|
|
|
448
448
|
This is where all data is stored. We have methods on entities but this is a bit of a trick, entities don't actually store any data and instead it is operating on the connected world. Each world has its own set of entities that do not overlap with another. Typically you only need one world.
|
|
449
449
|
|
|
450
|
-
Worlds can have traits, which is our version of a singleton. Use these for global resources like a clock. Each world gets its own entity used for world traits. This entity is
|
|
450
|
+
Worlds can have traits, which is our version of a singleton. Use these for global resources like a clock. Each world gets its own entity used for world traits. This entity is not queryable but will show up in the list of active entities making the only way to retrieve a world trait with its API.
|
|
451
451
|
|
|
452
452
|
```js
|
|
453
453
|
// Spawns an entity
|
|
@@ -533,7 +533,7 @@ entity.remove(Position)
|
|
|
533
533
|
|
|
534
534
|
// Checks if the entity has the trait
|
|
535
535
|
// Return boolean
|
|
536
|
-
const result =
|
|
536
|
+
const result = entity.has(Position)
|
|
537
537
|
|
|
538
538
|
// Gets a snapshot instance of the trait
|
|
539
539
|
// Return TraitInstance
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
1
3
|
// ../core/src/common.ts
|
|
2
4
|
var $internal = Symbol("internal");
|
|
3
5
|
|
|
@@ -487,6 +489,7 @@ function setChanged(world, entity, trait2) {
|
|
|
487
489
|
}
|
|
488
490
|
for (const query of data.queries) {
|
|
489
491
|
if (!query.hasChangedModifiers) continue;
|
|
492
|
+
if (!query.changedTraits.has(trait2)) continue;
|
|
490
493
|
let match = query.check(world, entity, { type: "change", traitData: data });
|
|
491
494
|
if (match) query.add(entity);
|
|
492
495
|
else query.remove(world, entity);
|
|
@@ -975,7 +978,12 @@ var Query = class {
|
|
|
975
978
|
run(world) {
|
|
976
979
|
this.commitRemovals(world);
|
|
977
980
|
const result = this.entities.dense.slice();
|
|
978
|
-
if (this.isTracking)
|
|
981
|
+
if (this.isTracking) {
|
|
982
|
+
this.entities.clear();
|
|
983
|
+
for (const eid of result) {
|
|
984
|
+
this.resetTrackingBitmasks(eid);
|
|
985
|
+
}
|
|
986
|
+
}
|
|
979
987
|
return result;
|
|
980
988
|
}
|
|
981
989
|
add(entity) {
|
|
@@ -1098,7 +1106,12 @@ function shallowEqual(obj1, obj2) {
|
|
|
1098
1106
|
function createQueryResult(query, world, params) {
|
|
1099
1107
|
query.commitRemovals(world);
|
|
1100
1108
|
const entities = query.entities.dense.slice();
|
|
1101
|
-
if (query.isTracking)
|
|
1109
|
+
if (query.isTracking) {
|
|
1110
|
+
query.entities.clear();
|
|
1111
|
+
for (const eid of entities) {
|
|
1112
|
+
query.resetTrackingBitmasks(eid);
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1102
1115
|
const stores = [];
|
|
1103
1116
|
const traits = [];
|
|
1104
1117
|
getQueryStores(params, traits, stores, world);
|
|
@@ -1329,7 +1342,11 @@ var World = class {
|
|
|
1329
1342
|
}
|
|
1330
1343
|
reset() {
|
|
1331
1344
|
const ctx = this[$internal];
|
|
1332
|
-
this.entities.forEach((entity) =>
|
|
1345
|
+
this.entities.forEach((entity) => {
|
|
1346
|
+
if (this.has(entity)) {
|
|
1347
|
+
destroyEntity(this, entity);
|
|
1348
|
+
}
|
|
1349
|
+
});
|
|
1333
1350
|
ctx.entityIndex = createEntityIndex(this.#id);
|
|
1334
1351
|
ctx.entityTraits.clear();
|
|
1335
1352
|
ctx.entityMasks = [[]];
|
|
@@ -1354,8 +1371,8 @@ var World = class {
|
|
|
1354
1371
|
const ctx = this[$internal];
|
|
1355
1372
|
if (typeof args[0] === "string") {
|
|
1356
1373
|
const query = ctx.queriesHashMap.get(args[0]);
|
|
1357
|
-
if (!query) return [];
|
|
1358
|
-
return query.
|
|
1374
|
+
if (!query) return createQueryResult(new Query(this, []), this, []);
|
|
1375
|
+
return createQueryResult(query, this, query.parameters);
|
|
1359
1376
|
} else {
|
|
1360
1377
|
const params = args;
|
|
1361
1378
|
const hash = createQueryHash(params);
|
package/dist/index.cjs
CHANGED
|
@@ -153,6 +153,7 @@ function setChanged(world, entity, trait2) {
|
|
|
153
153
|
}
|
|
154
154
|
for (const query of data.queries) {
|
|
155
155
|
if (!query.hasChangedModifiers) continue;
|
|
156
|
+
if (!query.changedTraits.has(trait2)) continue;
|
|
156
157
|
let match = query.check(world, entity, { type: "change", traitData: data });
|
|
157
158
|
if (match) query.add(entity);
|
|
158
159
|
else query.remove(world, entity);
|
|
@@ -951,7 +952,12 @@ var Query = class {
|
|
|
951
952
|
run(world) {
|
|
952
953
|
this.commitRemovals(world);
|
|
953
954
|
const result = this.entities.dense.slice();
|
|
954
|
-
if (this.isTracking)
|
|
955
|
+
if (this.isTracking) {
|
|
956
|
+
this.entities.clear();
|
|
957
|
+
for (const eid of result) {
|
|
958
|
+
this.resetTrackingBitmasks(eid);
|
|
959
|
+
}
|
|
960
|
+
}
|
|
955
961
|
return result;
|
|
956
962
|
}
|
|
957
963
|
add(entity) {
|
|
@@ -1074,7 +1080,12 @@ function shallowEqual(obj1, obj2) {
|
|
|
1074
1080
|
function createQueryResult(query, world, params) {
|
|
1075
1081
|
query.commitRemovals(world);
|
|
1076
1082
|
const entities = query.entities.dense.slice();
|
|
1077
|
-
if (query.isTracking)
|
|
1083
|
+
if (query.isTracking) {
|
|
1084
|
+
query.entities.clear();
|
|
1085
|
+
for (const eid of entities) {
|
|
1086
|
+
query.resetTrackingBitmasks(eid);
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1078
1089
|
const stores = [];
|
|
1079
1090
|
const traits = [];
|
|
1080
1091
|
getQueryStores(params, traits, stores, world);
|
|
@@ -1305,7 +1316,11 @@ var World = class {
|
|
|
1305
1316
|
}
|
|
1306
1317
|
reset() {
|
|
1307
1318
|
const ctx = this[$internal];
|
|
1308
|
-
this.entities.forEach((entity) =>
|
|
1319
|
+
this.entities.forEach((entity) => {
|
|
1320
|
+
if (this.has(entity)) {
|
|
1321
|
+
destroyEntity(this, entity);
|
|
1322
|
+
}
|
|
1323
|
+
});
|
|
1309
1324
|
ctx.entityIndex = createEntityIndex(this.#id);
|
|
1310
1325
|
ctx.entityTraits.clear();
|
|
1311
1326
|
ctx.entityMasks = [[]];
|
|
@@ -1330,8 +1345,8 @@ var World = class {
|
|
|
1330
1345
|
const ctx = this[$internal];
|
|
1331
1346
|
if (typeof args[0] === "string") {
|
|
1332
1347
|
const query = ctx.queriesHashMap.get(args[0]);
|
|
1333
|
-
if (!query) return [];
|
|
1334
|
-
return query.
|
|
1348
|
+
if (!query) return createQueryResult(new Query(this, []), this, []);
|
|
1349
|
+
return createQueryResult(query, this, query.parameters);
|
|
1335
1350
|
} else {
|
|
1336
1351
|
const params = args;
|
|
1337
1352
|
const hash = createQueryHash(params);
|
package/dist/index.js
CHANGED
package/dist/react.cjs
CHANGED
|
@@ -135,6 +135,7 @@ function setChanged(world, entity, trait2) {
|
|
|
135
135
|
}
|
|
136
136
|
for (const query of data.queries) {
|
|
137
137
|
if (!query.hasChangedModifiers) continue;
|
|
138
|
+
if (!query.changedTraits.has(trait2)) continue;
|
|
138
139
|
let match = query.check(world, entity, { type: "change", traitData: data });
|
|
139
140
|
if (match) query.add(entity);
|
|
140
141
|
else query.remove(world, entity);
|
|
@@ -932,7 +933,12 @@ var Query = class {
|
|
|
932
933
|
run(world) {
|
|
933
934
|
this.commitRemovals(world);
|
|
934
935
|
const result = this.entities.dense.slice();
|
|
935
|
-
if (this.isTracking)
|
|
936
|
+
if (this.isTracking) {
|
|
937
|
+
this.entities.clear();
|
|
938
|
+
for (const eid of result) {
|
|
939
|
+
this.resetTrackingBitmasks(eid);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
936
942
|
return result;
|
|
937
943
|
}
|
|
938
944
|
add(entity) {
|
|
@@ -1055,7 +1061,12 @@ function shallowEqual(obj1, obj2) {
|
|
|
1055
1061
|
function createQueryResult(query, world, params) {
|
|
1056
1062
|
query.commitRemovals(world);
|
|
1057
1063
|
const entities = query.entities.dense.slice();
|
|
1058
|
-
if (query.isTracking)
|
|
1064
|
+
if (query.isTracking) {
|
|
1065
|
+
query.entities.clear();
|
|
1066
|
+
for (const eid of entities) {
|
|
1067
|
+
query.resetTrackingBitmasks(eid);
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1059
1070
|
const stores = [];
|
|
1060
1071
|
const traits = [];
|
|
1061
1072
|
getQueryStores(params, traits, stores, world);
|
|
@@ -1286,7 +1297,11 @@ var World = class {
|
|
|
1286
1297
|
}
|
|
1287
1298
|
reset() {
|
|
1288
1299
|
const ctx = this[$internal];
|
|
1289
|
-
this.entities.forEach((entity) =>
|
|
1300
|
+
this.entities.forEach((entity) => {
|
|
1301
|
+
if (this.has(entity)) {
|
|
1302
|
+
destroyEntity(this, entity);
|
|
1303
|
+
}
|
|
1304
|
+
});
|
|
1290
1305
|
ctx.entityIndex = createEntityIndex(this.#id);
|
|
1291
1306
|
ctx.entityTraits.clear();
|
|
1292
1307
|
ctx.entityMasks = [[]];
|
|
@@ -1311,8 +1326,8 @@ var World = class {
|
|
|
1311
1326
|
const ctx = this[$internal];
|
|
1312
1327
|
if (typeof args[0] === "string") {
|
|
1313
1328
|
const query = ctx.queriesHashMap.get(args[0]);
|
|
1314
|
-
if (!query) return [];
|
|
1315
|
-
return query.
|
|
1329
|
+
if (!query) return createQueryResult(new Query(this, []), this, []);
|
|
1330
|
+
return createQueryResult(query, this, query.parameters);
|
|
1316
1331
|
} else {
|
|
1317
1332
|
const params = args;
|
|
1318
1333
|
const hash = createQueryHash(params);
|
package/dist/react.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koota",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "🌎 Performant real-time state management for React and TypeScript",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"type": "module",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"react": ">=18.0.0",
|
|
36
36
|
"react-dom": ">=18.0.0",
|
|
37
37
|
"tsup": "^8.3.0",
|
|
38
|
-
"
|
|
38
|
+
"@koota/core": "0.0.1",
|
|
39
39
|
"@koota/react": "0.0.1",
|
|
40
|
-
"
|
|
40
|
+
"tsconfig": "0.1.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@types/react": ">=18.0.0",
|
package/react/index.cjs
CHANGED
|
@@ -135,6 +135,7 @@ function setChanged(world, entity, trait2) {
|
|
|
135
135
|
}
|
|
136
136
|
for (const query of data.queries) {
|
|
137
137
|
if (!query.hasChangedModifiers) continue;
|
|
138
|
+
if (!query.changedTraits.has(trait2)) continue;
|
|
138
139
|
let match = query.check(world, entity, { type: "change", traitData: data });
|
|
139
140
|
if (match) query.add(entity);
|
|
140
141
|
else query.remove(world, entity);
|
|
@@ -932,7 +933,12 @@ var Query = class {
|
|
|
932
933
|
run(world) {
|
|
933
934
|
this.commitRemovals(world);
|
|
934
935
|
const result = this.entities.dense.slice();
|
|
935
|
-
if (this.isTracking)
|
|
936
|
+
if (this.isTracking) {
|
|
937
|
+
this.entities.clear();
|
|
938
|
+
for (const eid of result) {
|
|
939
|
+
this.resetTrackingBitmasks(eid);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
936
942
|
return result;
|
|
937
943
|
}
|
|
938
944
|
add(entity) {
|
|
@@ -1055,7 +1061,12 @@ function shallowEqual(obj1, obj2) {
|
|
|
1055
1061
|
function createQueryResult(query, world, params) {
|
|
1056
1062
|
query.commitRemovals(world);
|
|
1057
1063
|
const entities = query.entities.dense.slice();
|
|
1058
|
-
if (query.isTracking)
|
|
1064
|
+
if (query.isTracking) {
|
|
1065
|
+
query.entities.clear();
|
|
1066
|
+
for (const eid of entities) {
|
|
1067
|
+
query.resetTrackingBitmasks(eid);
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1059
1070
|
const stores = [];
|
|
1060
1071
|
const traits = [];
|
|
1061
1072
|
getQueryStores(params, traits, stores, world);
|
|
@@ -1286,7 +1297,11 @@ var World = class {
|
|
|
1286
1297
|
}
|
|
1287
1298
|
reset() {
|
|
1288
1299
|
const ctx = this[$internal];
|
|
1289
|
-
this.entities.forEach((entity) =>
|
|
1300
|
+
this.entities.forEach((entity) => {
|
|
1301
|
+
if (this.has(entity)) {
|
|
1302
|
+
destroyEntity(this, entity);
|
|
1303
|
+
}
|
|
1304
|
+
});
|
|
1290
1305
|
ctx.entityIndex = createEntityIndex(this.#id);
|
|
1291
1306
|
ctx.entityTraits.clear();
|
|
1292
1307
|
ctx.entityMasks = [[]];
|
|
@@ -1311,8 +1326,8 @@ var World = class {
|
|
|
1311
1326
|
const ctx = this[$internal];
|
|
1312
1327
|
if (typeof args[0] === "string") {
|
|
1313
1328
|
const query = ctx.queriesHashMap.get(args[0]);
|
|
1314
|
-
if (!query) return [];
|
|
1315
|
-
return query.
|
|
1329
|
+
if (!query) return createQueryResult(new Query(this, []), this, []);
|
|
1330
|
+
return createQueryResult(query, this, query.parameters);
|
|
1316
1331
|
} else {
|
|
1317
1332
|
const params = args;
|
|
1318
1333
|
const hash = createQueryHash(params);
|