Scaffold Our Shopping Cart Channel (Part I)
Explore how to build a maintainable real-time shopping cart by developing its functional core in Elixir. Learn to handle cart data with structs, add and remove items, serialize state securely for browser storage, and prepare for integration with Phoenix channels.
We'll cover the following...
Shopping cart
We’ll start developing our shopping cart by writing code that the Channel will use—our functional core. After we build our functional core, we’ll use it to develop a ShoppingCartChannel. We’ll start small and work our way up to a complete cart by the end of this section.
It’s essential to build a functional core that contains logic, data structures, or other parts of a program independent of the user interface. This helps increase the maintainability of our code because the separation between interface and logic means that either can be changed without a complete rewrite of the application. We’ll have an easier time adapting to change and adding new features when our application is split into separate parts this way.
Earlier, our ProductChannel accessed inventory data through an Inventory context—this was our functional core. We’re going to build ...