Scaffold Our Shopping Cart (Part II)

Learn how to link all of our channels to one another.

We'll cover the following

Sync all tabs

One important aspect of our application design is that all the user’s tabs stay in sync. Because each tab is a different Channel instance, we need to link the Channels to each other. The simplest way to do this is via the Channel topic. Two Channels with the topic cart:123 should be linked together. They should be separate from a Channel with the topic cart:345.

Browser cookies are a great place to store semi-permanent data. We will generate and store a random identifier in the cookie session so that multiple tabs share the same identifier. First, we need a way to generate a random cart ID. It is best to use :crypto.strong_rand_bytes/1 for this purpose. Add the following function to the Checkout module:

Get hands-on with 1200+ tech skills courses.