Skip to content

Commit

Permalink
checkpoint-kai-1700821404
Browse files Browse the repository at this point in the history
  • Loading branch information
coilysiren committed Nov 24, 2023
1 parent 18bb6a3 commit dfc228d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
wasm-pack.log
target/
dist/
pkg/
node_modules/
5 changes: 0 additions & 5 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import React from "react";
import * as ReactDOM from "react-dom/client";
import * as application from "./lib/application";

// A dependency graph that contains any wasm must all be imported asynchronously.
const galaxy = import("./lib/galaxy").catch((e) =>
console.error("Error importing `main`:", e)
);

ReactDOM.createRoot(document.getElementById("root")).render(
<application.Interface />
);
31 changes: 11 additions & 20 deletions src/js/lib/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,16 @@ import "./styles.css"
import * as dataviz from "./dataviz";
import * as galaxy from "./galaxy";

const wasm = import("galaxy_gen_backend/galaxy_gen_backend_bg.wasm");

export function Interface() {
const [galaxySize, setGalaxySize] = React.useState(100);
const [wasmModule, setWasmModule] = React.useState(null);
let galaxyFrontend: galaxy.Frontend = null;

// Fetch and instantiate the Wasm module
React.useEffect(() => {
const initWasm = async () => {
try {
const wasmModule = await import("galaxy_gen_backend");
const wasmGalaxy = new wasmModule.Galaxy(galaxySize, 0);
setWasmModule(module);
} catch (err) {
console.error('Error loading Wasm module:', err);
}
};
initWasm();
}, []);
wasm.then((module) => {
setWasmModule(module);
});

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setGalaxySize(parseInt(event.target.value));
Expand All @@ -37,15 +29,14 @@ export function Interface() {
)

const handleSeedClick = () => {
if (wasmModule !== null) {
} else {
if (wasmModule === null) {
console.error("wasm not yet loaded");
} else {
galaxyFrontend = new galaxy.Frontend(wasmModule, galaxySize);
galaxyFrontend.seed();
// galaxyFrontend = new galaxy.Frontend(galaxySize);
// dataviz.DataViz(galaxyFrontend);
}
// galaxyFrontend = new galaxy.Frontend(galaxySize);
// galaxyFrontend.seed();
galaxyFrontend = new galaxy.Frontend(wasmModule, galaxySize);
galaxyFrontend.seed();
// dataviz.DataViz(galaxyFrontend);
};

const seedButton = (
Expand Down

0 comments on commit dfc228d

Please sign in to comment.