Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: docs and example #231

Merged
merged 4 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/dojo-starter
4 changes: 3 additions & 1 deletion examples/react/react-app/readme.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
## React-app
## Dojo React Vite App

[book](https://book.dojoengine.org/)
2 changes: 0 additions & 2 deletions examples/react/react-app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion examples/react/react-app/src/assets/react.svg

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/* Autogenerated file. Do not edit manually. */
/*
* Autogenerated file. Do not edit manually.
* Generated using @dojoengine/core
* Command: npx @dojoengine/core <MANIFEST_LOCATION> <OUTPUT_PATH> <RPC_URL> <WORLD_ADDRESS>
*/

import { defineComponent, Type as RecsType, World } from "@dojoengine/recs";

Expand Down
2 changes: 0 additions & 2 deletions examples/react/react-app/src/dojo/generated/generated.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { Account, AccountInterface } from "starknet";
import { DojoProvider } from "@dojoengine/core";
import { Direction } from "../../utils";
Expand Down
2 changes: 0 additions & 2 deletions examples/react/react-app/src/dojo/generated/world.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { createWorld } from "@dojoengine/recs";

export const world = createWorld();
6 changes: 2 additions & 4 deletions examples/react/react-phaser-example/readme.md
Original file line number Diff line number Diff line change
@@ -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/)
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/* Autogenerated file. Do not edit manually. */
/*
* Autogenerated file. Do not edit manually.
* Generated using @dojoengine/core
* Command: npx @dojoengine/core <MANIFEST_LOCATION> <OUTPUT_PATH> <RPC_URL> <WORLD_ADDRESS>
*/

import { defineComponent, Type as RecsType, World } from "@dojoengine/recs";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { Account, AccountInterface } from "starknet";
import { DojoProvider } from "@dojoengine/core";
import { Direction } from "../utils";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { createWorld } from "@dojoengine/recs";

export const world = createWorld();
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/* Autogenerated file. Do not edit manually. */
/*
* Autogenerated file. Do not edit manually.
* Generated using @dojoengine/core
* Command: npx @dojoengine/core <MANIFEST_LOCATION> <OUTPUT_PATH> <RPC_URL> <WORLD_ADDRESS>
*/

import { defineComponent, Type as RecsType, World } from "@dojoengine/recs";

Expand Down
2 changes: 0 additions & 2 deletions examples/react/react-pwa-app/src/dojo/generated/generated.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { Account, AccountInterface } from "starknet";
import { DojoProvider } from "@dojoengine/core";
import { Direction } from "../../utils";
Expand Down
2 changes: 0 additions & 2 deletions examples/react/react-pwa-app/src/dojo/generated/world.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { createWorld } from "@dojoengine/recs";

export const world = createWorld();
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/* Autogenerated file. Do not edit manually. */
/*
* Autogenerated file. Do not edit manually.
* Generated using @dojoengine/core
* Command: npx @dojoengine/core <MANIFEST_LOCATION> <OUTPUT_PATH> <RPC_URL> <WORLD_ADDRESS>
*/

import { defineComponent, Type as RecsType, World } from "@dojoengine/recs";

Expand Down
2 changes: 0 additions & 2 deletions examples/react/react-threejs/src/dojo/generated/generated.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { Account, AccountInterface } from "starknet";
import { DojoProvider } from "@dojoengine/core";
import { Direction } from "../../utils";
Expand Down
2 changes: 0 additions & 2 deletions examples/react/react-threejs/src/dojo/generated/world.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { createWorld } from "@dojoengine/recs";

export const world = createWorld();
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/* Autogenerated file. Do not edit manually. */
/*
* Autogenerated file. Do not edit manually.
* Generated using @dojoengine/core
* Command: npx @dojoengine/core <MANIFEST_LOCATION> <OUTPUT_PATH> <RPC_URL> <WORLD_ADDRESS>
*/

import { defineComponent, Type as RecsType, World } from "@dojoengine/recs";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { Account, AccountInterface } from "starknet";
import { DojoProvider } from "@dojoengine/core";
import { Direction } from "../../utils";
Expand Down
2 changes: 0 additions & 2 deletions examples/react/starknet-react-app/src/dojo/generated/world.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { createWorld } from "@dojoengine/recs";

export const world = createWorld();
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/* Autogenerated file. Do not edit manually. */
/*
* Autogenerated file. Do not edit manually.
* Generated using @dojoengine/core
* Command: npx @dojoengine/core <MANIFEST_LOCATION> <OUTPUT_PATH> <RPC_URL> <WORLD_ADDRESS>
*/

import { defineComponent, Type as RecsType, World } from "@dojoengine/recs";

Expand Down
2 changes: 0 additions & 2 deletions examples/vue/vue-app/src/dojo/generated/generated.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { Account, AccountInterface } from "starknet";
import { DojoProvider } from "@dojoengine/core";
import { Direction } from "../../utils";
Expand Down
2 changes: 0 additions & 2 deletions examples/vue/vue-app/src/dojo/generated/world.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { createWorld } from "@dojoengine/recs";

