-
Notifications
You must be signed in to change notification settings - Fork 351
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
Allow APIOptions.trackInteraction()'s arg object to have extra keys #616
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/perseus": minor | ||
--- | ||
|
||
Extend argument object type for APIOptions.trackInteraction callback to support the arbitrary data each widget may add |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,33 @@ | ||
import { | ||
linterContextProps, | ||
linterContextDefault, | ||
} from "@khanacademy/perseus-linter"; | ||
import PropTypes from "prop-types"; | ||
import {linterContextDefault} from "@khanacademy/perseus-linter"; | ||
import * as React from "react"; | ||
import _ from "underscore"; | ||
|
||
import InlineIcon from "../components/inline-icon"; | ||
import {iconOk} from "../icon-paths"; | ||
import * as Changeable from "../mixins/changeable"; | ||
import {ApiOptions} from "../perseus-api"; | ||
import {PerseusSequenceWidgetOptions} from "../perseus-types"; | ||
import Renderer from "../renderer"; | ||
import Util from "../util"; | ||
|
||
import type {WidgetExports} from "../types"; | ||
|
||
class Sequence extends React.Component<any, any> { | ||
static propTypes = { | ||
...Changeable.propTypes, | ||
apiOptions: ApiOptions.propTypes, | ||
json: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
content: PropTypes.string, | ||
images: PropTypes.objectOf(PropTypes.any), | ||
widgets: PropTypes.objectOf(PropTypes.any), | ||
}), | ||
), | ||
trackInteraction: PropTypes.func.isRequired, | ||
linterContext: linterContextProps, | ||
}; | ||
import type {WidgetExports, WidgetProps} from "../types"; | ||
|
||
type Rubric = PerseusSequenceWidgetOptions; | ||
|
||
type ExternalProps = WidgetProps<PerseusSequenceWidgetOptions, Rubric>; | ||
|
||
type Props = ExternalProps; | ||
|
||
type DefaultProps = { | ||
Comment on lines
+14
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is our more modern way to define prop types for widgets. It uses |
||
json: Props["json"]; | ||
linterContext: Props["linterContext"]; | ||
}; | ||
|
||
type State = { | ||
visible: number; | ||
}; | ||
|
||
static defaultProps: any = { | ||
class Sequence extends React.Component<Props, State> { | ||
static defaultProps: DefaultProps = { | ||
json: [ | ||
{ | ||
content: "", | ||
|
@@ -41,7 +38,7 @@ class Sequence extends React.Component<any, any> { | |
linterContext: linterContextDefault, | ||
}; | ||
|
||
state: any = { | ||
state = { | ||
visible: 1, | ||
}; | ||
|
||
|
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.
The changes here are just migrating this widget to use TypeScript types for Props and State.
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.
This is awesome, thank you 🌈