Skip to content

Commit 7b58cd2

Browse files
feat: subscription
1 parent 1318341 commit 7b58cd2

File tree

14 files changed

+109
-49
lines changed

14 files changed

+109
-49
lines changed

examples/clients/react/react-sdk/src/App.tsx

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { useEffect, useState } from "react";
2-
import reactLogo from "./assets/react.svg";
3-
import viteLogo from "/vite.svg";
42
import "./App.css";
53
import { init } from "@dojoengine/sdk";
64

@@ -54,6 +52,41 @@ const db = await init<Schema>({
5452
});
5553

5654
function App() {
55+
useEffect(() => {
56+
let unsubscribe: (() => void) | undefined;
57+
58+
const subscribe = async () => {
59+
const subscription = await db.subscribeEntityQuery(
60+
{
61+
dojo_starter: {
62+
Moves: true,
63+
},
64+
},
65+
(response) => {
66+
if (response.error) {
67+
console.error(
68+
"Error setting up entity sync:",
69+
response.error
70+
);
71+
} else {
72+
console.log(response);
73+
}
74+
}
75+
);
76+
77+
unsubscribe = () => subscription.cancel();
78+
};
79+
80+
subscribe();
81+
82+
return () => {
83+
if (unsubscribe) {
84+
unsubscribe();
85+
console.log("Sync unsubscribed");
86+
}
87+
};
88+
}, []);
89+
5790
useEffect(() => {
5891
const fetchEntities = async () => {
5992
try {
@@ -62,7 +95,7 @@ function App() {
6295
dojo_starter: {
6396
Moves: {
6497
$: {
65-
where: { can_move: { $eq: true } },
98+
where: { last_direction: { $eq: "Left" } },
6699
},
67100
},
68101
},
@@ -76,11 +109,10 @@ function App() {
76109
return;
77110
}
78111
if (resp.data) {
79-
console.log("resp.data:", resp.data.dojo_starter);
80112
}
81113
}
82114
);
83-
console.log("Queried entities:", entities);
115+
// console.log("Queried entities:", entities);
84116
} catch (error) {
85117
console.error("Error querying entities:", error);
86118
}

packages/create-dojo/bin/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/create-dojo/bin/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sdk/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"type": "module",
99
"scripts": {
1010
"build": "tsup --dts-resolve",
11-
"test": "vitest run",
11+
"test": "vitest run --config ./vitest.config.ts",
1212
"coverage": "vitest run --coverage",
1313
"lint": "eslint . --ext .ts,.tsx"
1414
},
@@ -29,6 +29,7 @@
2929
},
3030
"dependencies": {
3131
"@dojoengine/torii-client": "workspace:*",
32+
"vite-plugin-wasm": "^3.3.0",
3233
"zustand": "^4.5.2"
3334
}
3435
}

packages/sdk/src/__tests__/convertQueryToClause.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ describe("convertQueryToClause", () => {
4343
model: "world-player",
4444
member: "id",
4545
operator: "Eq",
46-
value: { Primitive: { Felt252: "1" } },
46+
value: { String: "1" },
4747
},
4848
},
4949
{
5050
Member: {
5151
model: "world-player",
5252
member: "name",
5353
operator: "Eq",
54-
value: { Primitive: { Felt252: "Alice" } },
54+
value: { String: "Alice" },
5555
},
5656
},
5757
],
@@ -100,15 +100,15 @@ describe("convertQueryToClause", () => {
100100
model: "world-player",
101101
member: "id",
102102
operator: "Eq",
103-
value: { Primitive: { Felt252: "1" } },
103+
value: { String: "1" },
104104
},
105105
},
106106
{
107107
Member: {
108108
model: "world-game",
109109
member: "status",
110110
operator: "Eq",
111-
value: { Primitive: { Felt252: "active" } },
111+
value: { String: "active" },
112112
},
113113
},
114114
],

packages/sdk/src/__tests__/parseEntities.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ describe("parseEntities", () => {
165165
},
166166
};
167167

168-
const result = parseEntities(mockEntities, query);
168+
const result = parseEntities(mockEntities);
169169

170170
expect(result).toEqual([
171171
{

0 commit comments

Comments
 (0)