-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
Imagine a chat app which implements offline support:
- you can "send" messages and they're added to the queue and shown immediately (optimistic updates)
- when the client reconnects, it pulls messages that were sent by others: the Date of their messages can thus be before the messages the user has sent out
- we need to place those messages at their appropriate places in the list (e.g. in the middle), not append them.
This is just one use case, but there are many others (like reordering lists, where you'd need to remove an item and re-add it in a different place).
I'd imagine a lot of the times you don't know the index and you'd actually need to find after/before which specific item you want your new item to appear with some sort of a search function.
Not sure how a pure/functional API would look like for this case, but if it were a classic mutable state, it'd be something like:
collection.addAfter(newItem, item => item.date < newItem.date)This would iterate on all the elements until the return value of the search is false, then insert the new item at the index of the first item that returned false.
How can we deal with this case using cycle-collection?
Metadata
Metadata
Assignees
Labels
No labels