Skip to content

Commit

Permalink
eval webworker working, main RunFrame api implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Dec 13, 2024
1 parent 504a580 commit 28f8a8b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
Binary file modified bun.lockb
Binary file not shown.
7 changes: 6 additions & 1 deletion examples/runframe1-basic.fixture.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { RunFrame } from "lib/components/RunFrame"
import React from "react"

export default () => (
<RunFrame
fsMap={{
"main.tsx": `
circuit.add(
<resistor resistance="1k" />
<board width="10mm" height="10mm">
<resistor name="R1" resistance="1k" footprint="0402" />
<capacitor name="C1" capacitance="1uF" footprint="0603" pcbX={4} />
<trace from=".R1 .pin1" to=".C1 .pin1" />
</board>
)
`,
}}
Expand Down
17 changes: 15 additions & 2 deletions lib/components/RunFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { createCircuitWebWorker } from "@tscircuit/eval-webworker"
import { CircuitJsonPreview } from "./CircuitJsonPreview"
import { useEffect, useState } from "react"

// @ts-ignore
import evalWebWorkerBlobUrl from "@tscircuit/eval-webworker/blob-url"

interface Props {
/**
* Map of filenames to file contents that will be available in the worker
Expand Down Expand Up @@ -39,17 +42,27 @@ export const RunFrame = (props: Props) => {

useEffect(() => {
async function runWorker() {
const worker = await createCircuitWebWorker({})
const worker = await createCircuitWebWorker({
webWorkerUrl: evalWebWorkerBlobUrl,
verbose: true,
})
const $finished = worker.executeWithFsMap({
entrypoint: props.entrypoint,
fsMap: props.fsMap,
})
setCircuitJson(await worker.getCircuitJson())
console.log("waiting for execution to finish...")
await $finished
console.log("waiting for initial circuit json...")
setCircuitJson(await worker.getCircuitJson())
console.log("got initial circuit json")
await $finished.catch((e) => {
console.error(e)
})
setCircuitJson(await worker.getCircuitJson())
}
runWorker()
}, [props.fsMap])

console.log({ circuitJson })
return <CircuitJsonPreview circuitJson={circuitJson} />
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"@radix-ui/react-icons": "^1.3.2",
"@radix-ui/react-tabs": "^1.1.1",
"@tscircuit/3d-viewer": "^0.0.46",
"@tscircuit/eval-webworker": "^0.0.8",
"@tscircuit/pcb-viewer": "^1.10.21",
"@tscircuit/eval-webworker": "^0.0.20",
"@tscircuit/pcb-viewer": "^1.10.22",
"@tscircuit/schematic-viewer": "2.0.3",
"comlink": "^4.4.2",
"cssnano": "^7.0.6",
Expand Down

0 comments on commit 28f8a8b

Please sign in to comment.