Skip to content

Commit ae58c67

Browse files
[feature/peich] A few fixes from the merge with main.
1 parent 61282e3 commit ae58c67

File tree

3 files changed

+14
-45
lines changed

3 files changed

+14
-45
lines changed

packages/perseus-core/src/traversal.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const missingOptions = {
1212
graded: true,
1313
static: false,
1414
options: {
15+
numCorrect: 1,
1516
choices: [
1617
{
1718
content: "A",
@@ -78,9 +79,9 @@ const sampleOptions2: PerseusRenderer = {
7879
randomize: false,
7980
multipleSelect: false,
8081
displayCount: null,
81-
noneOfTheAbove: false,
8282
deselectEnabled: false,
8383
countChoices: false,
84+
numCorrect: 1,
8485
},
8586
version: {
8687
major: 0,

packages/perseus-core/src/traversal.ts

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
import _ from "underscore";
1717

18-
import {mapObject, applyDefaultsToWidget} from "@khanacademy/perseus-core";
19-
2018
import {mapObject} from "./utils/objective_";
2119
import * as Widgets from "./widgets/core-widget-registry";
2220

@@ -30,47 +28,18 @@ const deepCallbackFor = function (
3028
optionsCallback: (arg1: any) => void,
3129
) {
3230
const deepCallback = function (widgetInfo: any, widgetId: string) {
33-
// This doesn't modify the widget info if the widget info
34-
// is at a later version than is supported, which is important
35-
// for our latestVersion test below.
36-
const upgradedWidgetInfo = applyDefaultsToWidget(widgetInfo);
37-
const latestVersion = Widgets.getVersion(upgradedWidgetInfo.type);
38-
39-
// Only traverse our children if we can understand this version
40-
// of the widget props.
41-
// TODO(aria): This will break if the traversal code assumes that
42-
// any props that usually get defaulted in are present. That is,
43-
// it can fail on minor version upgrades.
44-
// For this reason, and because the upgrade code doesn't handle
45-
// minor versions correctly (it doesn't report anything useful
46-
// about what minor version a widget is actually at, since it
47-
// doesn't have meaning in the context of upgrades), we
48-
// just check the major version here.
49-
// TODO(aria): This is seriously quirky and would be unpleasant
50-
// to think about while writing traverseChildWidgets code. Please
51-
// make all of this a little tighter.
52-
// I think once we use react class defaultProps instead of relying
53-
// on getDefaultProps, this will become easier.
54-
let newWidgetInfo;
55-
if (
56-
latestVersion &&
57-
upgradedWidgetInfo.version?.major === latestVersion.major
58-
) {
59-
newWidgetInfo = Widgets.traverseChildWidgets(
60-
upgradedWidgetInfo,
61-
(rendererOptions) => {
62-
return traverseRenderer(
63-
rendererOptions,
64-
contentCallback,
65-
// so that we traverse grandchildren, too:
66-
deepCallback,
67-
optionsCallback,
68-
);
69-
},
70-
);
71-
} else {
72-
newWidgetInfo = upgradedWidgetInfo;
73-
}
31+
const newWidgetInfo = Widgets.traverseChildWidgets(
32+
widgetInfo,
33+
(rendererOptions) => {
34+
return traverseRenderer(
35+
rendererOptions,
36+
contentCallback,
37+
// so that we traverse grandchildren, too:
38+
deepCallback,
39+
optionsCallback,
40+
);
41+
},
42+
);
7443

7544
const userWidgetInfo = widgetCallback(newWidgetInfo, widgetId);
7645
if (userWidgetInfo !== undefined) {

packages/perseus/src/renderability.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import {
1111
Errors,
1212
PerseusError,
13-
upgradeWidgetInfoToLatestVersion,
1413
traverse,
1514
applyDefaultsToWidget,
1615
} from "@khanacademy/perseus-core";

0 commit comments

Comments
 (0)