Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
benchristel committed Jun 13, 2024
1 parent b9f6e89 commit d000b15
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ describe("StatefulMafsGraph", () => {
// Arrange: render a segment graph
const segmentGraphProps: StatefulMafsGraphProps = {
...getBaseStatefulMafsGraphProps(),
graph: {type: "segment"}
graph: {type: "segment"},
};
const {rerender} = render(<StatefulMafsGraph{...segmentGraphProps} />);
const {rerender} = render(<StatefulMafsGraph {...segmentGraphProps} />);

// Act: rerender with a quadratic graph
const quadraticGraphProps: StatefulMafsGraphProps = {
...getBaseStatefulMafsGraphProps(),
graph: {type: "quadratic"}
}
graph: {type: "quadratic"},
};
rerender(<StatefulMafsGraph {...quadraticGraphProps} />);

// Assert: there should be 3 movable points (which define the quadratic
Expand All @@ -135,21 +135,21 @@ describe("StatefulMafsGraph", () => {
// Arrange: render a segment graph with one segment
const oneSegmentProps: StatefulMafsGraphProps = {
...getBaseStatefulMafsGraphProps(),
graph: {type: "segment", numSegments: 1}
graph: {type: "segment", numSegments: 1},
};
const {rerender} = render(<StatefulMafsGraph{...oneSegmentProps} />);
const {rerender} = render(<StatefulMafsGraph {...oneSegmentProps} />);

// Act: rerender with two segments
const twoSegmentProps: StatefulMafsGraphProps = {
...getBaseStatefulMafsGraphProps(),
graph: {type: "segment", numSegments: 2}
}
graph: {type: "segment", numSegments: 2},
};
rerender(<StatefulMafsGraph {...twoSegmentProps} />);

// Assert: there should be 4 movable points. If there are 2 points, it
// means we are still rendering a single segment.
expect(screen.getAllByTestId("movable-point").length).toBe(4);
})
});
});

function graphToPixel(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {View} from "@khanacademy/wonder-blocks-core";
import {useLatestRef, View} from "@khanacademy/wonder-blocks-core";
import {UnreachableCaseError} from "@khanacademy/wonder-stuff-core";
import {Mafs} from "mafs";
import * as React from "react";
Expand Down Expand Up @@ -33,8 +33,8 @@ import {getGradableGraph, getRadius} from "./reducer/interactive-graph-state";
import {GraphConfigContext} from "./reducer/use-graph-config";

import type {InteractiveGraphState, InteractiveGraphProps} from "./types";
import type {Widget} from "../../renderer";
import type {PerseusGraphType} from "../../perseus-types";
import type {Widget} from "../../renderer";
import type {vec} from "mafs";

import "mafs/core.css";
Expand Down Expand Up @@ -152,9 +152,10 @@ export const StatefulMafsGraph = React.forwardRef<
}, [dispatch, xMinRange, xMaxRange, yMinRange, yMaxRange]);

const numSegments = graph.type === "segment" ? graph.numSegments : null;
const latestPropsRef = useLatestRef(props);
useEffect(() => {
dispatch(reinitialize(props));
}, [graph.type, numSegments]);
dispatch(reinitialize(latestPropsRef.current));
}, [graph.type, numSegments, latestPropsRef]);

return <MafsGraph {...props} state={state} dispatch={dispatch} />;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type InitializeGraphStateParams = {
step: [x: number, y: number];
snapStep: [x: number, y: number];
graph: PerseusGraphType;
}
};

export function initializeGraphState(
params: InitializeGraphStateParams,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {InitializeGraphStateParams} from "./initialize-graph-state";
import type {Interval, vec} from "mafs";
import {InitializeGraphStateParams} from "./initialize-graph-state";

export type InteractiveGraphAction =
| Reinitialize
Expand All @@ -21,7 +21,7 @@ export function reinitialize(params: InitializeGraphStateParams): Reinitialize {
return {
type: REINITIALIZE,
params,
}
};
}

export const MOVE_CONTROL_POINT = "move-control-point";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {vector as kvector} from "@khanacademy/kmath";
import {UnreachableCaseError} from "@khanacademy/wonder-stuff-core";
import type {Interval} from "mafs";
import {vec} from "mafs";
import _ from "underscore";

Expand All @@ -15,10 +14,10 @@ import {
} from "../../../util/geometry";
import GraphUtils from "../../../util/graph-utils";
import {polar} from "../../../util/graphie";
import type {QuadraticCoords} from "../graphs/quadratic";
import {getQuadraticCoefficients} from "../graphs/quadratic";
import {snap} from "../utils";

import {initializeGraphState} from "./initialize-graph-state";
import {
CHANGE_RANGE,
CHANGE_SNAP_STEP,
Expand All @@ -36,12 +35,14 @@ import {
type MoveControlPoint,
type MoveLine,
type MovePoint,
type MoveRadiusPoint, Reinitialize,
type MoveRadiusPoint,
REINITIALIZE,
} from "./interactive-graph-action";

import type {QuadraticCoords} from "../graphs/quadratic";
import type {InteractiveGraphState, PairOfPoints} from "../types";
import type {Coord} from "@khanacademy/perseus";
import {initializeGraphState} from "./initialize-graph-state";
import type {Interval} from "mafs";

export function interactiveGraphReducer(
state: InteractiveGraphState,
Expand Down

0 comments on commit d000b15

Please sign in to comment.