fix: move initial wasm into app

pull/2886/head
Steven 1 year ago
parent 79227021f5
commit 554f93eccc

@ -18,12 +18,6 @@
} }
</script> </script>
<script src="wasm_exec.js"></script> <script src="wasm_exec.js"></script>
<script>
const go = new Go();
WebAssembly.instantiateStreaming(fetch("gomark.wasm"), go.importObject).then((result) => {
go.run(result.instance);
});
</script>
</head> </head>
<body> <body>
<div id="root"></div> <div id="root"></div>

@ -26,16 +26,20 @@ const App = () => {
}, [systemStatus.host]); }, [systemStatus.host]);
useEffect(() => { useEffect(() => {
const initialGoWASMExec = async () => {
const go = new window.Go();
const result = await WebAssembly.instantiateStreaming(fetch("/gomark.wasm"), go.importObject);
go.run(result.instance);
};
const initialState = async () => { const initialState = async () => {
try { try {
await userStore.fetchCurrentUser(); await userStore.fetchCurrentUser();
} catch (error) { } catch (error) {
// Do nothing. // Do nothing.
} }
setLoading(false);
}; };
initialState(); Promise.all([initialGoWASMExec(), initialState()]).then(() => setLoading(false));
}, []); }, []);
useEffect(() => { useEffect(() => {

@ -1,7 +1,18 @@
import { Node } from "./node"; import { Node } from "./node";
declare class Go {
argv: string[];
env: { [envKey: string]: string };
exit: (code: number) => void;
importObject: WebAssembly.Imports;
exited: boolean;
mem: DataView;
run(instance: WebAssembly.Instance): Promise<void>;
}
declare global { declare global {
interface Window { interface Window {
Go: typeof Go;
parse: (content: string) => Node[]; parse: (content: string) => Node[];
restore: (input: Node[]) => string; restore: (input: Node[]) => string;
} }

Loading…
Cancel
Save