-
Notifications
You must be signed in to change notification settings - Fork 352
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
Remove jQuery from answer types #2278
base: main
Are you sure you want to change the base?
Conversation
Size Change: -22 B (0%) Total Size: 735 kB
ℹ️ View Unchanged
|
return []; | ||
}); | ||
const transformed = fractionTransformer(text); | ||
return transformed.reduce( |
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.
jQuery's map
seemingly does some special flattening/filtering that's not as straight-forward as JS' map
: HubSpot/youmightnotneedjquery#355
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.
Agreed. jQuery's map
says for the mapping callback:
The function can return:
* the translated value, which will be mapped to the resulting array
* null or undefined, to remove the item
* an array of values, which will be flattened into the full array
That last point comes into play. I think you could just use flatMap()
here instead of reduce()

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.
Good call out, thank you
@@ -442,17 +461,17 @@ const KhanAnswerTypes = { | |||
|
|||
// Numbers with percent signs | |||
percent: function (text) { | |||
text = $.trim(text); | |||
text = String(text).trim(); |
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.
jQuery's trim
coerces numbers to strings and apparently our code was banking on that.
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (ae6ed1f) and published it to npm. You Example: pnpm add @khanacademy/perseus@PR2278 If you are working in Khan Academy's webapp, you can run: ./dev/tools/bump_perseus_version.sh -t PR2278 |
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.
I'd love to see us build more unit tests around this file. It's pretty complex and has a pretty light set of tests. :) Not blocking this PR though!
return []; | ||
}); | ||
const transformed = fractionTransformer(text); | ||
return transformed.reduce( |
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.
Agreed. jQuery's map
says for the mapping callback:
The function can return:
* the translated value, which will be mapped to the resulting array
* null or undefined, to remove the item
* an array of values, which will be flattened into the full array
That last point comes into play. I think you could just use flatMap()
here instead of reduce()

Summary:
I'm kind of just trying this out, but I think it would be good to remove jQuery where possible anyway.
See: https://khanacademy.slack.com/archives/CDHPTMSTB/p1741115861977089