Suppose there are some users, say 100. Each user has, say 100 items and a percentage of which are shared to the users by other users. Each item has a name.
So... What I want is, if I edit the name of item1 of user1, it should update all the users who have item1.
I have already setup the permissions necessary and REST api is working over controllers.
Now I want to implement real time updates and channels in phoenix are the right fit. If I have a channel with topic item:*
, I can account for all the items of all the users.
So, if there is a user1 with item1, item2, item3...., item100. How will I setup the listeners on javascript side? I don't think this would be right approach?
Can someone help me out with the structure please. Thanks!
UPDATE: Will the following approach work?
forEach(function(items, val) {
var topic = "item:" + val
// Join the topic
var channel = socket.channel(topic, {})
channel.join()
.receive("ok", data => {
console.log("Joined topic", topic)
})
.receive("error", resp => {
console.log("Unable to join topic", topic)
})
channel.on("name_changed", resp => {
console.log("name was changed of this item", resp);
})
});