Skip to content

Commit

Permalink
fix: state recs convertValues do not add undefined when value is not …
Browse files Browse the repository at this point in the history
…present from schema
  • Loading branch information
MartianGreed committed Mar 3, 2025
1 parent e2ee851 commit 28398be
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .changeset/rude-doors-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"@dojoengine/state": patch
"template-vite-ts": patch
"@dojoengine/core": patch
"@dojoengine/create-burner": patch
"@dojoengine/create-dojo": patch
"@dojoengine/predeployed-connector": patch
"@dojoengine/react": patch
"@dojoengine/sdk": patch
"@dojoengine/torii-client": patch
"@dojoengine/torii-wasm": patch
"@dojoengine/utils": patch
"@dojoengine/utils-wasm": patch
---

fix: recs convertValues do not set to null
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export function defineContractComponents(world: World) {
},
{
metadata: {
name: "dojo_starter-Position",
namespace: "dojo_starter",
name: "Position",
types: ["contractaddress", "u32", "u32"],
customTypes: ["Vec2"],
},
Expand Down
13 changes: 13 additions & 0 deletions packages/state/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,17 @@ describe("convertValues", () => {
const expected = {};
expect(convertValues(schema, values)).toEqual(expected);
});
it("should not set value to undefined", () => {
const schema: Schema = {
name: RecsType.String,
age: RecsType.Number,
};
const values = {
name: { value: "Alice", type: "string" },
};
const expected = {
name: "Alice",
};
expect(convertValues(schema, values)).toStrictEqual(expected);
});
});
6 changes: 6 additions & 0 deletions packages/state/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export function convertValues(schema: Schema, values: any) {
let schemaType = schema[key];
let value = values[key];

// If key in values is not present, no need to set it to null
// so we return the accumulator as is
if (undefined === value) {
return acc;
}

if (value == null) {
acc[key] = value;
return acc;
Expand Down

0 comments on commit 28398be

Please sign in to comment.