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

Wrapper function for functions with similar functionality #1662

Closed
wants to merge 11 commits into from

Conversation

5saviahv
Copy link
Contributor

@5saviahv 5saviahv commented Jan 9, 2021

Wrapper function "_matcher" for functions with similar functionality.

  • It changes .parents function sorting (test shows strange sorting order)
  • it changes .siblings function matched elements (it matches same elements what jQuery [first example on their website] )

other functions work like before, simply repeating parts of the functions are kept in "wrapper" function

@5saviahv 5saviahv requested a review from fb55 January 9, 2021 06:25
@5saviahv 5saviahv marked this pull request as ready for review January 9, 2021 06:26
@fb55
Copy link
Member

fb55 commented Jan 12, 2021

Hi @5saviahv, this is an awesome idea, thanks for opening this PR! I just started a new job, so might need some time to review this properly – sorry about that. Also no need to rebase the PR (that is great, but GitHub can deal with it).

@5saviahv
Copy link
Contributor Author

Thanks for telling, take your time - in jQuery there are many such functions, it reduces repeating same constructs over and over.

@5saviahv
Copy link
Contributor Author

  • added fixture eleven so order of elements will be visible also it is separated by LF so tests have to deal with text nodes as well.
  • added some comments to function

Copy link
Member

@fb55 fb55 left a comment

Choose a reason for hiding this comment

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

This is a great idea! Right now, it will lead to a slowdown due to uniqueSort being used quite a bit, when some of the results were taken without a change before. I've left some comments, let me know if they are useful.

lib/api/traversing.js Outdated Show resolved Hide resolved
lib/api/traversing.js Outdated Show resolved Hide resolved
lib/api/traversing.js Show resolved Hide resolved
lib/api/traversing.js Outdated Show resolved Hide resolved
lib/api/traversing.js Outdated Show resolved Hide resolved
lib/api/traversing.js Outdated Show resolved Hide resolved
@5saviahv
Copy link
Contributor Author

Sry, while loop in siblings function kind of broke thing (first element was discarded) and I wasnt able revert it so I overwrite it.

@5saviahv
Copy link
Contributor Author

I added Cheerio-Select #7 and it is related to this. We can later come back and change how uniqueSort works.

Copy link
Member

@fb55 fb55 left a comment

Choose a reason for hiding this comment

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

I added cheeriojs/cheerio-select#7 and it is related to this. We can later come back and change how uniqueSort works.

I have updated cheerio-select's filter method to no longer change the order of the input. That hopefully (?) removes the need for sorting in here entirely.

lib/api/traversing.js Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants