#937·cyclejs

Unable to sort a `Collection` with `@cycle/state`

Author: monojackCreated Mar 31, 2020Updated Apr 13, 2021

I'm trying to render a list of state.items with makeCollection and I'm using a state lens where the getter sorts that list based on a state.sort value and returns it.

Clicking a "sort" button would update the state.sort value and the lens getter is invoked, creates a new list, sorts and then returns it, but the dom items are not reordered until the next update to state.items.

After further investigating the issue, I found that pickCombine might be the culprit and changing these lines to

javascript
if (!ils.has(key)) {
  ils.set(key, new PickCombineListener(key, out, this, sink))
}
sink._remove(ils.get(key))
sink._add(ils.get(key))

would make it work, though I'm not sure about the implications and I don't know if it's introducing a memory leak.

Code to reproduce the issue: Edit beautiful-knuth-k3jsm

Expected behavior: Clicking the Toggle sort button would sort the list items in asc/desc/none order.

Actual behavior: The DOM doesn't update until you add a new item.

Versions of packages used:

json
"@cycle/dom": "22.6.0",
"@cycle/isolate": "5.2.0",
"@cycle/run": "5.4.0",
"@cycle/state": "1.4.0",
"snabbdom": "0.7.4",
"xstream": "11.11.0"