export const world = createWorld();
26 changes: 26 additions & 0 deletions packages/state/src/recs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Comment on lines +15 to +19
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using any type for entities.

Using any type reduces type safety. Consider defining a specific type or interface for entities.

entities: Entity[],

export const getSyncEntities = async <S extends Schema>(
client: Client,
components: Component<S, Metadata, undefined>[],
Expand All @@ -19,6 +27,12 @@ export const getSyncEntities = async <S extends Schema>(
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).
*/
Comment on lines +33 to +35
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using any type for entities.

Using any type reduces type safety. Consider defining a specific type or interface for entities.

entities: Entity[],

export const getEntities = async <S extends Schema>(
client: Client,
components: Component<S, Metadata, undefined>[],
Expand All @@ -40,6 +54,13 @@ export const getEntities = async <S extends Schema>(
}
};

/**
* 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.
*/
Comment on lines +61 to +63
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using any type for entities.

Using any type reduces type safety. Consider defining a specific type or interface for entities.

entities: Entity[],

export const syncEntities = async <S extends Schema>(
client: Client,
components: Component<S, Metadata, undefined>[],
Expand All @@ -50,6 +71,11 @@ export const syncEntities = async <S extends Schema>(
});
};

/**
* 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.
*/
Comment on lines +77 to +78
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using any type for entities.

Using any type reduces type safety. Consider defining a specific type or interface for entities.

entities: Entity[],

export const setEntities = async <S extends Schema>(
entities: any[],
components: Component<S, Metadata, undefined>[]
Expand Down
2 changes: 1 addition & 1 deletion packages/torii-wasm/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
set -ex

# # Clone the repository
git clone https://github.com/dojoengine/dojo.c dojo.c
git clone --depth 1 --branch v0.7.0 https://github.com/dojoengine/dojo.c dojo.c
cd dojo.c

set -ex
Expand Down
29 changes: 17 additions & 12 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Dojo.js is the official JavaScript SDK for interacting with Dojo worlds. It is c

Bootstrap a dojo world like so. You will need [dojo](https://github.com/dojoengine/dojo) installed.

```console
```bash
npx @dojoengine/create-dojo
```

Expand All @@ -34,7 +34,7 @@ npx @dojoengine/create-dojo

From the repository root, run the following to install all the necessary package dependencies:

```console
```bash
pnpm i
```

Expand All @@ -44,21 +44,21 @@ pnpm i

To build all packages, from the root directory, run:

```console
```bash
pnpm run build
```

To watch for changes on all packages in parallel, from the root directory, run:

```console
```bash
pnpm run build-watch
```

#### Dojo starter:

To install dojo-starter submodule (which allows interactions with the examples), run:

```console
```bash
git submodule update --init --recursive
```

Expand All @@ -68,7 +68,7 @@ git submodule update --init --recursive

If you have issues on WSL, install package first then run command:

```console
```bash
npm i @dojoengine/create-dojo -g
npx @dojoengine/create-dojo
```
Expand All @@ -79,22 +79,27 @@ To run the examples that have the linked packages, follow the steps below:

**Terminal 1**: Set up the dojo starter with specific configurations.

```console
```bash
cd examples/dojo-starter
katana --disable-fee --block-time 1000
katana --disable-fee --allowed-origins "*"
Comment on lines +82 to +84
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

Ensure the --allowed-origins flag is documented

The --allowed-origins flag is used in the readme.md file but lacks an explanation of its purpose and implications. Please add documentation or comments to clarify its usage.

  • readme.md: Lines containing --allowed-origins
Analysis chain

LGTM! But verify the usage of --allowed-origins flag.

The command to set up the dojo starter with specific configurations looks good.

However, ensure that users understand the purpose and implications of the --allowed-origins flag.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `--allowed-origins` flag.

# Test: Search for the flag usage in the codebase. Expect: Documentation or comments explaining its purpose.
rg --type markdown --type js --type ts $'--allowed-origins'

Length of output: 478



Script:

#!/bin/bash
# Description: Verify the usage of `--allowed-origins` flag.

# Test: Search for the flag usage in the codebase. Expect: Documentation or comments explaining its purpose.
rg --type markdown --type js --type ts '--allowed-origins'

Length of output: 478



Script:

#!/bin/bash
# Description: Verify the usage of `--allowed-origins` flag.

# Test: Search for the flag usage in the codebase. Expect: Documentation or comments explaining its purpose.
rg --type markdown --type js --type ts '\-\-allowed-origins'

Length of output: 226

```

**Terminal 2**: Build and migrate the dojo starter.

```console
```bash
cd examples/dojo-starter

# Build and migrate
sozo build
sozo migrate
sozo migrate apply

# Run Torii
torii --world 0xb4079627ebab1cd3cf9fd075dda1ad2454a7a448bf659591f259efa2519b18 --allowed-origins "*"
```

**Terminal 3**: Start the React app.
**Terminal 3**: Start the App

```console
```bash
cd examples/<package>
pnpm install
pnpm run dev
Expand Down
Loading