Phoenix design question: AJAX vs Channels for update form

I am creating an app where people can create items and put them into collections.

To give it a ‘single page app’-like feel, I want people to be able to click on an ‘edit’ icon and edit and update one of the items in-place.

Now there is a choice here to use AJAX to do the updating behind-the-scenes, or to use Phoenix Channels.
One advantage that channels might have, is that a user could listen to each item’s topic, and also be notified when another user makes a change in one of the items.

However, the application will contain hundreds of items per collection, meaning that users might subscribe to many, many topics while they browse through a collection. Would this pose a problem?

Also, I wonder what the best way would be to serialize a form while using Phoenix Channels.

What is the better option here?

Each topic subscribed from a Phoenix Channel is a new process, so keep that in mind. :slight_smile:

What I’ve done is have a single manager process, but the webpage sends messages to it saying ‘I want to be subscribed to this information’, it then internally calls MyEndpoint.subscribe/3 for each appropriate thing, which then all binds to ‘this’ one process, so no process spam then. I wish there were an interface to simplify this pattern as I use it a surprising amount, but it is very easy to do as it is. :slight_smile:

You can get a json of the form information via javascript, easy to pass that back over then. :slight_smile:

You can even call that one parse function on Plug to have it parse its special list and such syntax too.

1 Like