Skip to content

Commit

Permalink
viz.js still not working
Browse files Browse the repository at this point in the history
  • Loading branch information
pfroud committed Jul 31, 2022
1 parent 39f9098 commit b711161
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "shell",
"group": "build",
// https://parceljs.org/features/cli/
"command": "npx parcel serve src/index.html src/operator/operator.html src/presentation/presentation.html",
"command": "npx parcel serve src/index.html src/operator/operator.html src/presentation/presentation.html --no-source-maps",
"presentation": {
"echo": false,
"reveal": "always",
Expand Down
8 changes: 5 additions & 3 deletions src/stateMachine/StateMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { generateDotFileForGraphviz } from "./generateDotFileForGraphviz";
import { GraphvizViewer } from "../graphvizViewer/graphvizViewer";

import Viz from "@aduh95/viz.js";
import getWorker from "@aduh95/viz.js/worker";

interface StateMap {
[stateName: string]: StateMachineState;
Expand Down Expand Up @@ -374,8 +373,11 @@ export class StateMachine {
const dotFileString = generateDotFileForGraphviz(this.allStates);


const worker = getWorker();
const viz = new Viz({ worker });
const viz = new Viz({
worker: new Worker(new URL("../worker.js", import.meta.url), {
type: "module",
}),
});

viz
.renderString("digraph{1 -> 2 }")
Expand Down
21 changes: 21 additions & 0 deletions src/worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//import initWASM from "@aduh95/viz.js/worker";
// If you are not using a bundler that supports package.json#exports
// use "./node_modules/@aduh95/viz.js/dist/render.browser.js" instead.
import initWASM from "../node_modules/@aduh95/viz.js/dist/render.browser.js";

// You need to configure your bundler to treat `.wasm` file as file to return a URL.
//import wasmURL from "@aduh95/viz.js/wasm";
// With Rollup, use the `@rollup/plugin-url` plugin and add `**/*.wasm` to the
// `include` list in the plugin config.
// With Webpack, use the `file-loader` plugin: "file-loader!@aduh95/viz.js/wasm"

// If you are not using a bundler that supports package.json#exports
// or doesn't have a file-loader plugin to get URL of the asset:
const wasmURL =
new URL("../node_modules/@aduh95/viz.js/dist/render.wasm", import.meta.url);

initWASM({
locateFile() {
return wasmURL;
},
});
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
//
// https://parceljs.org/languages/typescript/#isolatedmodules
// https://www.typescriptlang.org/tsconfig#isolatedModules
"isolatedModules": true
"isolatedModules": true,
"module": "es2022"
},
"exclude": [
"node_modules"
Expand Down

0 comments on commit b711161

Please sign in to comment.