Skip to content

Commit 2b89886

Browse files
authored
large led matrix test and fix for memoization (#115)
1 parent 5ff521d commit 2b89886

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

biome.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"indentStyle": "space"
99
},
1010
"files": {
11-
"ignore": ["cosmos-export", "dist", "package.json"]
11+
"ignore": ["cosmos-export", "dist", "package.json", "*.circuit.json"]
1212
},
1313
"javascript": {
1414
"formatter": {
@@ -28,6 +28,9 @@
2828
"suspicious": {
2929
"noExplicitAny": "off"
3030
},
31+
"correctness": {
32+
"useExhaustiveDependencies": "off"
33+
},
3134
"style": {
3235
"noNonNullAssertion": "off",
3336
"useNumberNamespace": "off",

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@types/react": "^18.3.3",
3636
"circuit-json": "^0.0.128",
3737
"next": "^14.1.4",
38+
"pixi.js": "^8.6.6",
3839
"react": "^18.2.0",
3940
"react-dom": "^18.2.0",
4041
"react-use": "^17.4.0",

src/PCBViewer.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ export const PCBViewer = ({
3535
editEvents: editEventsProp,
3636
onEditEventsChanged,
3737
}: Props) => {
38-
soup ??= circuitJson
38+
circuitJson ??= soup
3939
const {
4040
circuitJson: circuitJsonFromChildren,
4141
error: errorFromChildren,
4242
isLoading,
4343
} = useRenderedCircuit(children)
44+
circuitJson ??= circuitJsonFromChildren ?? []
4445

4546
const [ref, refDimensions] = useMeasure()
4647
const [transform, setTransformInternal] = useState(defaultTransform)
@@ -55,8 +56,6 @@ export const PCBViewer = ({
5556
let [editEvents, setEditEvents] = useState<EditEvent[]>([])
5657
editEvents = editEventsProp ?? editEvents
5758

58-
const stateElements = circuitJsonFromChildren ?? soup ?? []
59-
6059
const resetTransform = () => {
6160
const elmBounds =
6261
refDimensions?.width > 0 ? refDimensions : { width: 500, height: 500 }
@@ -88,12 +87,12 @@ export const PCBViewer = ({
8887
}
8988
}, [children, refDimensions])
9089

91-
const pcbElmsPreEdit: AnyCircuitElement[] = (
92-
circuitJson ??
93-
soup ??
94-
stateElements
95-
).filter(
96-
(e: any) => e.type.startsWith("pcb_") || e.type.startsWith("source_"),
90+
const pcbElmsPreEdit: AnyCircuitElement[] = useMemo(
91+
() =>
92+
circuitJson.filter(
93+
(e: any) => e.type.startsWith("pcb_") || e.type.startsWith("source_"),
94+
),
95+
[circuitJson],
9796
)
9897

9998
const elements = useMemo(() => {

src/stories/repros/repro4-large-led-matrix/large-led-matrix.circuit.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from "react"
2+
import { Meta, StoryObj } from "@storybook/react"
3+
import { PCBViewer } from "../../../PCBViewer"
4+
import circuitJson from "./large-led-matrix.circuit.json"
5+
6+
export const Repro4LargeLedMatrix: React.FC = () => {
7+
return (
8+
<div style={{ backgroundColor: "black" }}>
9+
<PCBViewer circuitJson={circuitJson as any} />
10+
</div>
11+
)
12+
}
13+
14+
const meta: Meta<typeof Repro4LargeLedMatrix> = {
15+
title: "Repros",
16+
component: Repro4LargeLedMatrix,
17+
}
18+
19+
export default meta

0 commit comments

Comments
 (0)