I’m currently working on a project and I decided to give liveview a try. I’m so happy with it and thanks for all the contributions everyone made.
I’m posting to ask whether my approach is authentic. Here we go: (it’s an auction system)
item: item has many bids
bid: bid belongs to an item
on the liveview page: I loaded all the items. (I’m not using temporary assign because I need to find a specific item later on)
when I click a specific item, a modal is popup, and I can create a new bid.
After the new bid is saved in the database, I want the bid number to be updated on the page.
I try to solve this with pubsub. After creating a bid, message is broadcasted to all subscriber including the liveview page.
In handle_info, I reload the bid association of the specific item. Then I use Enum.replace_at to replace that item in the items assign in the socket.
I knew that if I used temporary assign, I can simply [item | items] to let liveview track the difference and replace specific item. what can I do to utilize the similar mechanism without using temporary assign?
is it possible to use temporary assign in my use case? ( I need to find the detailed information of specific item after the initial rendering)
order is a must-have criteria. I think I will have to traverse the list. Also, I found that Enum.reject is used during deletion in liveview doc. I guess it’s ok when the list is not huge when pagination is involved.