Open mwoc opened 9 years ago
The problem is that the SortByProjection keeps using the outputObservable
, splicing items in and out of it based on where they are according to the new comparefn, while it should find them with the old comparefn and insert them with the new.
Alternatively an onStructuralChange
should be triggered.
Or after some more testing, the binary search finds the right item for the first 14 changes, then fails 4 times (doesn't find the item at all, returns index -1), and the last 2 are found correctly again.
As we are able to detect failing to find the right item index, we could in that case implicitly trigger a full resort somehow.
https://github.com/One-com/knockout-projections/tree/feature/change-sort-order now implements automatic re-sorting when the above case is detected.
Seeing some slowness when testing this on my end, not sure why.
Let's look at it tomorrow.
I'm experiencing the same issue.
I've just looked and tried the feature branch and it seems to have solved all my issues! Seems quite snappy for changing the sort order on ~300 items!
Hi @mwoc, is this still an issue after I merged feature/change-sort-order to master?
@sunesimonsen were you notified of my note on this commit? https://github.com/One-com/knockout-projections/commit/7711a5a5d095915fbbbc456e1d7e3b0e876637b1
@AdamWillden maybe - I'll take a look at it.
I merged feature/change-sort-order and released a new version, so if you found a problem I'm of cause interested :-)
I fixed the problem you highlighted in 7711a5a. Thank for finding that.
Sounds good, I'll re-test with 1.3.1 soon and will close if it's working now.
@sunesimonsen the issue is worse than I first noticed. Look at the new comments I've added in the same commit: https://github.com/One-com/knockout-projections/commit/7711a5a5d095915fbbbc456e1d7e3b0e876637b1
Be worth checking I've not missed any more
@AdamWillden I responded to the comment inline.
I've got a use case for changing the sort direction or the sort key after the data already has been sorted, however that results in an invalid output with some items missing and some duplicated.
The second test in this commit fails as just described: https://github.com/One-com/knockout-projections/commit/463fd04042b545139a5e29bc9e2355aee15c2be6