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

feat(useSorted): new function #1799

Merged
merged 9 commits into from Oct 16, 2022
Merged

Conversation

okxiaoliang4
Copy link
Member

Description

Composable reactive sort array.

move from #1465

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@okxiaoliang4 okxiaoliang4 linked an issue Jul 8, 2022 that may be closed by this pull request
4 tasks
packages/core/useSorted/index.md Outdated Show resolved Hide resolved
packages/core/useSorted/index.md Show resolved Hide resolved
packages/core/useSorted/index.md Outdated Show resolved Hide resolved
packages/core/useSorted/index.md Outdated Show resolved Hide resolved
@antfu
Copy link
Member

antfu commented Aug 4, 2022

Converting to draft, please toggle when you back working on it.

@antfu antfu marked this pull request as draft August 4, 2022 05:20
@okxiaoliang4 okxiaoliang4 marked this pull request as ready for review September 8, 2022 17:43
@okxiaoliang4
Copy link
Member Author

I am back! Too busy with work recently :(

@okxiaoliang4 okxiaoliang4 enabled auto-merge (squash) September 8, 2022 17:48
@okxiaoliang4 okxiaoliang4 merged commit feaa195 into vueuse:main Oct 16, 2022
@okxiaoliang4 okxiaoliang4 deleted the feat/useSorted branch October 17, 2022 00:42
@CallerOfSouls
Copy link

I really think this is a neat composable, but I cannot for the life of me figure out how the compare function works to be able to do something like :
[{name:"John",age:36,status:"First"},{name:"John",age:35,status:"First"},{name:"John",age:35,status:"waiting"},{name:"John",age:35,status:"attending"}]

and then compare it so that I could sort it like useSorted(items,(a,b)=>{ if(a.name == b.name) if(a.age == b.age) if(a.status > b.status){ return position_in_array_to_be; } else if(a.name == b.name){ if(a.age > b.age){ return new_Position_value; }else{ if(a.status <= b.status){ return position_in_array_to_be--; } return new_Position_Value++ } } }). i am aware that this code does not work, I have tried several variations using a var order = ref(0)
and trying to keep up with an order by myself through addition and subtraction but there is no way to properly get that to work it seems. Any advice on how we could make this easier to use with multiple parameters would be awesome. Maybe I need to look into how to contribute myself..... but any help is appreciated again!

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.

proposal: useSort
3 participants