Closed cjblomqvist closed 10 years ago
This is definitely true. For now, I've decided to punt on this. I am going to remove the ability for filters to work off of arrays and just throw an Error for now. This would be a nice feature, but I don't think it is worth the effort in the short term.
refLists doesn't currently work very well with arrays. There are a few reasons why that I've managed to pinpoint, including that:
A) RefList.prototype.idByItem always returns keys (indices) as strings, albeit in arrays they are actually numbers. This causes faulty lookups and comparison.
B) Another thing is that with arrays, if you insert or remove any items, your id list will most likely cause updates on the list where the output is (i.e. the to parameter; the first parameter). This is because if you make an insert, on the underlying array, your ids will probably get skewed. This may be desired behavior in certain scenarios, but in some other it's not. One workaround is to patch those changes afterwards, but that will cause a not wanted amount of changes (especially in the UI this is not desired). Further, this can become rather complicated. A better solution is to add a parameter where you can specify you want the ids to automatically get patched on inserts and removes.
One place where this affects the functionality is with filters. I originally made a workaround where the filter is responsible for patching, but a lot of strange edge cases happened and the patching became very cumbersome. Furthermore, a not wanted amount of changes would still occur (basically re-rendering items back and forth).
Both these issues are now dealt with in my PR (compared to the somewhat hacky way around previously), and it seems like it is a lot less changes are now needed and it seems to be a much better and more stable solution.
I do understand refLists were perhaps not meant to work properly with Arrays based upon how refLists were implemented, but I think it would be a loss if the aim would not be to try to have it work properly with arrays too (especially since filters are depending on it).