Skip to content

Commit f2c37d9

Browse files
MartianGreedThierry
andauthored
chore(example): showcase type system across all frameworks (#520)
* chore(example): showcase type system across all frameworks - React: replace any/Record<string, unknown> with ABI-derived types, add ParsedEntity, Token, TokenBalance, Event imports, remove console.log - Vue: use ABI-derived Position/Moves types instead of ComponentValue<any> - Node: add typed Position/Moves annotations from @showcase/dojo - Add educational comments pointing to core/types.ts for the full pattern - Fix 'Infinite Scroll Entities' -> 'Infinite Scroll Tokens' copy-paste bug * fix(example): address CodeRabbit review feedback - Extract shared NUMSGame interface to core/nums-types.ts (no duplication) - Use React.JSX.Element for React 19 compatibility - Use non-null assertion after .filter() instead of optional chaining - Type Event consistently across EventList, EventSubscriber, and InfiniteScroll - Add optional chaining for vec access in Vue moveUp/moveLeft - Cast getComponentValue at boundary in Vue for consistency with Node - Remove Partial<> wrapper on Vue refs (full model or null) * refactor(example): switch React from NUMS/Sepolia to dojo-starter - Connect to local Torii (localhost:8080) with dojo-starter manifest - Query dojo_starter-Position and dojo_starter-Moves models - Use ABI-derived Position/Moves types from @showcase/dojo - Remove manifest_sepolia.json and nums-types.ts - All frameworks now consistently use the dojo-starter world * chore(example): replace recs with SDK pattern in vue and node * fix(example): use Pagination.getItems() instead of private .items --------- Co-authored-by: Thierry <thierry@openclaw.ai>
1 parent 81f04d8 commit f2c37d9

10 files changed

Lines changed: 250 additions & 4761 deletions

File tree

example/core/dojo/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type {
1818
DirectionVariant,
1919
SpawnAction,
2020
MoveAction,
21+
DojoStarterSchema,
2122
} from "../types";
2223
export { dojoConfig } from "./config";
2324
export type { ContractComponents } from "./generated/contractComponents";
Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
1-
import { getComponentValue } from "@dojoengine/recs";
2-
import { getEntityIdFromKeys } from "@dojoengine/utils";
1+
import { init, ToriiQueryBuilder, KeysClause } from "@dojoengine/sdk/node";
32

4-
import { DirectionValue, dojoConfig, setup } from "@showcase/dojo";
3+
import {
4+
DirectionValue,
5+
dojoConfig,
6+
setup,
7+
type Position,
8+
type Moves,
9+
type DojoStarterSchema,
10+
} from "@showcase/dojo";
511

6-
async function main() {
12+
async function main(): Promise<void> {
713
const result = await setup(dojoConfig);
814

15+
// Initialize SDK for querying entities (no recs)
16+
const sdk = await init<DojoStarterSchema>({
17+
client: {
18+
toriiUrl: dojoConfig.toriiUrl,
19+
worldAddress: dojoConfig.manifest.world.address || "",
20+
},
21+
domain: {
22+
name: "dojo_starter",
23+
version: "1.0.0",
24+
chainId: "SN_MAIN",
25+
revision: "1",
26+
},
27+
});
28+
929
if (result.burnerManager.list().length === 0) {
1030
await result.burnerManager.create();
1131
}
@@ -23,19 +43,30 @@ async function main() {
2343
await result.systemCalls.move(account, DirectionValue.Right());
2444
await result.systemCalls.move(account, DirectionValue.Up());
2545

26-
const entityId = getEntityIdFromKeys([BigInt(account.address)]);
46+
// Query entities via SDK instead of recs getComponentValue
47+
const entities = await sdk.getEntities({
48+
query: new ToriiQueryBuilder()
49+
.withClause(
50+
KeysClause(
51+
["dojo_starter-Position", "dojo_starter-Moves"],
52+
[account.address],
53+
"VariableLen"
54+
).build()
55+
)
56+
.includeHashedKeys(),
57+
});
2758

28-
const position = getComponentValue(
29-
result.clientComponents.Position,
30-
entityId
31-
);
32-
const moves = getComponentValue(result.clientComponents.Moves, entityId);
59+
const entity = entities.getItems()[0];
60+
const position = entity?.models?.dojo_starter?.Position as
61+
| Position
62+
| undefined;
63+
const moves = entity?.models?.dojo_starter?.Moves as Moves | undefined;
3364

3465
console.log("Position", position?.vec);
3566
console.log("Moves remaining", moves?.remaining);
3667
}
3768

38-
main().catch((error) => {
69+
main().catch((error: unknown) => {
3970
console.error(error);
4071
process.exitCode = 1;
4172
});

example/frameworks/react/src/effect/atoms/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { Atom } from "@effect-atom/atom-react";
22
import { Layer } from "effect";
33
import { makeToriiLayer } from "@dojoengine/react/effect";
44
import { TracingLive } from "../tracing";
5-
import manifest from "../../manifest_sepolia.json" with { type: "json" };
5+
import manifest from "../../../../../core/manifest_dev.json" with {
6+
type: "json",
7+
};
68

79
const toriiLayer = makeToriiLayer(
8-
{ manifest, toriiUrl: "https://api.cartridge.gg/x/nums-bal/torii" },
10+
{ manifest, toriiUrl: "http://localhost:8080" },
911
{ autoReconnect: false, maxReconnectAttempts: 5 }
1012
);
1113

0 commit comments

Comments
 (0)