Skip to content

Commit 0041c4f

Browse files
authored
Merge pull request #410 from dojoengine/fix/state-recs-convertValues
fix: state recs convertValues do not add undefined when value is not …
2 parents e2ee851 + 28398be commit 0041c4f

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

.changeset/rude-doors-beg.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
"@dojoengine/state": patch
3+
"template-vite-ts": patch
4+
"@dojoengine/core": patch
5+
"@dojoengine/create-burner": patch
6+
"@dojoengine/create-dojo": patch
7+
"@dojoengine/predeployed-connector": patch
8+
"@dojoengine/react": patch
9+
"@dojoengine/sdk": patch
10+
"@dojoengine/torii-client": patch
11+
"@dojoengine/torii-wasm": patch
12+
"@dojoengine/utils": patch
13+
"@dojoengine/utils-wasm": patch
14+
---
15+
16+
fix: recs convertValues do not set to null

examples/example-vite-react-phaser-recs/src/dojo/generated/contractComponents.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ export function defineContractComponents(world: World) {
5454
},
5555
{
5656
metadata: {
57-
name: "dojo_starter-Position",
57+
namespace: "dojo_starter",
58+
name: "Position",
5859
types: ["contractaddress", "u32", "u32"],
5960
customTypes: ["Vec2"],
6061
},

packages/state/src/__tests__/utils.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,4 +348,17 @@ describe("convertValues", () => {
348348
const expected = {};
349349
expect(convertValues(schema, values)).toEqual(expected);
350350
});
351+
it("should not set value to undefined", () => {
352+
const schema: Schema = {
353+
name: RecsType.String,
354+
age: RecsType.Number,
355+
};
356+
const values = {
357+
name: { value: "Alice", type: "string" },
358+
};
359+
const expected = {
360+
name: "Alice",
361+
};
362+
expect(convertValues(schema, values)).toStrictEqual(expected);
363+
});
351364
});

packages/state/src/utils/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ export function convertValues(schema: Schema, values: any) {
55
let schemaType = schema[key];
66
let value = values[key];
77

8+
// If key in values is not present, no need to set it to null
9+
// so we return the accumulator as is
10+
if (undefined === value) {
11+
return acc;
12+
}
13+
814
if (value == null) {
915
acc[key] = value;
1016
return acc;

0 commit comments

Comments
 (0)