-
Notifications
You must be signed in to change notification settings - Fork 365
[AbsoluteValue] PR5 - editor support #3352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
11660f2
[LEMS-3347/absolute-value-pr5] Implement PR #5
handeyeco d53d5ef
[LEMS-3347/absolute-value-pr5] restore export
handeyeco 166e08c
[LEMS-3347/absolute-value-pr5] docs(changeset): Add editor support fo…
handeyeco 99494a9
[LEMS-3347/absolute-value-pr5] add feature flag
handeyeco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@khanacademy/perseus": minor | ||
| "@khanacademy/perseus-editor": minor | ||
| --- | ||
|
|
||
| Add editor support for AbsoluteValue |
This file contains hidden or 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 hidden or 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
1 change: 1 addition & 0 deletions
1
packages/perseus-editor/src/widgets/interactive-graph-editor/start-coords/types.ts
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 The
absolute-valuecase usesStartCoordsPoint(which expectsCoord[]) instead ofStartCoordsLine(which expectsCollinearTuple/[Coord, Coord]). SincegetAbsoluteValueCoordsreturns[Coord, Coord], usingStartCoordsLinewould be more type-safe and consistent with howlinear/rayhandle the same structure.Extended reasoning...
What the bug is
The new
absolute-valuecase inStartCoordsSettingsInner(line 46-57) rendersStartCoordsPointto handle start coordinate editing. However,getAbsoluteValueCoordsreturns[Coord, Coord](a fixed-length tuple), which is the same shape asCollinearTupleused bylinearandraygraph types.StartCoordsPointexpectsCoord[](variable-length array) and is designed forpoint/polygongraphs.How the type widening happens
StartCoordsPointdeclares its props as{ startCoords: Coord[]; onChange: (startCoords: Coord[]) => void }. ItsonChangehandler usesconst newStartCoords = [...startCoords](spread into a new array), then callsonChange(newStartCoords). This spread widens the TypeScript type from[Coord, Coord]toCoord[]. In contrast,StartCoordsLinedeclares{ startCoords: CollinearTuple; onChange: (startCoords: CollinearTuple) => void }and its onChange constructs the tuple explicitly:onChange([value, startCoords[1]]), preserving the[Coord, Coord]type.Step-by-step proof
StartCoordsSettingsInnermatchescase "absolute-value"(line 46).getAbsoluteValueCoordsis called, returning a[Coord, Coord]value.<StartCoordsPoint startCoords={absoluteValueCoords} onChange={onChange} />.StartCoordsPoint.onChangefires with[...startCoords](line 31 of start-coords-point.tsx), producingCoord[].onChangeprop propagates thisCoord[]value upward, where the absolute-value graph expects[Coord, Coord].For comparison,
linearandray(which have the identical[Coord, Coord]type) correctly useStartCoordsLine(lines 62-68), andsinusoid(also[Coord, Coord]) usesStartCoordsSinusoid.Impact
This is not a runtime bug — at JavaScript runtime, a 2-element array is indistinguishable whether typed as
[Coord, Coord]orCoord[], and the UI renders identically (both show "Point 1" / "Point 2" inputs). TheonChangehandler at line 170 is untyped, so the widening passes silently. However, it is a type-safety and consistency concern: downstream TypeScript code expecting[Coord, Coord]could receiveCoord[], and this breaks the established pattern in the codebase.How to fix
Replace
StartCoordsPointwithStartCoordsLinein theabsolute-valuecase, matching the pattern used bylinear/ray: