Skip to content

feat: new readme #286

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

Merged
merged 11 commits into from
Oct 4, 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
16 changes: 6 additions & 10 deletions examples/example-vite-react-sdk/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useEffect, useMemo } from "react";
import { SDK, createDojoStore } from "@dojoengine/sdk";
import { Schema } from "./bindings.ts";

import { useDojo } from "./useDojo.tsx";
import { getEntityIdFromKeys } from "@dojoengine/utils";
import { addAddressPadding } from "starknet";

import { Models, Schema } from "./bindings.ts";
import { useDojo } from "./useDojo.tsx";
import useModel from "./useModel.tsx";

export const useDojoStore = createDojoStore<Schema>();

function App({ db }: { db: SDK<Schema> }) {
Expand Down Expand Up @@ -109,13 +110,8 @@ function App({ db }: { db: SDK<Schema> }) {
fetchEntities();
}, [db, account?.account.address]);

const position = useMemo(() => {
return entities[entityId]?.models?.dojo_starter.Position;
}, [entities]);

const moves = useMemo(() => {
return entities[entityId]?.models?.dojo_starter.Moves;
}, [entities]);
const moves = useModel(entityId, Models.Moves);
const position = useModel(entityId, Models.Position);

return (
<div className="bg-black min-h-screen w-full p-4 sm:p-8">
Expand Down
8 changes: 7 additions & 1 deletion examples/example-vite-react-sdk/src/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ type Schema = {
};
};

enum Models {
Moves = "dojo_starter-Moves",
DirectionsAvailable = "dojo_starter-DirectionsAvailable",
Position = "dojo_starter-Position",
}

