Skip to content

A proper way of update/re-render single item (using redux) #121

@soulfly

Description

@soulfly

We are building a chat app using ngx-ui-scroll

Seems we have an issue with understanding of how to properly do one thing

Let's say we have data source with 50 messages

Now a user sends 2 new messages, so we call adapter.append to show them, all is good

Then we have messages states, so by default the state is sent and a user can receive a delivered state signal per each message.

So once we receive a delivery signal - we update a special field of message in redux, which causes our subscription to get an updated messages array from redux:

this.conversationRepo.getSelectedConversationMessages().subscribe(messages => {
   // 50 messages
})

So we got 2 signals about delivered state (for our new messages we sent) and then got our subscription called 2 times as well

And here we have 2 questions:

  1. if we want to re-render a single message item to update message.state mark in UI, how we can do it? I see adapter.reload which should be a proper way, but it does not receive a single item index to reload, but a startIndex instead which will cause more items to be reloaded

  2. Is there a way just to connect a redux to ngx-ui-scroll and then it will do all it's job what changed and need to be reloaded and what's not ?

As an alternative idea - my initial idea was to call adapter.reload() all the time we have a redux upgraded (w/o startIndex) and also to have a new method in adapter shouldReload which will then determine should an item be reloaded or not

    this.datasource = new Datasource ({
      get: (index, count, success) => {
        const data = this.getAdpterData(index, count).reverse();
        success(data);
      },
      shouldReload: (index) => {
          return true/false;
       } 
   });

Could you please let me know your thoughts re this

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