Skip to content
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 passing comparators to flamegraph.sort #188

Merged
merged 1 commit into from
Oct 12, 2021

Conversation

nickgirardo
Copy link
Contributor

I've added a third overload for sort to the type definitions. This definition allows passing in a comparator function.

You can see an example of this in the existing examples. While this works fine, the TypeScript definitions only allowed for passing no args or a boolean in.

You will notice this is a simple comparator function, similar to those used by d3 array in its type definitions. Notice that I've bound the generic variable T here to StackFrame. I'm not 100% sure that's correct. If other things besides StackFrames could be passed as arguments to sort, we can modify it or keep it generic.

This has always been possible-- and has examples in documentation
however they typescript definitions did not include this until now
@spiermar spiermar self-requested a review September 22, 2021 16:07
@spiermar
Copy link
Owner

Thank you @nickgirardo! Good catch! A generic variable would be preferable here I believe. I have a few cases where a modified string is passed.

Copy link
Owner

@spiermar spiermar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but changing to a generic variable would be preferable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants