-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55f56f8
commit 381d88e
Showing
8 changed files
with
43 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,35 @@ | ||
import React, { useState } from "react"; | ||
import SvgDisplay from "./SvgDisplay"; | ||
import { MemoryModels, MemoryModel } from "./MemoryModels"; | ||
|
||
const DEMO_OBJECTS = [ | ||
{ | ||
isClass: true, | ||
name: "__main__", | ||
id: null, | ||
value: { lst1: 82, lst2: 84, p: 99, d: 10, t: 11 }, | ||
stack_frame: true, | ||
}, | ||
{ | ||
isClass: false, | ||
name: "str", | ||
id: 19, | ||
value: "David is cool!", | ||
style: ["highlight"], | ||
}, | ||
{ isClass: false, name: "int", id: 13, value: 7 }, | ||
]; | ||
import MemoryModelsUserInput from "./MemoryModels"; | ||
import { ErrorBoundary } from "react-error-boundary"; | ||
|
||
export default function App() { | ||
const [formData, setFormData] = useState(""); | ||
const [jsonResult, setJsonResult] = useState([]); | ||
const [jsonResult, setJsonResult] = useState(null); | ||
|
||
const onSubmit = async (event) => { | ||
event.preventDefault(); | ||
setJsonResult(JSON.parse(formData)); | ||
try { | ||
setJsonResult(JSON.parse(formData)); | ||
} catch (error) { | ||
console.error("Error parsing inputted JSON: ", error); | ||
setJsonResult(null); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<MemoryModels | ||
<MemoryModelsUserInput | ||
formData={formData} | ||
setFormData={setFormData} | ||
onSubmit={onSubmit} | ||
/> | ||
<SvgDisplay jsonResult={jsonResult} /> | ||
<section> | ||
<h2>Output</h2> | ||
<ErrorBoundary fallback={<div>Something went wrong</div>}> | ||
<SvgDisplay jsonResult={jsonResult} /> | ||
</ErrorBoundary> | ||
</section> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,20 @@ | ||
import React, { useRef, useEffect } from "react"; | ||
import mem from "../../src/index"; // TODO: replace with import of the package after it's been published | ||
|
||
// const DEMO_OBJECTS = [ | ||
// { | ||
// isClass: true, | ||
// name: "__main__", | ||
// id: null, | ||
// value: { lst1: 82, lst2: 84, p: 99, d: 10, t: 11 }, | ||
// stack_frame: true, | ||
// }, | ||
// { | ||
// isClass: false, | ||
// name: "str", | ||
// id: 19, | ||
// value: "David is cool!", | ||
// style: ["highlight"], | ||
// }, | ||
// { isClass: false, name: "int", id: 13, value: 7 }, | ||
// ]; | ||
|
||
export default function SvgDisplay(props) { | ||
const canvasRef = useRef(null); | ||
|
||
useEffect(() => { | ||
if (props.jsonResult.length > 0) { | ||
if (props.jsonResult !== null) { | ||
const m = mem.draw(props.jsonResult, true, { width: 1300 }); | ||
m.clear(canvasRef.current); | ||
m.render(canvasRef.current); | ||
} | ||
}, [props.jsonResult]); | ||
|
||
return ( | ||
<section> | ||
<h2>Output</h2> | ||
<> | ||
<canvas ref={canvasRef} width={1000} height={1000} />; | ||
</section> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters