Skip to content

Commit d9db01b

Browse files
Rename
1 parent 98e91f7 commit d9db01b

8 files changed

Lines changed: 1690 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>React ECS example</title>
7+
</head>
8+
<body>
9+
<div id="root"></div>
10+
<script type="module" src="/src/main.tsx"></script>
11+
</body>
12+
</html>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "ecs-react-example",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"scripts": {
7+
"start": "vite",
8+
"build": "tsc && vite build"
9+
},
10+
"dependencies": {
11+
"ecs-react": "^1.1.1",
12+
"react": "^19.1.1",
13+
"react-dom": "^19.1.1"
14+
},
15+
"devDependencies": {
16+
"@types/react": "^19.1.11",
17+
"@types/react-dom": "^19.1.9",
18+
"@typescript-eslint/eslint-plugin": "^8.40.0",
19+
"@typescript-eslint/parser": "^8.40.0",
20+
"@vitejs/plugin-react": "^5.0.1",
21+
"eslint": "^9.34.0",
22+
"eslint-plugin-react-hooks": "^5.0.0",
23+
"eslint-plugin-react-refresh": "^0.4.5",
24+
"typescript": "^5.9.2",
25+
"vite": "^7.1.3"
26+
}
27+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import * as React from "react";
2+
import {
3+
ECS,
4+
useComponent,
5+
type ComponentSchema,
6+
type SignalSchema,
7+
type WithEntityProps,
8+
} from "ecs-react";
9+
10+
type MyComponents = ComponentSchema<{
11+
counter: { count: number };
12+
label: string;
13+
}>;
14+
15+
type MySignals = SignalSchema<"click" | "hover">;
16+
17+
const ecs = new ECS<MyComponents, MySignals>();
18+
19+
const counterEntity = ecs.createEntity();
20+
21+
counterEntity.addComponent("counter", { count: 0 });
22+
23+
ecs.createSystem({
24+
name: "counterSystem",
25+
signals: ["click"],
26+
fn: ({ entity }) => {
27+
entity.updateComponent("counter", prevValue => ({
28+
count: prevValue.count + 1,
29+
}));
30+
},
31+
});
32+
33+
const Button: React.FC<WithEntityProps<MyComponents>> = ({ entity }) => {
34+
return <button onClick={() => ecs.signal("click", entity)}>Click</button>;
35+
};
36+
37+
const Display: React.FC<WithEntityProps<MyComponents>> = ({ entity }) => {
38+
const counter = useComponent(entity, "counter");
39+
40+
return <span>{counter?.count}</span>;
41+
};
42+
43+
export const App: React.FC = () => {
44+
return (
45+
<div style={{ display: "flex", gap: "10px" }}>
46+
<Button entity={counterEntity} />
47+
<Display entity={counterEntity} />
48+
</div>
49+
);
50+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import ReactDOM from "react-dom/client";
2+
import { App } from "./App";
3+
4+
const root = document.getElementById("root");
5+
6+
if (root) {
7+
ReactDOM.createRoot(root).render(<App />);
8+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2020",
4+
"useDefineForClassFields": true,
5+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
6+
"module": "ESNext",
7+
"skipLibCheck": true,
8+
9+
/* Bundler mode */
10+
"moduleResolution": "bundler",
11+
"allowImportingTsExtensions": true,
12+
"resolveJsonModule": true,
13+
"isolatedModules": true,
14+
"noEmit": true,
15+
"jsx": "react-jsx",
16+
17+
/* Linting */
18+
"strict": true,
19+
"noUnusedLocals": true,
20+
"noUnusedParameters": true,
21+
"noFallthroughCasesInSwitch": true
22+
},
23+
"include": ["src"],
24+
"references": [{ "path": "./tsconfig.node.json" }]
25+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"composite": true,
4+
"skipLibCheck": true,
5+
"module": "ESNext",
6+
"moduleResolution": "bundler",
7+
"allowSyntheticDefaultImports": true
8+
},
9+
"include": ["vite.config.ts"]
10+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { defineConfig } from "vite";
2+
import react from "@vitejs/plugin-react";
3+
4+
export default defineConfig({
5+
plugins: [react()],
6+
});

0 commit comments

Comments
 (0)