Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

Custom sorting function #33

Open
The-BlackWidow opened this issue Apr 25, 2018 · 2 comments
Open

Custom sorting function #33

The-BlackWidow opened this issue Apr 25, 2018 · 2 comments
Labels

Comments

@The-BlackWidow
Copy link

Hi again!

I would like to create my own sorting function in Vue 2.0, according to whether it is a folder or a leaf. However, I only get infinite loops:

      sort: (a, b) => {
        if((a.children && b.children) || (!a.children && !b.children)) {
          return a.name.localeCompare(b.name)
        } else if (a.children && !b.children) {
          return -1
        } else {
          return 1
        }
      }

Could you please help me understand how the sort function works?

@elbywan
Copy link
Owner

elbywan commented Apr 28, 2018

Hi @The-BlackWidow !

Actually this is a bug, I reproduced having an infinite loop simply by calling console.log(b.children) inside the sorting function.

As a workaround, you can try this while I will attempt to fix the real issue :

sort(a, b) { 
  const sameChildrenState = 'children' in a === 'children' in b
  if(sameChildrenState) {
    return a.name.localeCompare(b.name)
  } else if ('children' in a) {
    return -1
  } else {
    return 1
  }
}

@elbywan elbywan added the bug label Apr 28, 2018
@The-BlackWidow
Copy link
Author

Thank you very much! It's working. Please keep me posted when the fix is out 😃 !

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

No branches or pull requests

2 participants