const schema: Schema = {
dojo_starter: {
Moves: {
Expand All @@ -62,4 +68,4 @@ const schema: Schema = {
};

export type { Schema, Moves, DirectionsAvailable, Position, Vec2 };
export { Direction, schema };
export { Direction, schema, Models };
12 changes: 6 additions & 6 deletions examples/example-vite-react-sdk/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { init } from "@dojoengine/sdk";
import { Schema, schema } from "./bindings.ts";
import { dojoConfig } from "../dojoConfig.ts";
import { DojoContextProvider } from "./DojoContext.tsx";
import { setupBurner } from "./setupBurner.tsx";
import { setupBurnerManager } from "@dojoengine/create-burner";

async function main() {
const db = await init<Schema>(
Expand All @@ -20,20 +20,20 @@ async function main() {
worldAddress: dojoConfig.manifest.world.address,
},
domain: {
name: "Example",
name: "WORLD_NAME",
version: "1.0",
chainId: "your-chain-id",
chainId: "KATANA",
revision: "1",
},
},
schema
);

const burnerManager = await setupBurner(dojoConfig);

createRoot(document.getElementById("root")!).render(
<StrictMode>
<DojoContextProvider burnerManager={burnerManager}>
<DojoContextProvider
burnerManager={await setupBurnerManager(dojoConfig)}
>
Comment on lines +34 to +36
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Refactor burner manager setup to improve code structure.

While the direct integration of setupBurnerManager into the component props simplifies the code, using await inside JSX is not recommended and may lead to unexpected behavior.

Consider refactoring this part to separate the asynchronous operation from the JSX:

 async function main() {
     // ... (previous code)
+    const burnerManager = await setupBurnerManager(dojoConfig);
 
     createRoot(document.getElementById("root")!).render(
         <StrictMode>
             <DojoContextProvider
-                burnerManager={await setupBurnerManager(dojoConfig)}
+                burnerManager={burnerManager}
             >
                 <App db={db} />
             </DojoContextProvider>
         </StrictMode>
     );
 }

This change will improve code readability and prevent potential issues with using await in JSX.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<DojoContextProvider
burnerManager={await setupBurnerManager(dojoConfig)}
>
async function main() {
// ... (previous code)
const burnerManager = await setupBurnerManager(dojoConfig);
createRoot(document.getElementById("root")!).render(
<StrictMode>
<DojoContextProvider
burnerManager={burnerManager}
>
<App db={db} />
</DojoContextProvider>
</StrictMode>
);
}

<App db={db} />
</DojoContextProvider>
</StrictMode>
Expand Down
28 changes: 28 additions & 0 deletions examples/example-vite-react-sdk/src/useModel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useDojoStore } from "./App";
import { Schema } from "./bindings";

/**
* Custom hook to retrieve a specific model for a given entityId within a specified namespace.
*
* @param entityId - The ID of the entity.
* @param model - The model to retrieve, specified as a string in the format "namespace-modelName".
* @returns The model structure if found, otherwise undefined.
*/
function useModel<N extends keyof Schema, M extends keyof Schema[N] & string>(
entityId: string,
model: `${N}-${M}`
): Schema[N][M] | undefined {
const [namespace, modelName] = model.split("-") as [N, M];

// Select only the specific model data for the given entityId
const modelData = useDojoStore(
(state) =>
state.entities[entityId]?.models?.[namespace]?.[modelName] as
| Schema[N][M]
| undefined
);

return modelData;
}

export default useModel;
8 changes: 8 additions & 0 deletions media/dojo-mark-full-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@
"docs": "npx typedoc --out docs",
"prepare": "husky install"
},
"dependencies": {
"@commitlint/cli": "^18.4.4",
"@commitlint/config-conventional": "^18.4.4",
"@ianvs/prettier-plugin-sort-imports": "^4.3.1",
"react": "^18.2.0"
},
"devDependencies": {
"husky": "^9.0.11",
"husky": "^9.1.6",
"lerna": "^8.1.5",
"prettier": "^3.3.3",
"tsup": "^8.1.0",
"typedoc": "^0.26.7",
"typedoc-material-theme": "^1.1.0",
"typedoc-plugin-coverage": "^3.3.0"
"typedoc-plugin-coverage": "^3.3.0",
"@commitlint/cli": "^18.4.4",
"@commitlint/config-conventional": "^18.4.4",
"@ianvs/prettier-plugin-sort-imports": "^4.3.1"
Comment on lines +14 to +23
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

React is still in use within the project

The react package remains imported and utilized across multiple files in the codebase, including JSX and TSX files. This indicates that React is still actively used despite its removal from package.json.

Please address the following:

  • If React removal was intentional:

    1. Remove all React-related code and components from the project.
    2. Ensure that no React dependencies remain in the codebase.
    3. Update documentation to reflect the removal of React.
  • If React removal was unintentional:

    1. Add react back to the appropriate section (dependencies or devDependencies) in package.json.
    2. Ensure all necessary React packages are correctly listed and versioned.
🔗 Analysis chain

Verify the removal of React dependency

The react package seems to have been removed entirely from both dependencies and devDependencies. This is a significant change that wasn't mentioned in the PR objectives.

Please confirm if this removal was intentional. If it was:

  1. Ensure that the project no longer uses React in any way.
  2. Update any documentation or README files to reflect this change.
  3. Remove any React-related code or components from the project.

If this removal was unintentional, please add React back to the appropriate section (dependencies or devDependencies) based on how it's used in the project.

To help verify the usage of React in the project, you can run the following script:

This script will help identify if React is still being used in the project, which can guide the decision on whether to keep or remove the React dependency.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for React usage in the project

# Search for React imports or usage in JavaScript and TypeScript files
echo "Searching for React usage:"
rg --type js --type ts 'import.*React|from.*react|React\.' -g '!node_modules'

# Check if there are any JSX files in the project
echo -e "\nChecking for JSX files:"
fd -e jsx -e tsx

Length of output: 28503

}
}
1 change: 1 addition & 0 deletions packages/create-burner/src/manager/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { BurnerManager } from "./burnerManager";
export { PredeployedManager } from "./predeployedManager";
export { prefundAccount } from "./prefundAccount";
export { setupBurnerManager } from "./setupBurnerManager";
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { DojoConfig } from "@dojoengine/core";
import { BurnerManager } from "@dojoengine/create-burner";
import { Account, RpcProvider } from "starknet";
import { BurnerManager } from "..";

export const setupBurner = async (config: DojoConfig) => {
export const setupBurnerManager = async (config: DojoConfig) => {
const burnerManager = new BurnerManager({
masterAccount: new Account(
{
Expand Down
1 change: 0 additions & 1 deletion packages/create-dojo/bin/index.d.ts

This file was deleted.

83 changes: 0 additions & 83 deletions packages/create-dojo/bin/index.js

This file was deleted.

Loading
Loading