layout is handed out live, outlives its device, accepts anything (NaN boxes, silently lost arrays), and the API reads 0 as missing #1325
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
jaylouisw/packetforge#1325
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The third thing a board holds, after devices (#1321) and cables (#1323).
layout— where each box sits — wasthe least guarded of the three.
Measured against the current code:
Why each is a defect and not a taste
layoutwas stillhanding out its own object: the API response, the UI, the example builder and every test fixture received the live
layout, so adjusting what you were given adjusted the lab.
removeDevice()left the position. The server remembereddelete topo.layout[devId]; the engine did not. Aremoval from anywhere else — a script, a test, a future route — left a position in the file for a box that is not
on the board, and it accumulates with every board that ever had a device removed.
web/canvas.jsreadspos.xstraight from the layout.{"x": "left"}gives NaNcoordinates, so the box is not drawn anywhere and nothing says why.
layout: []is worse: accepted, kept inmemory, and then lost at the next save, because
JSON.stringifyignores an array's string keys — thepositions vanish on the next save, long after the document that caused it.
{ x: body.x || 160 }treats zero as missing, so a device placed at the origin — thetop-left corner, the one place a box is most likely to be dragged to — is quietly moved to 160,160.
/layoutstored whatever it was handed, unvalidated:{ "d1": { "x": "left" } }over HTTP.What must be true instead
serialize()copies the layout; the document you are given is yours to change;removeDevice()takes it, and a saved board has no box that is not on the board;E_LAYOUT_BAD_ENTRY); a layoutthat is not a map is refused (
E_LAYOUT_MALFORMED); a position naming a device the document does not contain is awarning (
E_LAYOUT_UNKNOWN_DEVICE) — all inloadIssues, which every state payload already carries;400naming the rule, checked for every entry before any is stored, so a badentry cannot half-apply a layout;
0places a device at0.runtime[].countershas two shapes (drops/ports missing on idle devices) and hands out the engine's live record #1329