Skip to content

Commit

Permalink
Switch to standard ES exports for objective utils
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremywiebe committed Dec 5, 2024
1 parent f355127 commit 91063b1
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 24 deletions.
4 changes: 2 additions & 2 deletions packages/perseus/src/interactive2/movable-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import KhanColors from "../util/colors";

import InteractiveUtil from "./interactive-util";
import MovableLineOptions from "./movable-line-options";
import objective_ from "./objective_";
import {pluck} from "./objective_";
import WrappedLine from "./wrapped-line";

const assert = InteractiveUtil.assert;
Expand Down Expand Up @@ -83,7 +83,7 @@ _.extend(MovableLine.prototype, {
// - are objects, not primitives (and need a deeper copy)
// - they don't need getters created for them
// TODO(jack): Consider "default" once we es3ify perseus
objective_.pluck(MovableLineOptions, "standard"),
pluck(MovableLineOptions, "standard"),
),
DEFAULT_PROPS,
);
Expand Down
4 changes: 2 additions & 2 deletions packages/perseus/src/interactive2/movable-point.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import Tex from "../util/tex";

import InteractiveUtil from "./interactive-util";
import MovablePointOptions from "./movable-point-options";
import objective_ from "./objective_";
import {pluck} from "./objective_";
import WrappedEllipse from "./wrapped-ellipse";

import type {Movable} from "./movable";
Expand Down Expand Up @@ -170,7 +170,7 @@ export class MovablePoint {
// - are objects, not primitives (and need a deeper copy)
// - they don't need getters created for them
// TODO(jack): Consider "default" once we es3ify perseus
objective_.pluck(MovablePointOptions, "standard"),
pluck(MovablePointOptions, "standard"),
// We only update props here, because we want things on state to
// be persistent, and updated appropriately in modify()
),
Expand Down
4 changes: 2 additions & 2 deletions packages/perseus/src/interactive2/movable-polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import GraphUtils from "../util/graph-utils";

import InteractiveUtil from "./interactive-util";
import MovablePolygonOptions from "./movable-polygon-options";
import objective_ from "./objective_";
import {pluck} from "./objective_";

const assert = InteractiveUtil.assert;
const normalizeOptions = InteractiveUtil.normalizeOptions;
Expand Down Expand Up @@ -91,7 +91,7 @@ _.extend(MovablePolygon.prototype, {
// - are objects, not primitives (and need a deeper copy)
// - they don't need getters created for them
// TODO(jack): Consider "default" once we es3ify perseus
objective_.pluck(MovablePolygonOptions, "standard"),
pluck(MovablePolygonOptions, "standard"),

// We only update props here, because we want things on state to
// be persistent, and updated appropriately in modify()
Expand Down
12 changes: 3 additions & 9 deletions packages/perseus/src/interactive2/objective_.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import _ from "underscore";
* rotation: false
* }
*/
const pluck = function (table: any, subKey: string): any {
export const pluck = function (table: any, subKey: string): any {
return _.object(
_.map(table, function (value, key) {
return [key, value[subKey]];
Expand All @@ -41,7 +41,7 @@ const pluck = function (table: any, subKey: string): any {
* });
* {a: 2, b: 3}
*/
const mapObject = function <K extends string, V, U>(
export const mapObject = function <K extends string, V, U>(
obj: Record<K, V>,
lambda: (arg1: V, arg2: K) => U,
): Record<K, U> {
Expand All @@ -61,7 +61,7 @@ const mapObject = function <K extends string, V, U>(
* });
* {a: 'aa', b: 'bb'}
*/
const mapObjectFromArray = function <K extends string, V>(
export const mapObjectFromArray = function <K extends string, V>(
arr: ReadonlyArray<K>,
lambda: (arg1: K) => V,
): Record<K, V> {
Expand All @@ -71,9 +71,3 @@ const mapObjectFromArray = function <K extends string, V>(
});
return result;
};

export default {
pluck: pluck,
mapObject: mapObject,
mapObjectFromArray: mapObjectFromArray,
};
4 changes: 1 addition & 3 deletions packages/perseus/src/renderer-util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Objective from "./interactive2/objective_";
import {mapObject} from "./interactive2/objective_";
import Util from "./util";
import {getWidgetIdsFromContent} from "./widget-type-utils";
import {getWidgetScorer, upgradeWidgetInfoToLatestVersion} from "./widgets";
Expand All @@ -8,8 +8,6 @@ import type {PerseusStrings} from "./strings";
import type {PerseusScore} from "./types";
import type {UserInput, UserInputMap} from "./validation.types";

const {mapObject} = Objective;

export function getUpgradedWidgetOptions(
oldWidgetOptions: PerseusWidgetsMap,
): PerseusWidgetsMap {
Expand Down
4 changes: 1 addition & 3 deletions packages/perseus/src/renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {DefinitionProvider} from "./definition-context";
import {getDependencies} from "./dependencies";
import ErrorBoundary from "./error-boundary";
import InteractionTracker from "./interaction-tracker";
import Objective from "./interactive2/objective_";
import {mapObject} from "./interactive2/objective_";
import JiptParagraphs from "./jipt-paragraphs";
import {Log} from "./logging/log";
import {ClassNames as ApiClassNames, ApiOptions} from "./perseus-api";
Expand Down Expand Up @@ -65,8 +65,6 @@ import type {LinterContextProps} from "@khanacademy/perseus-linter";

import "./styles/perseus-renderer.less";

const {mapObject} = Objective;

const rContainsNonWhitespace = /\S/;
const rImageURL = /(web\+graphie|https):\/\/[^\s]*/;

Expand Down
5 changes: 2 additions & 3 deletions packages/perseus/src/traversal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

import _ from "underscore";

// TODO(aria): Pull this out of interactive2 / replace with new _.mapObject
import objective_ from "./interactive2/objective_";
import {mapObject} from "./interactive2/objective_";
import * as Widgets from "./widgets";

const noop = function () {};
Expand Down Expand Up @@ -93,7 +92,7 @@ const traverseRenderer = function (
}
}

const newWidgets = objective_.mapObject(
const newWidgets = mapObject(
rendererOptions.widgets || {},
function (widgetInfo, widgetId) {
// Widgets without info or a type are empty widgets, and
Expand Down

0 comments on commit 91063b1

Please sign in to comment.