From 0e66b7f284823504ec1800fe2ab23c617cd28907 Mon Sep 17 00:00:00 2001 From: ponderingdemocritus Date: Tue, 2 Jul 2024 15:57:10 +1000 Subject: [PATCH] fix: docs and example --- examples/dojo-starter | 2 +- examples/react/react-app/readme.md | 4 ++- examples/react/react-app/src/App.tsx | 2 -- examples/react/react-app/src/assets/react.svg | 1 - examples/react/react-phaser-example/readme.md | 6 ++--- packages/state/src/recs/index.ts | 26 +++++++++++++++++++ 6 files changed, 32 insertions(+), 9 deletions(-) delete mode 100644 examples/react/react-app/src/assets/react.svg diff --git a/examples/dojo-starter b/examples/dojo-starter index c0ebfc65..cb8edb3b 160000 --- a/examples/dojo-starter +++ b/examples/dojo-starter @@ -1 +1 @@ -Subproject commit c0ebfc65937a20dba32e886c842d04203e7fbdd9 +Subproject commit cb8edb3b0ebcc225c32316bf6a747791dd7b01e5 diff --git a/examples/react/react-app/readme.md b/examples/react/react-app/readme.md index b767338b..69d79b8f 100644 --- a/examples/react/react-app/readme.md +++ b/examples/react/react-app/readme.md @@ -1 +1,3 @@ -## React-app +## Dojo React Vite App + +[book](https://book.dojoengine.org/) diff --git a/examples/react/react-app/src/App.tsx b/examples/react/react-app/src/App.tsx index c8372f3a..58abd907 100644 --- a/examples/react/react-app/src/App.tsx +++ b/examples/react/react-app/src/App.tsx @@ -30,8 +30,6 @@ function App() { const moves = useComponentValue(Moves, entityId); const directions = useComponentValue(DirectionsAvailable, entityId); - console.log("directions", directions); - const handleRestoreBurners = async () => { try { await account?.applyFromClipboard(); diff --git a/examples/react/react-app/src/assets/react.svg b/examples/react/react-app/src/assets/react.svg deleted file mode 100644 index 6c87de9b..00000000 --- a/examples/react/react-app/src/assets/react.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/examples/react/react-phaser-example/readme.md b/examples/react/react-phaser-example/readme.md index b5f91de3..14efb414 100644 --- a/examples/react/react-phaser-example/readme.md +++ b/examples/react/react-phaser-example/readme.md @@ -1,5 +1,3 @@ -## Phaser +## Dojo Phaser React App -### Instructions - -When running `components` script to generate a component file, make sure to replace already given **World address** with the World Address you get after running `sozo migrate`. +[book](https://book.dojoengine.org/) diff --git a/packages/state/src/recs/index.ts b/packages/state/src/recs/index.ts index 91572834..73d2836c 100644 --- a/packages/state/src/recs/index.ts +++ b/packages/state/src/recs/index.ts @@ -9,6 +9,14 @@ import { import { Client } from "@dojoengine/torii-client"; import { convertValues } from "../utils"; +/** + * Fetches and synchronizes entities with their components. + * @param client - The client instance for API communication. + * @param components - An array of component definitions. + * @param entities - An array of entities to synchronize. + * @param limit - The maximum number of entities to fetch per request (default: 100). + * @returns A promise that resolves when synchronization is complete. + */ export const getSyncEntities = async ( client: Client, components: Component[], @@ -19,6 +27,12 @@ export const getSyncEntities = async ( return await syncEntities(client, components, entities); }; +/** + * Fetches all entities and their components from the client. + * @param client - The client instance for API communication. + * @param components - An array of component definitions. + * @param limit - The maximum number of entities to fetch per request (default: 100). + */ export const getEntities = async ( client: Client, components: Component[], @@ -40,6 +54,13 @@ export const getEntities = async ( } }; +/** + * Sets up a subscription to sync entity updates. + * @param client - The client instance for API communication. + * @param components - An array of component definitions. + * @param entities - An array of entities to watch for updates. + * @returns A promise that resolves with the subscription handler. + */ export const syncEntities = async ( client: Client, components: Component[], @@ -50,6 +71,11 @@ export const syncEntities = async ( }); }; +/** + * Updates the components of entities in the local state. + * @param entities - An array of entities with their updated component data. + * @param components - An array of component definitions. + */ export const setEntities = async ( entities: any[], components: Component[]