@dcl/ecs 7.27.1-34480514651.commit-2778e4b → 7.27.1-34485770520.commit-5ec1a8a
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/dist/engine/lww-element-set-component-definition.js +20 -14
- package/dist/engine/readonly.d.ts +1 -1
- package/dist/engine/readonly.js +10 -0
- package/dist-cjs/engine/lww-element-set-component-definition.js +20 -14
- package/dist-cjs/engine/readonly.d.ts +1 -1
- package/dist-cjs/engine/readonly.js +10 -0
- package/package.json +2 -2
|
@@ -201,12 +201,16 @@ export function createComponentDefinitionFromSchema(componentName, componentId,
|
|
|
201
201
|
return data.has(entity);
|
|
202
202
|
},
|
|
203
203
|
deleteFrom(entity, markAsDirty = true) {
|
|
204
|
+
// Presence, not truthiness: a component defined from a primitive schema can
|
|
205
|
+
// legitimately hold 0, false or an empty string, and deleting one must still
|
|
206
|
+
// return the value that was there.
|
|
207
|
+
const had = data.has(entity);
|
|
204
208
|
const component = data.get(entity);
|
|
205
209
|
if (data.delete(entity) && markAsDirty) {
|
|
206
210
|
dirtyIterator.add(entity);
|
|
207
211
|
}
|
|
208
212
|
lastSentData.delete(entity);
|
|
209
|
-
return component
|
|
213
|
+
return had ? component : null;
|
|
210
214
|
},
|
|
211
215
|
entityDeleted(entity, markAsDirty) {
|
|
212
216
|
if (data.delete(entity) && markAsDirty) {
|
|
@@ -215,19 +219,20 @@ export function createComponentDefinitionFromSchema(componentName, componentId,
|
|
|
215
219
|
lastSentData.delete(entity);
|
|
216
220
|
},
|
|
217
221
|
getOrNull(entity) {
|
|
218
|
-
|
|
219
|
-
|
|
222
|
+
// Presence, not truthiness: a component defined from a primitive schema
|
|
223
|
+
// can legitimately hold 0, false or an empty string.
|
|
224
|
+
if (!data.has(entity))
|
|
225
|
+
return null;
|
|
226
|
+
return deepReadonly(data.get(entity));
|
|
220
227
|
},
|
|
221
228
|
get(entity) {
|
|
222
|
-
|
|
223
|
-
if (!component) {
|
|
229
|
+
if (!data.has(entity)) {
|
|
224
230
|
throw new Error(`[getFrom] Component ${componentName} for entity #${entity} not found`);
|
|
225
231
|
}
|
|
226
|
-
return deepReadonly(
|
|
232
|
+
return deepReadonly(data.get(entity));
|
|
227
233
|
},
|
|
228
234
|
create(entity, value) {
|
|
229
|
-
|
|
230
|
-
if (component) {
|
|
235
|
+
if (data.has(entity)) {
|
|
231
236
|
throw new Error(`[create] Component ${componentName} for ${entity} already exists`);
|
|
232
237
|
}
|
|
233
238
|
const usedValue = value === undefined ? schema.create() : schema.extend ? schema.extend(value) : value;
|
|
@@ -243,21 +248,22 @@ export function createComponentDefinitionFromSchema(componentName, componentId,
|
|
|
243
248
|
return usedValue;
|
|
244
249
|
},
|
|
245
250
|
getMutableOrNull(entity) {
|
|
246
|
-
|
|
247
|
-
if (!
|
|
251
|
+
// Presence, not truthiness, so a falsy primitive value is still mutable.
|
|
252
|
+
if (!data.has(entity)) {
|
|
248
253
|
return null;
|
|
249
254
|
}
|
|
250
255
|
dirtyIterator.add(entity);
|
|
251
|
-
return
|
|
256
|
+
return data.get(entity);
|
|
252
257
|
},
|
|
253
258
|
getOrCreateMutable(entity, value) {
|
|
254
|
-
|
|
255
|
-
|
|
259
|
+
// Presence, not truthiness: a stored 0/false/'' must not be treated as absent,
|
|
260
|
+
// which would send this through create() and throw "already exists".
|
|
261
|
+
if (!data.has(entity)) {
|
|
256
262
|
return this.create(entity, value);
|
|
257
263
|
}
|
|
258
264
|
else {
|
|
259
265
|
dirtyIterator.add(entity);
|
|
260
|
-
return
|
|
266
|
+
return data.get(entity);
|
|
261
267
|
}
|
|
262
268
|
},
|
|
263
269
|
getMutable(entity) {
|
package/dist/engine/readonly.js
CHANGED
|
@@ -2,5 +2,15 @@
|
|
|
2
2
|
* @internal
|
|
3
3
|
*/
|
|
4
4
|
export function deepReadonly(val) {
|
|
5
|
+
// A component can be defined straight from a primitive or array schema, not
|
|
6
|
+
// only from a Map, which is why this is no longer constrained to an object.
|
|
7
|
+
// Spreading those threw the value away: a number came back as {}, an array
|
|
8
|
+
// as an object keyed by index.
|
|
9
|
+
if (val === null || typeof val !== 'object') {
|
|
10
|
+
return val;
|
|
11
|
+
}
|
|
12
|
+
if (Array.isArray(val)) {
|
|
13
|
+
return Object.freeze([...val]);
|
|
14
|
+
}
|
|
5
15
|
return Object.freeze({ ...val });
|
|
6
16
|
}
|
|
@@ -208,12 +208,16 @@ function createComponentDefinitionFromSchema(componentName, componentId, schema)
|
|
|
208
208
|
return data.has(entity);
|
|
209
209
|
},
|
|
210
210
|
deleteFrom(entity, markAsDirty = true) {
|
|
211
|
+
// Presence, not truthiness: a component defined from a primitive schema can
|
|
212
|
+
// legitimately hold 0, false or an empty string, and deleting one must still
|
|
213
|
+
// return the value that was there.
|
|
214
|
+
const had = data.has(entity);
|
|
211
215
|
const component = data.get(entity);
|
|
212
216
|
if (data.delete(entity) && markAsDirty) {
|
|
213
217
|
dirtyIterator.add(entity);
|
|
214
218
|
}
|
|
215
219
|
lastSentData.delete(entity);
|
|
216
|
-
return component
|
|
220
|
+
return had ? component : null;
|
|
217
221
|
},
|
|
218
222
|
entityDeleted(entity, markAsDirty) {
|
|
219
223
|
if (data.delete(entity) && markAsDirty) {
|
|
@@ -222,19 +226,20 @@ function createComponentDefinitionFromSchema(componentName, componentId, schema)
|
|
|
222
226
|
lastSentData.delete(entity);
|
|
223
227
|
},
|
|
224
228
|
getOrNull(entity) {
|
|
225
|
-
|
|
226
|
-
|
|
229
|
+
// Presence, not truthiness: a component defined from a primitive schema
|
|
230
|
+
// can legitimately hold 0, false or an empty string.
|
|
231
|
+
if (!data.has(entity))
|
|
232
|
+
return null;
|
|
233
|
+
return (0, readonly_1.deepReadonly)(data.get(entity));
|
|
227
234
|
},
|
|
228
235
|
get(entity) {
|
|
229
|
-
|
|
230
|
-
if (!component) {
|
|
236
|
+
if (!data.has(entity)) {
|
|
231
237
|
throw new Error(`[getFrom] Component ${componentName} for entity #${entity} not found`);
|
|
232
238
|
}
|
|
233
|
-
return (0, readonly_1.deepReadonly)(
|
|
239
|
+
return (0, readonly_1.deepReadonly)(data.get(entity));
|
|
234
240
|
},
|
|
235
241
|
create(entity, value) {
|
|
236
|
-
|
|
237
|
-
if (component) {
|
|
242
|
+
if (data.has(entity)) {
|
|
238
243
|
throw new Error(`[create] Component ${componentName} for ${entity} already exists`);
|
|
239
244
|
}
|
|
240
245
|
const usedValue = value === undefined ? schema.create() : schema.extend ? schema.extend(value) : value;
|
|
@@ -250,21 +255,22 @@ function createComponentDefinitionFromSchema(componentName, componentId, schema)
|
|
|
250
255
|
return usedValue;
|
|
251
256
|
},
|
|
252
257
|
getMutableOrNull(entity) {
|
|
253
|
-
|
|
254
|
-
if (!
|
|
258
|
+
// Presence, not truthiness, so a falsy primitive value is still mutable.
|
|
259
|
+
if (!data.has(entity)) {
|
|
255
260
|
return null;
|
|
256
261
|
}
|
|
257
262
|
dirtyIterator.add(entity);
|
|
258
|
-
return
|
|
263
|
+
return data.get(entity);
|
|
259
264
|
},
|
|
260
265
|
getOrCreateMutable(entity, value) {
|
|
261
|
-
|
|
262
|
-
|
|
266
|
+
// Presence, not truthiness: a stored 0/false/'' must not be treated as absent,
|
|
267
|
+
// which would send this through create() and throw "already exists".
|
|
268
|
+
if (!data.has(entity)) {
|
|
263
269
|
return this.create(entity, value);
|
|
264
270
|
}
|
|
265
271
|
else {
|
|
266
272
|
dirtyIterator.add(entity);
|
|
267
|
-
return
|
|
273
|
+
return data.get(entity);
|
|
268
274
|
}
|
|
269
275
|
},
|
|
270
276
|
getMutable(entity) {
|
|
@@ -5,6 +5,16 @@ exports.deepReadonly = void 0;
|
|
|
5
5
|
* @internal
|
|
6
6
|
*/
|
|
7
7
|
function deepReadonly(val) {
|
|
8
|
+
// A component can be defined straight from a primitive or array schema, not
|
|
9
|
+
// only from a Map, which is why this is no longer constrained to an object.
|
|
10
|
+
// Spreading those threw the value away: a number came back as {}, an array
|
|
11
|
+
// as an object keyed by index.
|
|
12
|
+
if (val === null || typeof val !== 'object') {
|
|
13
|
+
return val;
|
|
14
|
+
}
|
|
15
|
+
if (Array.isArray(val)) {
|
|
16
|
+
return Object.freeze([...val]);
|
|
17
|
+
}
|
|
8
18
|
return Object.freeze({ ...val });
|
|
9
19
|
}
|
|
10
20
|
exports.deepReadonly = deepReadonly;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcl/ecs",
|
|
3
3
|
"description": "Decentraland ECS",
|
|
4
|
-
"version": "7.27.1-
|
|
4
|
+
"version": "7.27.1-34485770520.commit-5ec1a8a",
|
|
5
5
|
"author": "DCL",
|
|
6
6
|
"bugs": "https://github.com/decentraland/ecs/issues",
|
|
7
7
|
"files": [
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"dependencies": {},
|
|
35
35
|
"types": "./dist/index.d.ts",
|
|
36
36
|
"typings": "./dist/index.d.ts",
|
|
37
|
-
"commit": "
|
|
37
|
+
"commit": "5ec1a8a1536e07acf2fb58bc8ddbac856c200794"
|
|
38
38
|
}
|