Skip to content

Instantly share code, notes, and snippets.

@ratbeard
Last active March 1, 2019 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ratbeard/c6d6c307008028bfdf5a0bccc3c1674b to your computer and use it in GitHub Desktop.
Save ratbeard/c6d6c307008028bfdf5a0bccc3c1674b to your computer and use it in GitHub Desktop.
/*
griz asks:
something I didn't get
question isn't in the object passed in, and the order of the args doesn't match
seems like that'd be a type error?
*/
export function MatchingQuestion({ onSelectChoice, onBreakMatch, questionState }: {
question: MatchingQuestionUI;
questionState: MatchingQuestionState;
onSelectChoice: (choice: MatchingChoice) => void;
onBreakMatch: (choice: MatchingChoice) => void;
}) {
// Equiv to =>
interface Argz {
question: MatchingQuestionUI;
questionState: MatchingQuestionState;
onSelectChoice: (choice: MatchingChoice) => void;
onBreakMatch: (choice: MatchingChoice) => void;
}
export function MatchingQuestion({ onSelectChoice, onBreakMatch, questionState }: Argz) {
// Equiv to =>
interface Argz {
question: MatchingQuestionUI;
questionState: MatchingQuestionState;
onSelectChoice: (choice: MatchingChoice) => void;
onBreakMatch: (choice: MatchingChoice) => void;
}
export function MatchingQuestion(props: Argz) {
const { onSelectChoice, onBreakMatch, questionState } = props
// So, its ok to not be destructuring all the properties out of the given props, and the order doesn't matter.
// Though the unused `question` prop should be deleted out of the inline interface def. 🧹
// And I generally try to sort stuff alphabetically. `highlight lines, cmd+shift+p, Sort Lines Ascending)` for lines,
// manually for props w/in a destructure. Though *GOD DAMNIT* I am merely human 🧜🏻‍♂️
@ratbeard
Copy link
Author

ratbeard commented Mar 1, 2019

2019-03-01 at 12 44 30 pm

@justinmchase
Copy link

I kind of do each one depending on the size. The more properties I have the more likely to do #3. I definitely prefer this over having each be a separate function arg.

I hate alphabetizing anything though, I like to sort them by name length or simple types down to complex types or by how related they are... Or just how pleasant they look to me in the code editor with syntax highlighting. But never alphabetically.

@justinmchase
Copy link

For example I'd do this:

{
userId: string,
name: string,
profile: IUserProfile
}

Eff alphabetizing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment