angular-ui / ui-scroll

Unlimited bidirectional scrolling over a limited element buffer for AngularJS applications

Home Page:http://angular-ui.github.io/ui-scroll/demo/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Index with decimal...

priandsf opened this issue · comments

Not sure if this is a bug or not, but it sometimes calls the datasource with a non integer number, like 19.4 (and count=10). In that case, should we round it down to 19 but then, should we increment the count as well?

Thanks for the issue! Having analysed it shallowly, I would say following. This

(success) => datasource.get(buffer.next, bufferSize, success) :

and that
(success) => datasource.get(buffer.first - bufferSize, bufferSize, success) :

are the only places where index are being passed to the datasource.get. The buffer.next and buffer.first are being maintained by src/modules/buffer.js and there are only ++, --, =1 and =startIndex operations. So I'm wondering how did you get this non-decimal index value...

Maybe I'm missing something, so it needs to be debugged, what code is responsible for breaking index integrity. If you want me to debug, the best option would be to make a plunkr/jsfiddle/stackblitz demo reproducing the issue.

Thank Denis. I need to debug through it which I'll do this week-end. It seems that the issue happens after a reload, where we changed the data source and the #of rows. The debugger shows, for example. buffer.first, maxIndex, minIndex all set a the value like "22.6". I'll try to find out how this happens
image

Your screenshot makes me think about

reset(startIndex) {
buffer.remove(0, buffer.length);
buffer.eof = false;
buffer.bof = false;
buffer.first = startIndex;
buffer.next = startIndex;
buffer.minIndex = startIndex;
buffer.maxIndex = startIndex;
buffer.minIndexUser = null;
buffer.maxIndexUser = null;
},

So, speaking of reload, I would recommend to investigate startIndex argument value...

Anyway, I think it is a good idea to protect "start-index" attribute and Adapter.reload(startIndex) argument from non-decimal values right in the ui-scroll code. I see it's not safe now, it is fully under user responsibility, which could be improved. Putting enhancement label.

Yep this is I actually did and this is the culprit. So nothing on your side, unless you might want to make it robust calling Math.floor().
Thanks for your help, this is an awesone library!

angular-ui-scroll v1.7.3 has been released, it includes "start-index" attribute and Adapter.reload method argument pre-validation