Skip to content

Strange effect with inverted datasource  #115

Closed
@DaveLomber

Description

@DaveLomber

Hi there

I have implemented inverted data source to work with chat messages:

datasource: Datasource;
MIN_DATASOURCE_ITEMS_INDEX = 1; 


this.datasource = new Datasource ({
  get: (index, count, success) => {
    const data = this.getAdpterData(index, count).reverse();
    success(data);
  },
  settings: {
    startIndex: -10,
  }
});

getAdpterData(_index: number, count: number) {
  const index = -_index - count + this.MIN_DATASOURCE_ITEMS_INDEX;
  const data = [];
  const start = Math.max(this.MIN_DATASOURCE_ITEMS_INDEX, index);
  const end = index + count - 1;

  console.log(`[DataSource][getAdpterData] ${start} -> ${end}. Total: ${this.messages.length}, Rendered: ${this.datasource.adapter.itemsCount}, bof ${this.datasource.adapter.bof}`);

  if (start <= end) {
    for (let i = start; i <= end; i++) {
      data.push({body: i + "", from: "asdasd", index: i});
    }
  }
  return data;
}

So far all is good when I scroll to top, to get older history

But then, when I returned to bottom and then scroll again to top - the datasource.get method started to calling so much times

This effect can be seen on this video https://www.dropbox.com/s/wri4kt6fnf21s0g/ng-invertedd-scroll.mov?dl=0

I did many diff checks, but still not able to get the root cause.
If anybody has an idea - please share, will be much appreciated

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions