Repository navigation
Extracted read-only Graph.js state functions into typed graphState module - #1825
Merged
Merged
Conversation
Moves isSelected, isSelectedNode, isSelectedBool, and the
arePrereqsSatisfied{Bool,Node,Hybrid} methods out of Graph.js into pure
functions in graphState.ts that take the relevant state slice explicitly,
and adds unit tests for them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Moves the pure status calculations out of updateNode, updateNodeBool, updateEdgeStatus, and the FCE total in componentDidUpdate into computeNodeStatus, computeBoolStatus, computeEdgeStatus, and totalSelectedCredits in graphState.ts, with unit tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Coverage Report for CI Build 41326257887Coverage increased (+0.1%) to 60.788%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Proposed Changes
This continues breaking up
Graph.js. It extracts the functions that only read graph state into a new typed module,js/components/graph/graphState.ts. Each is a pure function that takes the relevant state as an explicitGraphStateparameter (aPickofLoadedGraphData).Graph.jsnow calls them withthis.state, which keeps the same timing as the old methods, since those also readthis.statewhen called.Moved out of
Graph.js:isSelected,isSelectedNode,isSelectedBool. These were removed fromGraphas methods.arePrereqsSatisfiedBool,arePrereqsSatisfiedNode,arePrereqsSatisfiedHybrid. These were removed fromGraphas methods.setState:computeNodeStatus, fromupdateNodecomputeBoolStatus, fromupdateNodeBoolcomputeEdgeStatus, fromupdateEdgeStatustotalSelectedCredits, fromcomponentDidUpdateSmall simplifications made while moving the code (no behaviour change):
arePrereqsSatisfiedNodeno longer handles nested arrays of parents.loadGraphDataonly produces flatstring[]parent lists, so that branch could never run.arePrereqsSatisfiedBoolmerged an if/else whose two branches were identical. It also returnsfalseinstead ofundefinedfor a bool that isn't "and"/"or". Its only caller treats both values the same.Added
js/components/graph/__tests__/graphState.test.js, which covers each function on a small sample graph containing course nodes, hybrid nodes and bools.Screenshots of your changes (if applicable)
Type of Change
(Write an
Xor a brief description next to the type or types that best describe your changes.)Checklist
(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the
[ ]into a[x]in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)Before opening your pull request:
After opening your pull request:
Questions and Comments
js/components/graphtests pass, andgraphState.tshas 100% line and branch coverage.tscand eslint pass.updateNodereadsthis.state.edgesStatus[edge]where every other branch readsedgesJSON. BecauseedgesStatusvalues are strings,currentEdge.id_,.sourceand.targetare allundefined. As a result, that branch never recalculates the node's edges, and it writes a stray"undefined"entry intoedgesStatus. Fixing it changes behaviour, so it will be a separate PR with its own test.updateNode/focusPrereqsand related methods, which chain manysetStatecalls) into a single pure update ingraphState.tsthat calls onesetState.🤖 Generated with Claude Code