<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tracey Onim on Medium]]></title>
        <description><![CDATA[Stories by Tracey Onim on Medium]]></description>
        <link>https://medium.com/@traceyonim22?source=rss-80af953d809a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*hrDKiHbpzEjZVV37u5Z9aw.jpeg</url>
            <title>Stories by Tracey Onim on Medium</title>
            <link>https://medium.com/@traceyonim22?source=rss-80af953d809a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 21:18:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@traceyonim22/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Filling In The Blank, Artificial Intelligence(AI)]]></title>
            <link>https://medium.com/@traceyonim22/filling-in-the-blank-artificial-intelligence-ai-1104d8c09eea?source=rss-80af953d809a------2</link>
            <guid isPermaLink="false">https://medium.com/p/1104d8c09eea</guid>
            <category><![CDATA[vibe-coding]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[upskilling]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Tracey Onim]]></dc:creator>
            <pubDate>Thu, 21 Aug 2025 06:56:38 GMT</pubDate>
            <atom:updated>2025-08-21T06:56:38.580Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4OEXlgSo030JWa8WUpS_UA.jpeg" /></figure><p>AI is here — what’s next?</p><p>We’re already seeing incredible things being built with it. Productivity is improved, tasks are being completed faster than ever, and innovation seems endless.</p><h4>What is AI?</h4><p>To my understanding, it’s the ability of machines or systems to operate by mimicking human intelligence or cognitive functions.</p><p>You’ve probably interacted with it more than you realize, from voice assistants, to tools like ChatGPT, to code generators that help speed up development.</p><h4>AI and Software Engineers</h4><p>So, how are software engineers using AI?</p><ul><li>Some wonder if AI will eventually replace parts of our jobs.</li><li>Others see it as an opportunity, provided we upskill and adapt.</li></ul><p><strong>Vibe coding</strong> is just emerging, and people are performing wonders. <em>Vibe coding is using simple , descriptive language to express the needs and ideas to an AI agent and it generates code</em>. <a href="https://x.com/karpathy">Andrej Karpathy</a> explains it better on his <a href="https://x.com/karpathy/status/1886192184808149383">X post</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yhSxoXUdq8Cc-pPOXZixVg.png" /></figure><p>Also get to listen to his talk; <a href="https://youtu.be/LCEmiRjPEtQ">software is changing(Again)</a></p><p><strong>Vibe coding</strong> seems feasible to everyone, regardless of software development experience. If an MVP can be ready in 2 hours instead of 6 months, why not?</p><h4>The Big Question</h4><p>As software engineers, how do we efficiently leverage AI? Which direction should we take as this technology evolves?</p><p>I’d love to hear your thoughts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1104d8c09eea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Avoid Full Page Reloads with Live Navigation in Phoenix LiveView]]></title>
            <link>https://medium.com/@traceyonim22/avoid-full-page-reloads-with-live-navigation-in-phoenix-liveview-107ef13e5d7a?source=rss-80af953d809a------2</link>
            <guid isPermaLink="false">https://medium.com/p/107ef13e5d7a</guid>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[phoenix-liveview]]></category>
            <category><![CDATA[web-applications]]></category>
            <category><![CDATA[phoenix]]></category>
            <dc:creator><![CDATA[Tracey Onim]]></dc:creator>
            <pubDate>Mon, 14 Jul 2025 15:36:18 GMT</pubDate>
            <atom:updated>2025-07-14T15:36:18.971Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U9n6PfpSDQW9gW5hFbY-yQ.png" /></figure><p>If you’ve used a software application’s UI or visited a website, you’ve probably interacted with links, menus, or buttons that help you navigate between pages.</p><p>Page navigation is essential for a good user experience, enabling users to access different parts of the application easily.</p><p><a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html">Phoenix LiveView</a> — a library that allows the creation of rich, real-time web applications with server-rendered HTML — has a feature called <a href="https://hexdocs.pm/phoenix_live_view/live-navigation.html"><strong>live navigation</strong></a>, which lets you transition between pages without reloading the entire browser page.</p><p>Reloading the full page, whether due to updates or user navigation, can negatively impact the user experience by slowing down application performance.</p><p>A full page reload forces the browser to re-download all page assets (HTML, CSS, JavaScript, images, etc.), which increases load times, even though only the differences need to be updated.</p><h3>Introducing Live Navigation</h3><p>Live navigation can be triggered from:</p><h4>i. The Client Side</h4><p>To enable live navigation from the client side, use the <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.Component.html#link/1">Phoenix.Component.link/1</a>. This component generates a link that redirects to a specified route. You should define it with either the patch or navigate attribute passed as an assign.</p><pre>&lt;.link patch={~p&quot;/demo_one?page_name=demo_one&quot;}&gt;&lt;/.link&gt;<br><br>&lt;.link navigate ={~p&quot;/demo_one&quot;}&gt;&lt;/.link&gt;&lt;/.link&gt;</pre><h4>ii. The Server Side</h4><p>To trigger live navigation from the server side, LiveView provides two functions:</p><ul><li><a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#push_patch/2">Phoenix.LiveView.push_patch/2</a> — for navigating within the current LiveView</li><li><a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#push_navigate/2">Phoenix.LiveView.push_navigate/2</a> — for navigating to another LiveView within the same session</li></ul><pre>{:noreply, push_patch(socket, to: ~p&quot;/demo_one?page_name=demo_one&quot;)}<br><br>{:noreply, push_navigate(socket, to: ~p&quot;/demo_two&quot;)}</pre><h4>When to use Patch or Navigate</h4><p>Use <strong>patch</strong> when you want to maintain the current LiveView with the given path, without mounting a new LiveView.</p><p>A common example is pagination. When a user moves from one page to another, there’s no need to mount a new LiveView for each page. Instead, you can reuse the same LiveView and update only the necessary parts (the <strong>diff</strong>) based on the current parameters received from the URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0V4D9gejb1haAU0zx241qQ.png" /></figure><p>When patch is used, the <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#c:handle_params/3">handle_params/3</a> callback must be implemented. This callback is triggered when either &lt;.link patch={...}&gt; or push_patch/2 is used.</p><p>The handle_params/3 function takes three arguments:</p><p>1. Request parameters</p><p>2. Uri</p><p>3. Socket</p><p>It returns {:noreply, socket} . This is where an update can be performed based on the URL changes and update the socket for diff rendering.</p><p>Use <strong>navigate</strong> when you want to move to a new LiveView. In this case, the current LiveView is dismounted, and a new one is mounted. Navigation only works between LiveViews that are part of the same <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.Router.html#live_session/3">live_session</a>— a group of live routes declared under the same <strong>live_session</strong> in your router.</p><p>When navigating to another LiveView within the same session, the new LiveView is mounted without reloading the entire browser page; only the content of the LiveView is loaded on the page.</p><h4>Working with Live Navigation vs the Tradition Browser Navigation</h4><p>Let’s build a sample feature to demonstrate how live navigation works.</p><p>In this demonstration, we’ll explore the following scenarios:</p><ol><li>Implementing live navigation on both the client and server sides using patch and navigate.</li><li>Using traditional browser navigation via the href attribute or redirect/2.</li><li>Navigating to another LiveView using patch, or across live sessions using navigate.</li></ol><p>We’ll add different buttons on a LiveView page to showcase each use case.</p><p><strong>Let’s begin!</strong></p><p>First, create a new LiveView application:</p><pre>mix phx.new sample_live --live</pre><p><strong>Note:</strong> You can also use an existing LiveView application if you have one.<br>The mix phx.new command with the --live flag will generate a new application with LiveView installed and configured.</p><p>Next, let’s define live paths for the different use cases in the router.</p><pre>scope &quot;/&quot;, SampleLiveWeb do<br>  pipe_through(:browser)<br><br>   live_session :demo do<br>     live &quot;/demo_one&quot;, DemoOneLive<br>     live &quot;/demo_two&quot;, DemoTwoLive<br>   end<br>   <br>   live_session :another_demo do<br>     live &quot;/demo_three&quot;, DemoThreeLive<br>   end<br>   <br>   live &quot;/demo_four&quot;, DemoFourLive<br>end</pre><p>To define a live route, the <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.Router.html#live/4">live/4</a> macro is used, where the path and the LiveView module are specified. The <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.Router.html#live_session/3">live_session/3</a> defined within the group of <strong>live</strong> routes allows support for navigate redirects.</p><p>Each live_session is given a different name because reusing the same name will result in a runtime error — LiveView will interpret it as an attempt to override or redefine an existing live_session.</p><p>Inside the sample_live_web folder in your LiveView application, there is a live directory, which we’ll use to add the LiveViews defined in the router.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*CD24XAmwrYHZ0KmCUn_CCg.png" /></figure><p>Lets define each Live View file</p><pre>#lib/sample_live_web/live/demo_one_live.ex<br><br>defmodule SampleLiveWeb.DemoOneLive do<br>  use EventHubWeb, :live_view<br><br>  def mount(_params, _session, socket) do<br>    {:ok, socket}<br>  end<br><br>  def render(assigns) do<br>    ~H&quot;&quot;&quot;<br>    &lt;div class=&quot;flex flex-col gap-4&quot;&gt;<br>      &lt;h1&gt;Demo Client Side Navigation&lt;/h1&gt;<br>      &lt;.link<br>        patch={~p&quot;/demo_one?page_name=demo_one&quot;}<br>        class=&quot;rounded-md w-full mt-6 bg-cyan-600 py-2 px-4 border border-transparent text-center text-sm text-white transition-all shadow-md hover:shadow-lg focus:bg-cyan-700 focus:shadow-none active:bg-cyan-700 hover:bg-cyan-700 active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none&quot;<br>      &gt;<br>        Display Page Name<br>      &lt;/.link&gt;<br>      &lt;.link<br>        navigate={~p&quot;/demo_two&quot;}<br>        class=&quot;rounded-md w-full mt-6 bg-cyan-600 py-2 px-4 border border-transparent text-center text-sm text-white transition-all shadow-md hover:shadow-lg focus:bg-cyan-700 focus:shadow-none active:bg-cyan-700 hover:bg-cyan-700 active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none&quot;<br>      &gt;<br>        Navigate to Demo Two<br>      &lt;/.link&gt;<br>      &lt;.link<br>        href={~p&quot;/demo_two&quot;}<br>        class=&quot;rounded-md w-full mt-6 bg-cyan-600 py-2 px-4 border border-transparent text-center text-sm text-white transition-all shadow-md hover:shadow-lg focus:bg-cyan-700 focus:shadow-none active:bg-cyan-700 hover:bg-cyan-700 active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none&quot;<br>      &gt;<br>        Navigate to Demo Two with href<br>      &lt;/.link&gt;<br><br>      &lt;h1&gt;Demo Server Side Navigation&lt;/h1&gt;<br>      &lt;.link<br>        patch={~p&quot;/demo_one?action=patch&quot;}<br>        class=&quot;rounded-md w-full mt-6 bg-cyan-600 py-2 px-4 border border-transparent text-center text-sm text-white transition-all shadow-md hover:shadow-lg focus:bg-cyan-700 focus:shadow-none active:bg-cyan-700 hover:bg-cyan-700 active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none&quot;<br>      &gt;<br>        Patch From the Server Side<br>      &lt;/.link&gt;<br>      &lt;.link<br>        patch={~p&quot;/demo_one?action=navigate&quot;}<br>        class=&quot;rounded-md w-full mt-6 bg-cyan-600 py-2 px-4 border border-transparent text-center text-sm text-white transition-all shadow-md hover:shadow-lg focus:bg-cyan-700 focus:shadow-none active:bg-cyan-700 hover:bg-cyan-700 active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none&quot;<br>      &gt;<br>        Navigate From the Server Side<br>      &lt;/.link&gt;<br>      &lt;.link<br>        patch={~p&quot;/demo_one?action=redirect&quot;}<br>        class=&quot;rounded-md w-full mt-6 bg-cyan-600 py-2 px-4 border border-transparent text-center text-sm text-white transition-all shadow-md hover:shadow-lg focus:bg-cyan-700 focus:shadow-none active:bg-cyan-700 hover:bg-cyan-700 active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none&quot;<br>      &gt;<br>        Redirect From the Server Side<br>      &lt;/.link&gt;<br>    &lt;/div&gt;<br>    &quot;&quot;&quot;<br>  end<br>end</pre><p>We’ve made some changes within the DemoOneLive LiveView by defining the <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#c:mount/3">mount/3</a> and <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#c:render/1">render/1</a> callbacks. The render/1 function renders the HTML template defined inside the ~H sigil.</p><p>For more details on how mount/3 and render/1 work, check out the <a href="https://medium.com/@traceyonim22/understanding-liveview-lifecycle-mount-handle-params-render-and-reconnects-bf0e28910aee">blog</a>.</p><p>When you start the server using mix phx.server and navigate to the /demo_one page, you’ll see something like this in the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lQBES5edhP81Jm36ahOW2Q.png" /></figure><p>As you can see, there are links added on the client side that will trigger navigation based on the attribute passed to the link/3 component. There are also links for the server side, which will be used to demonstrate server-side navigation.</p><p>The changes in DemoOneLive are not yet complete, but let’s add a few changes so we can test navigation from the client side first. We need to implement the handle_params/3 callback, which will be invoked when patch is used. Additionally, we need to define the render/1 and mount/3 callbacks in the other LiveViews.</p><pre>#lib/sample_live_web/live/demo_one_live.ex<br><br>defmodule EventHubWeb.DemoOneLive do<br>  use EventHubWeb, :live_view<br><br>  def mount(_params, _session, socket) do<br>    {:ok, assign(socket, page_name: nil)}<br>  end<br><br>  def render(assigns) do<br>    ~H&quot;&quot;&quot;<br>    &lt;%= if @page_name do %&gt;<br>      &lt;h1&gt;Page Name: {@page_name}&lt;/h1&gt;<br>    &lt;% else %&gt;<br>      &lt;div class=&quot;flex flex-col gap-4&quot;&gt;<br>        &lt;h1&gt;Demo Client Side Navigation&lt;/h1&gt;<br>        &lt;.link<br>          patch={~p&quot;/demo_one?page_name=demo_one&quot;}<br>          class=&quot;rounded-md w-full mt-6 bg-cyan-600 py-2 px-4 border border-transparent text-center text-sm text-white transition-all shadow-md hover:shadow-lg focus:bg-cyan-700 focus:shadow-none active:bg-cyan-700 hover:bg-cyan-700 active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none&quot;<br>        &gt;<br>          Display Page Name<br>        &lt;/.link&gt;<br>        &lt;.link<br>          navigate={~p&quot;/demo_two&quot;}<br>          class=&quot;rounded-md w-full mt-6 bg-cyan-600 py-2 px-4 border border-transparent text-center text-sm text-white transition-all shadow-md hover:shadow-lg focus:bg-cyan-700 focus:shadow-none active:bg-cyan-700 hover:bg-cyan-700 active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none&quot;<br>        &gt;<br>          Navigate to Demo Two<br>        &lt;/.link&gt;<br>        &lt;.link<br>          href={~p&quot;/demo_two&quot;}<br>          class=&quot;rounded-md w-full mt-6 bg-cyan-600 py-2 px-4 border border-transparent text-center text-sm text-white transition-all shadow-md hover:shadow-lg focus:bg-cyan-700 focus:shadow-none active:bg-cyan-700 hover:bg-cyan-700 active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none&quot;<br>        &gt;<br>          Navigate to Demo Two with href<br>        &lt;/.link&gt;<br><br>        &lt;h1&gt;Demo Server Side Navigation&lt;/h1&gt;<br>        &lt;.link<br>          patch={~p&quot;/demo_one?action=patch&quot;}<br>          class=&quot;rounded-md w-full mt-6 bg-cyan-600 py-2 px-4 border border-transparent text-center text-sm text-white transition-all shadow-md hover:shadow-lg focus:bg-cyan-700 focus:shadow-none active:bg-cyan-700 hover:bg-cyan-700 active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none&quot;<br>        &gt;<br>          Patch From the Server Side<br>        &lt;/.link&gt;<br>        &lt;.link<br>          patch={~p&quot;/demo_one?action=navigate&quot;}<br>          class=&quot;rounded-md w-full mt-6 bg-cyan-600 py-2 px-4 border border-transparent text-center text-sm text-white transition-all shadow-md hover:shadow-lg focus:bg-cyan-700 focus:shadow-none active:bg-cyan-700 hover:bg-cyan-700 active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none&quot;<br>        &gt;<br>          Navigate From the Server Side<br>        &lt;/.link&gt;<br>        &lt;.link<br>          patch={~p&quot;/demo_one?action=redirect&quot;}<br>          class=&quot;rounded-md w-full mt-6 bg-cyan-600 py-2 px-4 border border-transparent text-center text-sm text-white transition-all shadow-md hover:shadow-lg focus:bg-cyan-700 focus:shadow-none active:bg-cyan-700 hover:bg-cyan-700 active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none&quot;<br>        &gt;<br>          Redirect From the Server Side<br>        &lt;/.link&gt;<br>      &lt;/div&gt;<br>    &lt;% end %&gt;<br>    &quot;&quot;&quot;<br>  end<br><br>  def handle_params(%{&quot;page_name&quot; =&gt; page_name}, _url, socket) do<br>    {:noreply, assign(socket, page_name: page_name)}<br>  end<br><br>  def handle_params(_params, _url, socket) do<br>    {:noreply, socket}<br>  end<br>end</pre><p>page_name has been added as an assign in the mount/3 callback of DemoOneLive. This assign holds the value passed to it when the state is updated via the handle_params/3 callback, which is triggered when the page name is patched from the client side. The value is then displayed on the page.</p><p>We have defined two versions of handle_params/3. This is because, when no query parameters are patched to the URL during LiveView mounting, handle_params/3 is still invoked — but since no parameters are expected in that case, it matches the second clause.</p><pre>#other liveview page<br># replace * with the actual name, for example DemoTwoLive, DemoThreeLive, DemoFourLive<br>defmodule EventHubWeb.Demo* do<br>  use EventHubWeb, :live_view<br><br>  def mount(_params, _session, socket) do<br>    {:ok, socket}<br>  end<br><br>  def render(assigns) do<br>    ~H&quot;&quot;&quot;<br>    &lt;div&gt;<br>      &lt;h1&gt;Demo * LiveView Page&lt;/h1&gt;<br>    &lt;/div&gt;<br>    &quot;&quot;&quot;<br>  end<br>end</pre><h4>Let’s Begin Testing on the Client Side</h4><p>When you navigate to the /demo_one route, an HTTP GET request is made, establishing a server connection. The LiveView is then mounted. During this connection process, you may also notice additional requests made to load assets (CSS and JavaScript). At this point, a full page reload occurs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NIGGGasBpuwEofPJFT983g.png" /></figure><h4>i. Patch</h4><p>On the /demo_one page, click the <strong>Display Page Name</strong> button. This triggers a patch on the current LiveView (DemoOneLive) using the path passed to the patch attribute:<br> &lt;.link patch={~p&quot;/demo_one?page_name=demo_one&quot;}&gt;.</p><p>In the logs, you’ll see that handle_params/3 is invoked with the given parameters on the current LiveView. Notice that <strong>no additional HTTP request</strong> is made.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uancPYiXm5mjmvEJur3J0w.png" /></figure><h4>ii. Navigate</h4><p>Click the <strong>Navigate to Demo Two</strong> button. This takes you to another LiveView page (DemoTwoLive). Just like with the patch, you’ll observe that <strong>no additional HTTP request</strong> is made, only the new LiveView (DemoTwoLive) is mounted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ECqw-TTtEFBXP80Wl46pTw.png" /></figure><h4>iii. Redirect with href</h4><p>When you click the <strong>Navigate to Demo Two with href</strong> button, it behaves like the initial navigation to /demo_one. An HTTP GET request to /demo_two is made, a new server connection is established, and DemoTwoLive is then mounted — resulting in a <strong>full page reload</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2tM0LxvpStpGHxyQ8Z6hkw.png" /></figure><h4>Triggering Navigation from the Server Side</h4><p>Now let’s modify DemoOneLive to support server-triggered navigation.</p><p>On the client side, we’ve added three links using the patch attribute. Each button links to the same LiveView (DemoOneLive) but includes a different query param (action) that determines what kind of navigation should be triggered from the server.<br> <br>When the query param action is:</p><ul><li>patch → use push_patch/2 to trigger patch navigation</li><li>navigate → use push_navigate/2 to navigate to another LiveView</li><li>redirect → use redirect/2 for a full page reload</li></ul><p>This navigation logic is handled inside the handle_params/3 callback, since the links are patching to the current LiveView.</p><p>We can now proceed to modify DemoOneLive accordingly.</p><pre>#lib/sample_live_web/live/demo_one_live.ex<br><br>defmodule EventHubWeb.DemoOneLive do<br>  use EventHubWeb, :live_view<br><br>  def mount(_params, _session, socket) do<br>    {:ok, assign(socket, page_name: nil)}<br>  end<br><br>  def render(assigns) do<br>    ~H&quot;&quot;&quot;<br>    &lt;%= if @page_name do %&gt;<br>      &lt;h1&gt;Page Name: {@page_name}&lt;/h1&gt;<br>    &lt;% else %&gt;<br>      &lt;div class=&quot;flex flex-col gap-4&quot;&gt;<br>        &lt;h1&gt;Demo Client Side Navigation&lt;/h1&gt;<br>        &lt;.link<br>          patch={~p&quot;/demo_one?page_name=demo_one&quot;}<br>          class=&quot;rounded-md w-full mt-6 bg-cyan-600 py-2 px-4 border border-transparent text-center text-sm text-white transition-all shadow-md hover:shadow-lg focus:bg-cyan-700 focus:shadow-none active:bg-cyan-700 hover:bg-cyan-700 active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none&quot;<br>        &gt;<br>          Display Page Name<br>        &lt;/.link&gt;<br>        &lt;.link<br>          navigate={~p&quot;/demo_two&quot;}<br>          class=&quot;rounded-md w-full mt-6 bg-cyan-600 py-2 px-4 border border-transparent text-center text-sm text-white transition-all shadow-md hover:shadow-lg focus:bg-cyan-700 focus:shadow-none active:bg-cyan-700 hover:bg-cyan-700 active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none&quot;<br>        &gt;<br>          Navigate to Demo Two<br>        &lt;/.link&gt;<br>        &lt;.link<br>          href={~p&quot;/demo_two&quot;}<br>          class=&quot;rounded-md w-full mt-6 bg-cyan-600 py-2 px-4 border border-transparent text-center text-sm text-white transition-all shadow-md hover:shadow-lg focus:bg-cyan-700 focus:shadow-none active:bg-cyan-700 hover:bg-cyan-700 active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none&quot;<br>        &gt;<br>          Navigate to Demo Two with href<br>        &lt;/.link&gt;<br><br>        &lt;h1&gt;Demo Server Side Navigation&lt;/h1&gt;<br>        &lt;.link<br>          patch={~p&quot;/demo_one?action=patch&quot;}<br>          class=&quot;rounded-md w-full mt-6 bg-cyan-600 py-2 px-4 border border-transparent text-center text-sm text-white transition-all shadow-md hover:shadow-lg focus:bg-cyan-700 focus:shadow-none active:bg-cyan-700 hover:bg-cyan-700 active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none&quot;<br>        &gt;<br>          Patch From the Server Side<br>        &lt;/.link&gt;<br>        &lt;.link<br>          patch={~p&quot;/demo_one?action=navigate&quot;}<br>          class=&quot;rounded-md w-full mt-6 bg-cyan-600 py-2 px-4 border border-transparent text-center text-sm text-white transition-all shadow-md hover:shadow-lg focus:bg-cyan-700 focus:shadow-none active:bg-cyan-700 hover:bg-cyan-700 active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none&quot;<br>        &gt;<br>          Navigate From the Server Side<br>        &lt;/.link&gt;<br>        &lt;.link<br>          patch={~p&quot;/demo_one?action=redirect&quot;}<br>          class=&quot;rounded-md w-full mt-6 bg-cyan-600 py-2 px-4 border border-transparent text-center text-sm text-white transition-all shadow-md hover:shadow-lg focus:bg-cyan-700 focus:shadow-none active:bg-cyan-700 hover:bg-cyan-700 active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none&quot;<br>        &gt;<br>          Redirect From the Server Side<br>        &lt;/.link&gt;<br>      &lt;/div&gt;<br>    &lt;% end %&gt;<br>    &quot;&quot;&quot;<br>  end<br><br>  def handle_params(%{&quot;page_name&quot; =&gt; page_name}, _url, socket) do<br>    {:noreply, assign(socket, page_name: page_name)}<br>  end<br><br>  def handle_params(%{&quot;page_name&quot; =&gt; page_name}, _url, socket) do<br>    {:noreply, assign(socket, page_name: page_name)}<br>  end<br><br>  def handle_params(%{&quot;action&quot; =&gt; &quot;patch&quot;}, _url, socket) do<br>    {:noreply, push_patch(socket, to: ~p&quot;/demo_one?page_name=demo_one&quot;)}<br>  end<br><br>  def handle_params(%{&quot;action&quot; =&gt; &quot;navigate&quot;}, _url, socket) do<br>    {:noreply, push_navigate(socket, to: ~p&quot;/demo_two&quot;)}<br>  end<br><br>  def handle_params(%{&quot;action&quot; =&gt; &quot;redirect&quot;}, _url, socket) do<br>    {:noreply, redirect(socket, to: ~p&quot;/demo_two&quot;)}<br>  end<br><br>  def handle_params(_params, _url, socket) do<br>    {:noreply, socket}<br>  end<br>end</pre><p>When you navigate to the /demo_one page and click on the server-side links, you’ll see that the logs for server-side navigation are similar to those from the client side.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qvdBu8e8rcwXFKvs-Ltgqw.png" /></figure><p>If you attempt to patch to another LiveView or navigate to a LiveView in a different <strong>live session</strong>, it will behave like a traditional browser redirect — just as it would with the href attribute or redirect/2. This will <strong>trigger a full page reload</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VfEkbGzIYUUIN8cfldpxyg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9_td98a9lp9ptQUurcFRxQ.png" /></figure><h4>Wrap up</h4><p>In this post, we introduced <a href="https://hexdocs.pm/phoenix_live_view/live-navigation.html"><strong>live navigation</strong></a>, a feature in <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html">Phoenix LiveView</a> that optimizes page navigation without requiring a full page reload.</p><p>We also explained how live navigation can be triggered using patch and navigate on the <strong>client side</strong>, and with push_patch/2 and push_navigate/2 on the <strong>server side</strong>, including when to use each approach.</p><p>Finally, we demonstrated how <a href="https://hexdocs.pm/phoenix_live_view/live-navigation.html"><strong>live navigation</strong></a> compares to <strong>traditional browser navigation</strong>.</p><p>By leveraging Live Navigation, you can deliver a faster and smoother user experience while reducing unnecessary page reloads.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=107ef13e5d7a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create Cards With Reusable Function Components]]></title>
            <link>https://medium.com/@traceyonim22/create-cards-with-reusable-function-components-7c0fc9e42193?source=rss-80af953d809a------2</link>
            <guid isPermaLink="false">https://medium.com/p/7c0fc9e42193</guid>
            <category><![CDATA[phoenix]]></category>
            <category><![CDATA[phoenix-liveview]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[components]]></category>
            <dc:creator><![CDATA[Tracey Onim]]></dc:creator>
            <pubDate>Thu, 29 May 2025 06:24:52 GMT</pubDate>
            <atom:updated>2025-05-29T06:24:52.079Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever found yourself duplicating <strong>HTML templates</strong> or working on an application with repeated templates throughout? If you pay attention, you may notice that these duplicated templates have been rewritten due to minor differences, such as the content within the template or specific attributes like classes, while the overall structure and tags remain the same.</p><p>Duplicating code can lead to significant headaches when it comes to maintenance. Imagine an update being implemented; you would need to perform the same maintenance in all areas where the code is duplicated.</p><p>In this post, we’ll explore how to avoid that by creating reusable function components — saving time, reducing bugs, and keeping your codebase clean.</p><h3>Prerequisites</h3><p>This blog assumes you are already familiar with <strong>Phoenix LiveView</strong> and how it handles rendering using <strong>HEEx templates</strong>. <br>If you’re new to these concepts, consider reviewing the <a href="https://hexdocs.pm/phoenix_live_view">Phoenix LiveView documentation</a> before continuing.</p><h4>What is a Function Component?</h4><p>In LiveView, the Phoenix.Component module lets you define <strong>reusable function components</strong> using HEEx templates—a templating language that combines HTML with Elixir code through interpolation.</p><pre>&lt;p&gt; Hello {@name} &lt;/p&gt;</pre><p>In this snippet, &lt;p&gt; is an HTML tag, and {@name} uses Elixir interpolation({…}) to access a key from the assigns map. Interpolation like this allows you to insert dynamic values or Elixir expressions directly into your HTML or attributes.</p><p>A <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.Component.html"><strong>function component</strong></a> is simply,<em> any function that receives an assign map as an argument and returns a rendered struct built with the ~H sigil.</em></p><p>Let’s look at a basic example:</p><pre>#lib/my_app_web/custom_components.ex<br><br>defmodule MyAppWeb.CustomComponent do<br> use Phoenix.Component<br><br> def card(assign) do<br>  ~H &quot;&quot;&quot;<br>    &lt;h1&gt; Building reusable cards !!! &lt;/h1&gt;<br>    &quot;&quot;&quot;<br> end<br>end</pre><p>In this example, we define a card/1 function component. The use Phoenix.Component line brings in all the necessary macros and functions to make this work. The function name can be anything, as long as it takes in an assign and returns a rendered template built with the ~H sigil.</p><p>To render this component, you simply call it inside another ~H sigil—whether from another component or from a LiveView&#39;s render/1 callback:</p><pre>#lib/my_app_web/live/card_live.ex<br><br>defmodule MyAPPWeb.Live.CardLive do<br> import MyAppWeb.CustomComponent<br><br><br>  def mount(params, session, socket) do<br>     {:ok, socket}<br>   end<br><br>  def render(assigns) do<br>   ~H &quot;&quot;&quot;<br>     &lt;.card/&gt;<br>     &quot;&quot;&quot;<br>  end<br>end</pre><p>Alternatively, you can also render it from a .heex template:</p><pre><br><br>&lt;!-- lib/my_app_web/live/card_live.html.heex --&gt;<br><br> &lt;. card /&gt;</pre><p>When you inspect the browser, you’ll see the following HTML rendered;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zzuU962xGM9_az-jrwKx4g.png" /></figure><h4>Use Case: Create Reusable Card With Images Using Function Components</h4><p>Let’s look at a practical use case for function components. Suppose you want to display <strong>three cards</strong>, all sharing the same layout but with <strong>different titles, descriptions, and background colors</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WRafKg0lSnhpnZGTMg1vKg.png" /></figure><p>Here’s how the HTML looks <strong>without</strong> a function component:</p><pre>&lt;!-- lib/my_app_web/live/card_live.html.heex --&gt;<br><br>&lt;div class=&quot;grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-5&quot;&gt;<br>  &lt;div class=&quot;max-w-sm bg-white border border-gray-200 rounded-lg shadow-sm dark:bg-gray-800 dark:border-gray-700&quot;&gt;<br>    &lt;div&gt;<br>      &lt;img class=&quot;rounded-t-lg&quot; src=&quot;/images/logo.svg&quot; alt=&quot;&quot; /&gt;<br>    &lt;/div&gt;<br>    &lt;div class=&quot;p-5&quot;&gt;<br>      &lt;h5 class=&quot;mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white&quot;&gt;<br>        Silver<br>      &lt;/h5&gt;<br>      &lt;p class=&quot;mb-3 font-normal text-gray-700 dark:text-gray-400&quot;&gt;<br>        This is a Silver card<br>      &lt;/p&gt;<br>      &lt;a<br>        href=&quot;#&quot;<br>        class=&quot;inline-flex items-center px-3 py-2 text-sm font-medium text-center text-white bg-blue-700 rounded-lg hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800&quot;<br>      &gt;<br>        Read more<br>        &lt;svg<br>          class=&quot;rtl:rotate-180 w-3.5 h-3.5 ms-2&quot;<br>          aria-hidden=&quot;true&quot;<br>          xmlns=&quot;http://www.w3.org/2000/svg&quot;<br>          fill=&quot;none&quot;<br>          viewBox=&quot;0 0 14 10&quot;<br>        &gt;<br>          &lt;path<br>            stroke=&quot;currentColor&quot;<br>            stroke-linecap=&quot;round&quot;<br>            stroke-linejoin=&quot;round&quot;<br>            stroke-width=&quot;2&quot;<br>            d=&quot;M1 5h12m0 0L9 1m4 4L9 9&quot;<br>          /&gt;<br>        &lt;/svg&gt;<br>      &lt;/a&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br><br>  &lt;div class=&quot;max-w-sm bg-lime-800 border border-gray-200 rounded-lg shadow-sm dark:bg-gray-800 dark:border-gray-700&quot;&gt;<br>    &lt;div&gt;<br>      &lt;img class=&quot;rounded-t-lg&quot; src=&quot;/images/logo.svg&quot; alt=&quot;&quot; /&gt;<br>    &lt;/div&gt;<br>    &lt;div class=&quot;p-5&quot;&gt;<br>      &lt;h5 class=&quot;mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white&quot;&gt;<br>        Bronze<br>      &lt;/h5&gt;<br>      &lt;p class=&quot;mb-3 font-normal text-gray-700 dark:text-gray-400&quot;&gt;<br>        This is a Bronze card<br>      &lt;/p&gt;<br>      &lt;a<br>        href=&quot;#&quot;<br>        class=&quot;inline-flex items-center px-3 py-2 text-sm font-medium text-center text-white bg-blue-700 rounded-lg hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800&quot;<br>      &gt;<br>        Read more<br>        &lt;svg<br>          class=&quot;rtl:rotate-180 w-3.5 h-3.5 ms-2&quot;<br>          aria-hidden=&quot;true&quot;<br>          xmlns=&quot;http://www.w3.org/2000/svg&quot;<br>          fill=&quot;none&quot;<br>          viewBox=&quot;0 0 14 10&quot;<br>        &gt;<br>          &lt;path<br>            stroke=&quot;currentColor&quot;<br>            stroke-linecap=&quot;round&quot;<br>            stroke-linejoin=&quot;round&quot;<br>            stroke-width=&quot;2&quot;<br>            d=&quot;M1 5h12m0 0L9 1m4 4L9 9&quot;<br>          /&gt;<br>        &lt;/svg&gt;<br>      &lt;/a&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br><br>  &lt;div class=&quot;max-w-sm bg-amber-500 border border-gray-200 rounded-lg shadow-sm dark:bg-gray-800 dark:border-gray-700&quot;&gt;<br>    &lt;div&gt;<br>      &lt;img class=&quot;rounded-t-lg&quot; src=&quot;/images/logo.svg&quot; alt=&quot;&quot; /&gt;<br>    &lt;/div&gt;<br>    &lt;div class=&quot;p-5&quot;&gt;<br>      &lt;h5 class=&quot;mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white&quot;&gt;<br>        Gold<br>      &lt;/h5&gt;<br>      &lt;p class=&quot;mb-3 font-normal text-gray-700 dark:text-gray-400&quot;&gt;<br>        This is a Gold card<br>      &lt;/p&gt;<br>      &lt;a<br>        href=&quot;#&quot;<br>        class=&quot;inline-flex items-center px-3 py-2 text-sm font-medium text-center text-white bg-blue-700 rounded-lg hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800&quot;<br>      &gt;<br>        Read more<br>        &lt;svg<br>          class=&quot;rtl:rotate-180 w-3.5 h-3.5 ms-2&quot;<br>          aria-hidden=&quot;true&quot;<br>          xmlns=&quot;http://www.w3.org/2000/svg&quot;<br>          fill=&quot;none&quot;<br>          viewBox=&quot;0 0 14 10&quot;<br>        &gt;<br>          &lt;path<br>            stroke=&quot;currentColor&quot;<br>            stroke-linecap=&quot;round&quot;<br>            stroke-linejoin=&quot;round&quot;<br>            stroke-width=&quot;2&quot;<br>            d=&quot;M1 5h12m0 0L9 1m4 4L9 9&quot;<br>          /&gt;<br>        &lt;/svg&gt;<br>      &lt;/a&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/div&gt;</pre><p>As you can see, only a few things differ between the cards: the <strong>title</strong>, <strong>description</strong>, and <strong>background color</strong>.</p><p>Let’s improve this by creating a <strong>function component</strong> called card_with_image/1` that we can reuse for each card. This component will receive the dynamic parts of each card from the assigns and render a consistent layout.</p><pre>#lib/my_app_web/custom_components.ex<br><br>defmodule MyAppWeb.CustomComponent do<br> use Phoenix.Component<br><br>  attr :title, :string, required: true<br>  attr :description, :string, required: true<br>  attr :image, :string, required: true<br><br>  attr :rest, :global<br><br> def card_with_image(assigns) do<br>    ~H&quot;&quot;&quot;<br>    &lt;div {@rest}&gt;<br>      &lt;div&gt;<br>        &lt;img class=&quot;rounded-t-lg&quot; src={@image} alt=&quot;&quot; /&gt;<br>      &lt;/div&gt;<br>      &lt;div class=&quot;p-5&quot;&gt;<br>        &lt;h5 class=&quot;mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white&quot;&gt;<br>          {@title}<br>        &lt;/h5&gt;<br>        &lt;p class=&quot;mb-3 font-normal text-gray-700 dark:text-gray-400&quot;&gt;<br>          {@description}<br>        &lt;/p&gt;<br>        &lt;a<br>          href=&quot;#&quot;<br>          class=&quot;inline-flex items-center px-3 py-2 text-sm font-medium text-center text-white bg-blue-700 rounded-lg hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800&quot;<br>        &gt;<br>          Read more<br>          &lt;svg<br>            class=&quot;rtl:rotate-180 w-3.5 h-3.5 ms-2&quot;<br>            aria-hidden=&quot;true&quot;<br>            xmlns=&quot;http://www.w3.org/2000/svg&quot;<br>            fill=&quot;none&quot;<br>            viewBox=&quot;0 0 14 10&quot;<br>          &gt;<br>            &lt;path<br>              stroke=&quot;currentColor&quot;<br>              stroke-linecap=&quot;round&quot;<br>              stroke-linejoin=&quot;round&quot;<br>              stroke-width=&quot;2&quot;<br>              d=&quot;M1 5h12m0 0L9 1m4 4L9 9&quot;<br>            /&gt;<br>          &lt;/svg&gt;<br>        &lt;/a&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>    &quot;&quot;&quot;<br>  end<br>end</pre><p>Our function naming is very specific. We want a card with an image added to it. You can enforce some rules within your function component regarding the attributes expected to be received when invoked. This is done by using the <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.Component.html#attr/3">attr/3</a> macro provided by<a href="https://hexdocs.pm/phoenix_live_view/Phoenix.Component.html"> Phoenix.Component</a>.</p><p>In our card_with_imagecomponent, we can declare that the image, description, and titleare required.</p><pre>  attr :title, :string, required: true<br>  attr :description, :string, required: true<br>  attr :image, :string, required: true</pre><p>By declaring image, description, and title as required attributes, when invoking card_with_image, the attributes must be present in the assigns for proper rendering; otherwise, it will result in a compilation error.</p><pre>&lt;MyAppWeb.CustomComponent.card_with_image /&gt;<br>  &lt;!-- warning: missing required attribute &quot;title&quot; for component MyAppWeb.CustomComponent.card_with_image/1<br>           lib/my_app_web/custom_components.ex:10 --&gt;</pre><p>In the function component, we are now interpolating {@image},{@title}, and {@description}. This means we are dynamically retrieving the values for each card</p><p>Additionally, the three cards had different background colors; this can still be achieved by declaring an attribute of type <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.Component.html#module-global-attributes">global</a>. These are a set of attributes, such as class attributes and phx-* bindings, common to all standard HTML tags. See <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes">Global attributes</a>.</p><pre>attr :rest, :global</pre><p>By passing a class attribute through the @rest (global attributes), we allow each card to have a unique background color without modifying the component itself.</p><p>Now you can use the component like this:</p><pre>&lt;!-- lib/my_app_web/live/card_live.html.heex --&gt;<br><br>&lt;.card_with_image <br>  image=&quot;/images/bronze.png&quot;<br>  title=&quot;Bronze&quot;<br>  description=&quot;This is a Bronze card.&quot;<br>  class=&quot;max-w-sm bg-white border border-gray-200 rounded-lg shadow-sm dark:bg-gray-800 dark:border-gray-700&quot;<br>&gt;<br> &lt;/.card_with_image&gt;<br><br>&lt;.card_with_image <br>  image=&quot;/images/silver.png&quot;<br>  title=&quot;Silver&quot;<br>  description=&quot;This is a Silver card.&quot;<br>  class=&quot;max-w-sm bg-lime-800 border border-gray-200 rounded-lg shadow-sm dark:bg-gray-800 dark:border-gray-700&quot;<br>&gt;<br> &lt;/.card_with_image&gt;<br><br>&lt;.card_with_image <br>  image=&quot;/images/gold.png&quot;<br>  title=&quot;Gold&quot;<br>  description=&quot;This is a Gold card.&quot;<br>  class=&quot;max-w-sm bg-amber-500 border border-gray-200 rounded-lg shadow-sm dark:bg-gray-800 dark:border-gray-700&quot;<br>&gt;<br>&lt;/.card_with_image&gt;</pre><h3>Wrapping UP</h3><p><strong>Function components</strong> are a powerful way to improve code organization and maintain a clean, reusable design structure in your Phoenix LiveView applications. You can use it to create reusable functions with <strong>HEEx templates</strong> and avoid duplication.</p><p>In this post, we introduced the concept of <strong>function components</strong>, explored how they work, and walked through a practical use case — creating reusable <strong>cards with images</strong>. We also demonstrated how to enforce required attributes using attr/3 and how to support additional customization through global attributes like class.</p><p>To dive deeper, check out the official <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.Component.html#content">Phoenix.Component documentation</a>.</p><p>Happy Coding !!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c0fc9e42193" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tech Events Highlight: Code Beam America 2025]]></title>
            <link>https://medium.com/@traceyonim22/tech-events-highlight-code-beam-america-2025-f702eea6a7d6?source=rss-80af953d809a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f702eea6a7d6</guid>
            <category><![CDATA[elixirlang]]></category>
            <category><![CDATA[code-beam-america-2025]]></category>
            <category><![CDATA[tech-events]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[community]]></category>
            <dc:creator><![CDATA[Tracey Onim]]></dc:creator>
            <pubDate>Fri, 28 Mar 2025 09:01:57 GMT</pubDate>
            <atom:updated>2025-03-28T09:01:57.369Z</atom:updated>
            <content:encoded><![CDATA[<p>Attending<a href="https://codebeamamerica.com/"> <strong>Code Beam America 2025</strong></a> was a privilege! This two-day event was packed with <strong>learning</strong>, <strong>inspiration</strong>, and <strong>networking</strong> opportunities. Although I joined virtually, the experience was nothing short of amazing.</p><p>In this blog, I’ll share key takeaways from the event — insights that stood out to me.</p><h3>How I Found Out About the Event</h3><p>I first learned about <strong>Code Beam America 2025</strong> through <strong>X</strong> (formerly Twitter). In January, I received a notification from their official page (<a href="https://x.com/CodeBEAMio">@CodeBEAMio</a>), which led me to sign up for their waiting list in hopes of securing an early bird ticket.</p><h3>What I was looking for</h3><p>My primary goal was to <strong>connect</strong> with other Beamers. Even before reviewing the program, I knew these gatherings offer a chance to engage with like-minded professionals, exchange ideas, and learn. The opportunity to connect with the community is invaluable. Reading testimonials and insights from previous attendees only reinforced my excitement — why miss out on the chance to be part of it?</p><p>In addition to networking, I was eager to gain valuable insights that I could apply to my career and work. I’m grateful to say that this event exceeded my expectations; it was an enriching experience from start to finish.</p><h3>My Experience Attending Virtually</h3><p>The virtual experience was smooth and well-organized. Three days before the event, I received a detailed email from Code Beam with instructions on how to prepare, including access details and a help center for any issues.</p><p>One of the highlights was the <a href="https://codebeamamerica.com/birdsofafeather/"><strong>Birds of a Feather</strong></a><strong> — Roundtable Discussion</strong>, where attendees could submit topics for open discussions. This was a great opportunity for engagement and knowledge sharing, making the virtual experience feel interactive and inclusive.</p><h3>KeyTake Aways</h3><p>Here are the key insights I gathered from the talks I attended at <strong>Code Beam America 2025</strong>:</p><h3>1. Opening Keynote: Designing LLM-Native Systems</h3><p>When integrating <strong>Large Language Models (LLMs)</strong> into our workflows, they should enhance productivity rather than hinder cognitive thinking. In this session, <a href="https://www.linkedin.com/in/sean-m-ba231a149/"><strong>Sean Moriarity</strong></a> explored three key aspects of LLM : <strong>Organization , Workflow, and Products.</strong></p><p>His talk resonated deeply, especially regarding how organizations adopt <strong>AI assistant tools</strong>. As software engineers, many of us already use <strong>AI-generated code tools</strong>, but they come with challenges. Some of the key concerns he raised included:</p><ul><li><strong>Offloading critical thinking</strong> to AI, leading to a decline in problem-solving skills.</li><li><strong>Accepting complex changes</strong> suggested by AI without fully understanding them.</li><li><strong>Potentially stunting professional growth</strong> by relying too heavily on AI-generated solutions.</li></ul><p>But does this mean we should stop using AI altogether? Not necessarily. Instead, he emphasized using AI responsibly by adopting these best practices:</p><ol><li><strong>Collaborative AI Use</strong> — Walk your team through your thought process when solving a problem, and if you’re using AI, share the prompts you used.</li><li><strong>Transparency in AI-Assisted Workflows</strong> — Encourage a culture where everyone shares their AI-generated prompts and chat history when proposing code changes.</li><li><strong>Active Learning</strong> — Instead of blindly accepting AI-generated solutions, take the time to write out the code manually and ensure you fully understand the logic behind it.</li></ol><h3>2. Elixir Updates</h3><p>The presentation on Elixir updates was conducted by <a href="https://x.com/emjii"><strong>Eric Meadows-Jönsson</strong></a><strong>. </strong>One of the key takeaways from the event was learning about <strong>Elixir’s release cadence</strong> — a new version is released <strong>every six months</strong>. I hadn’t realized this before, and it was insightful to see how structured Elixir’s updates are.</p><p>The latest release, <strong>Elixir v1.18</strong>, launched in <strong>December 2024</strong>, bringing several exciting features:</p><ul><li><strong>Type checks calls and patterns</strong></li><li><strong>ExUnit groups and parameters</strong></li><li><strong>mix format --migrate</strong></li><li><strong>JSON support</strong></li></ul><p>A major highlight of the session was the <strong>Elixir type system</strong>, which piqued my interest. It’s something I plan to explore further.</p><p>Some recommended resources on the <strong>Elixir type system</strong>:</p><p><strong>i. Official Documentation:</strong> <a href="https://hexdocs.pm/elixir/main/gradual-set-theoretic-types.html">Gradual Set-Theoretic Types in Elixir</a><br><strong>ii. </strong><a href="https://arxiv.org/pdf/2306.06391">The Design Principles of the Elixir Type System</a></p><h3>3. Live Voices with LiveView</h3><p>Ever wondered how <strong>real-time transcription</strong> works or how tools like <strong>Google Translate</strong> process speech? This talk by <a href="https://www.linkedin.com/in/lawik/"><strong>Lars Wikman</strong></a> explored exactly that.</p><p>I’ll admit — when I first saw the title, I thought <strong>LiveView</strong> had an AI-powered voice feature integrated!</p><p>But as the talk unfolded, I discovered an exciting intersection of <strong>machine learning, media processing, and LiveView.</strong></p><p>To make the <a href="https://github.com/lawik/relive">demo</a> work, the setup combined:</p><ul><li><strong>Machine Learning</strong></li><li><strong>Membrane Media Framework</strong> (an Elixir-based media framework)</li><li><strong>LiveView</strong> for UI updates</li></ul><h4>Key Models Used</h4><p>Lars walked us through several models that powered the system:</p><ul><li><strong>SmolLM2</strong></li><li><strong>Whisper</strong> — speech to text model</li><li><strong>Kokoro</strong> — text to speech</li><li><strong>Silero-VAD</strong> — useful for voice activity detection</li></ul><p>These models were run using:</p><ul><li><strong>NX</strong> — Elixir’s numerical computing library</li><li><strong>Ortex</strong> &amp; <strong>ONNX</strong> — For running optimized ML models</li></ul><p>This talk sparked my curiosity to explore <strong>Membrane Framework</strong> and the possibilities of integrating machine learning in the Elixir application.</p><h3>4. The Detective Hat: Investigating Production Issues</h3><p>If you’re part of a <strong>technical support team</strong> or ever find yourself debugging <strong>production issues</strong>, this talk by <a href="https://www.linkedin.com/in/jennybramble/"><strong>Jeny Bramble</strong></a><strong> and </strong><a href="https://www.linkedin.com/in/adriandunston/"><strong>Adrian Dunston</strong></a> was packed with valuable insights.</p><p>One quote that stood out to me was:<br> <strong>“Scars build seniors.”</strong><br> It’s a powerful reminder that incidents are learning opportunities, and the best engineers grow through hands-on problem-solving.</p><h4>The 5 Laws of Debugging Production Issues</h4><p>Here are five key principles I took away from this talk:</p><ol><li><strong>All production issues are a failure of process</strong> — Instead of blaming individuals, focus on improving systems and workflows.</li><li><strong>Believe the problem is real until proven otherwise</strong> — Assume validity first.</li><li><strong>Write things down as you go</strong> — Document everything:<br>- The problem<br>- Potential causes<br>- Complications involved<br>- Unanswered questions<br>- What might become tomorrow’s problem</li><li><strong>Communicate the status as you go</strong> — Keep stakeholders informed and explain how the issue was fixed with clear, factual evidence.</li><li><strong>Learn something from every incident</strong> — Every issue should lead to improvements, whether in monitoring, documentation, or process refinement.</li></ol><p>One of the highlights of this session was how <strong>Jeny and Adrian</strong> delivered a <strong>theatrical and engaging</strong> presentation. It was a great reminder that even technical talks can be <strong>fun, dynamic, and memorable</strong>!</p><h3>5. Bring Back the Power of BEAM Deployments with DeployEx</h3><p>In this talk, <a href="https://www.linkedin.com/in/thiago-cesar-calori-esteves-972368115/"><strong>Thiago Cesar</strong></a> introduced <a href="https://github.com/thiagoesteves/deployex"><strong>DeployEx</strong></a>, an Erlang library designed to manage and handle BEAM deployments. The session challenged conventional container-based deployment strategies, making me rethink the best way to deploy Elixir applications.</p><h4>Challenges of Containerization with Beam Applications mentioned</h4><p>1. <strong>Network Topology :</strong></p><ul><li><strong>Elixir applications</strong> rely heavily on <strong>Erlang’s built-in distribution capabilities</strong>, which enable seamless node-to-node communication.</li><li>Deploying <strong>Elixir on AWS Kubernetes </strong>creates networking challenges, requiring extra tooling like <strong>libcluster</strong> for node discovery, adding complexity.</li></ul><p>2. <strong>Hot Code Reloading:</strong></p><ul><li>One of <strong>BEAM’s core advantages</strong> is <strong>hot code reloading</strong>, allowing systems to upgrade without downtime.</li><li>However, modern containerized deployments (which rely on stateless containers) completely discard this feature.</li><li>This means every deployment requires a restart instead of taking advantage of BEAM’s built-in ability .</li></ul><p>A thought-provoking question raised during the talk was:</p><blockquote>Cloud providers like Amazon RDS, Amazon Redis, and AWS Secrets Manager do not containerize their services, so why are you providing containers for your clients?</blockquote><p>This raises an important discussion about whether containerization is truly the best solution — or if we’re losing efficiency and performance.</p><p><strong>DeployEx</strong> aims to <strong>bring back a deployment strategy tailored to BEAM’s strengths</strong>, making it a <strong>tool worth exploring</strong> for teams looking to get the most out of their Beam deployments.</p><h3>6. Choosing an effective testing structure</h3><p>Writing tests can be challenging — you might end up with <strong>flaky tests, inefficient coverage, or misleading results</strong>. Speaker <a href="https://www.linkedin.com/in/jasonaxelson/">Jason Axelson</a> shared his opinion on choosing an effective structure.</p><ol><li>When writing test<br><strong>i. Write tests to fail first</strong> —This approach ensures you write tests that fail with useful failure messages, clearly indicating where errors originate.<br><strong>ii. Use async tests</strong> — Running tests asynchronously ensures faster test suite execution<br><strong>iii. Verify your tests by changing the code</strong> — Apply <strong>mutation testing</strong> to confirm that your tests actually catch failures.<br><strong>iv. Avoid depending on factory values</strong> — can make tests to be undeterministic.<br><strong>v. Follow the Given/When/Then approach</strong> — Structuring tests this way improves readability .</li><li>Useful Libraries for Running Tests<br><strong>i. mix test.watch</strong> (<a href="https://github.com/lpil/mix-test.watch">GitHub</a>) — Automatically reruns tests when source code changes.<br><strong>ii. ExUnitSpan</strong> (<a href="https://github.com/ananthakumaran/ex_unit_span">GitHub</a>) — Visualizes test execution and provides a trace to analyze test concurrency.<br><strong>iii. Run tests directly from your editor</strong> — Save time by using <strong>#vscode-elixir-tests extension</strong> instead of manually copying file names and line numbers.</li><li>Common Anti-Patterns to Avoid<br><strong>Avoid meck-based libraries</strong> (e.g., meck, mock, patch, espec) — These libraries replaces modules , making it difficult to debug and track down issues in test suites.</li></ol><p>More test libraries to look out for</p><ul><li>Bypass library <a href="https://hexdocs.pm/bypass/Bypass.html">https://hexdocs.pm/bypass/Bypass.html</a> — allows you to mock an HTTP server and return prebaked response</li><li>ProcessTree library <a href="https://github.com/jbsf2/process-tree">https://github.com/jbsf2/process-tree</a> — a library for avoiding global state in Elixir</li><li>Mneme <a href="https://github.com/zachallaun/mneme">https://github.com/zachallaun/mneme</a> — snapshot testing library that helps write and update your assertions</li><li>Parameterized test <a href="https://hexdocs.pm/parameterized_test/readme.html">https://hexdocs.pm/parameterized_test/readme.html</a> — creates test cases from markdown tables</li></ul><h3>7. Keynote: AI for worker collective Action</h3><p>Extensive research is being conducted to improve various aspects of work. In this talk by <a href="https://www.linkedin.com/in/saiphcita/">Saiph Savage</a>, I gained insights into how AI has been used to transform the working dynamics of gig workers taking into account that not everyone is skilled in prompt engineering, as well as the diverse dynamics and cultural factors at play.</p><h3>8. Battling Memory Leaks: Tales from the Trenches @WhatsApp</h3><p>Memory leaks are a major issue in many applications, and a lack of understanding about how to address them can complicate the problem even further. In her talk, <a href="https://www.linkedin.com/in/miriampena/">Miriam Pena</a> discusses her experiences dealing with memory leaks while working at <a href="https://www.linkedin.com/company/whatsapp./">WhatsApp</a>, a platform that manages high traffic with nearly 2 billion active users.</p><h4>Key Takeaways</h4><ol><li><strong>Understanding BEAM Memory Usage</strong></li></ol><ul><li>The :erlang.memory() function provides insights into how memory is allocated in a BEAM system.</li><li><strong>Instrumentation</strong> is crucial—tools like <strong>Telemetry</strong> help track memory usage over time.</li></ul><p><strong>2. Detecting and Debugging Memory Leaks</strong></p><ul><li>Use an <strong>external process</strong> to monitor memory consumption before the kernel intervenes and terminates your application due to an Out-of-Memory (OOM) situation. You can proactively terminate the beam process to generate a crash dump.</li><li><strong>crash dumps</strong> provide valuable data for troubleshooting memory leaks.</li><li>This technique works well for ETS (Erlang Term Storage) memory, but troubleshooting binary and process memory can be more challenging. To address these, you can opt for garbage collection.</li></ul><p><strong>3. Preventing Out-of-Memory (OOM) Techniques</strong></p><ul><li>Limit maximum heap sizes</li><li>Aggressive garbage collection .</li><li>Remove a service from the load balancer or throttle requests when approaching an OOM scenario.</li></ul><p>Pro-Tips</p><ul><li>Add metrics of how much your memory allocators are using.</li><li>When beam allocators cause trouble try JEMAlloc</li><li>Become a crash dump expert</li></ul><p>This talk definitely a must-watch for anyone working with <strong>high-traffic Elixir/Erlang systems</strong>!</p><p>Resource to look out for:</p><ul><li><a href="https://github.com/happi/theBeamBook">https://github.com/happi/theBeamBook</a></li><li><a href="https://s3.us-east-2.amazonaws.com/ferd.erlang-in-anger/text.v1.1.0.pdf">https://s3.us-east-2.amazonaws.com/ferd.erlang-in-anger/text.v1.1.0.pdf</a></li></ul><p>There were many insightful talks at Code BEAM America 2025, and I couldn’t attend them all. However, I’ve shared <strong>key takeaways</strong> from the sessions that resonated most with me.</p><p>The good news? Recordings will be released publicly!<strong> </strong>Keep an eye on the <a href="https://www.youtube.com/c/CodeSync"><strong>Code Sync YouTube channel</strong></a> to catch up on all the amazing talks.</p><h3>Conclusion: Why You Should Look Forward to BEAM Events</h3><p>Attending <strong>Code BEAM America 2025</strong> was a fantastic experience, and if you’re in the <strong>Elixir/Erlang community</strong>, I highly recommend looking forward to such events. Here’s why:</p><ol><li><strong>Growth Opportunity</strong> — Whether you’re a beginner or an experienced developer, there’s always something new to learn.</li><li><strong>Deep Technical Knowledge</strong> — Get insights from experts on cutting-edge topics.</li><li><strong>Learn from Other Companies</strong> — See how different companies are adopting BEAM technologies, solving real-world challenges, and scaling their applications.</li><li><strong>Inspiring Stories</strong> — It’s not just about tech; it’s about people<strong>, </strong>connections, and legacy. One story that stood out to me was how <a href="https://www.linkedin.com/in/francescocesarini/"><strong>Francesco Cesarini</strong> </a>first noticed <a href="https://www.linkedin.com/in/chelseatroy/"><strong>Chelsea Troy</strong></a> at the <strong>Code Mesh virtual conference</strong> — not just for her talk, but because she was <strong>the only speaker presenting while standing</strong> instead of sitting. Small things can make a big impression!</li><li><strong>Honoring the Legacy of BEAM Pioneers</strong> — The contributions of legends like <strong>Joe Armstrong</strong> continue to shape the future. These events keep that spirit alive and inspire the next generation.</li><li><strong>Career &amp; Hiring Opportunities</strong> — Many companies use these events to connect with talent. If you’re looking for new opportunities, these conferences can be a great way to network and discover hiring companies.</li><li><strong>Connect and Grow Your Network — </strong>Expand Your Network and Grow Together — this is the strength of community. Events like these offer more than just technical discussions — they provide an opportunity to connect, learn, and grow.</li></ol><p><strong>Final Thoughts</strong><br> Code BEAM is more than just a conference — it’s a <strong>gathering of passionate engineers, problem solvers, and innovators</strong>. Whether you attend virtually or in person, the <strong>learning, networking, and inspiration</strong> you gain are truly invaluable.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f702eea6a7d6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding LiveView LifeCycle: Mount, Handle Params, Render, and Reconnects.]]></title>
            <link>https://medium.com/@traceyonim22/understanding-liveview-lifecycle-mount-handle-params-render-and-reconnects-bf0e28910aee?source=rss-80af953d809a------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf0e28910aee</guid>
            <category><![CDATA[liveview]]></category>
            <category><![CDATA[phoenix]]></category>
            <category><![CDATA[phoenix-liveview]]></category>
            <category><![CDATA[lifecycle]]></category>
            <category><![CDATA[elixir]]></category>
            <dc:creator><![CDATA[Tracey Onim]]></dc:creator>
            <pubDate>Sat, 01 Mar 2025 06:11:10 GMT</pubDate>
            <atom:updated>2025-03-01T06:43:09.671Z</atom:updated>
            <content:encoded><![CDATA[<h4>Introduction</h4><p><a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#content">Phoenix LiveView</a> simplifies real-time web application development by handling UI updates efficiently over WebSockets. However, understanding its lifecycle is crucial to building resilient applications. Let’s explore how LiveView handles connections, URL changes, rendering, and process crashes.</p><h4>The Initial Connection</h4><p><em>You begin by rendering a LiveView typically from your router. When LiveView is first rendered, the </em><a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#c:mount/3"><em>mount/3</em></a><em> callback is invoked with the current params, the current session and the LiveView socket.</em></p><p>When a liveview process is started the <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#c:mount/3">mount/3</a> callback is invoked. This happens only once per connection. At this point, the state is initialized and socket assigns are wired up with data necessary for rendering.</p><pre>def mount(_params, _session, socket) do<br> {:ok, socket}<br>end</pre><h3>Handling URI and Query Params with handle_params/3</h3><p>After mounting <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#c:handle_params/3">handle_params/3</a> is invoked to handle the URI and query parameters. This function allows LiveView to update state based on URL changes without requiring a full re-mount.</p><pre> def handle_params(_params, _uri, socket) do<br>   {:noreply, socket}<br> end</pre><h3>Rendering with render/1</h3><p>The <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#c:render/1">render/1</a> function is finally invoked to generate the HTML output, which is pushed to the client as a standard HTML response.</p><pre>def render(assigns) do<br> ~H&quot;&quot;&quot;<br>   Hello World!<br>  &quot;&quot;&quot;<br>end</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5fsGxVWD2fhdlyrR8oBzgw.png" /><figcaption>Spin up server</figcaption></figure><h4>What Happens When LiveView Crashes?</h4><p>Crashes can occur due to errors, process termination, or unexpected failures when a LiveView process crashes. The Phoenix socket automatically attempts to reconnect. It gracefully reconnects by calling <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#c:mount/3">mount/3</a> and <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#c:handle_params/3">handle_params/3</a> again.</p><h4>Conclusion</h4><p>Understanding the <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#module-life-cycle">lifecycle of a LiveView</a> is essential. To recap, we have covered what happens from the moment you begin rendering a LiveView from the router, leading to <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#c:mount/3">mount/3</a>, <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#c:handle_params/3">handle_params/3</a>, and <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#c:render/1">render/1</a> being invoked. It’s important to understand that <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#c:mount/3">mount/3</a> is invoked <strong>once for every live connection</strong>, and if a LiveView process crashes, the client reconnects and re-runs <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#c:mount/3">mount/3</a> and <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#c:handle_params/3">handle_params/3</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf0e28910aee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tech Events Highlight: Her Vision 2025]]></title>
            <link>https://medium.com/@traceyonim22/tech-events-highlight-2025-352f134fd05c?source=rss-80af953d809a------2</link>
            <guid isPermaLink="false">https://medium.com/p/352f134fd05c</guid>
            <category><![CDATA[vision-board]]></category>
            <category><![CDATA[women-in-tech]]></category>
            <category><![CDATA[networking-event]]></category>
            <category><![CDATA[community]]></category>
            <category><![CDATA[tech-events]]></category>
            <dc:creator><![CDATA[Tracey Onim]]></dc:creator>
            <pubDate>Wed, 05 Feb 2025 18:32:13 GMT</pubDate>
            <atom:updated>2025-03-25T13:50:33.880Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XevrizbxZJ2bisYVsBBMUA.png" /></figure><p>This year, I promised myself to be very intentional about attending tech events. There’s something truly special about being part of a thriving, passionate community — where innovation, learning, and networking come together.</p><p>So, why do I love tech community events?</p><ol><li>It’s through these events that talent is easily spotted.</li><li>It’s through these events that you can get the opportunity to showcase your niche. You never know who is watching</li><li>It builds you, empowers you, and helps you learn to grow your network</li></ol><h3>Her Vision 2025 with TechSisterKE</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iGTtnaJund5T1uBnqOuuuA.png" /></figure><p>My first physical event of the year — <strong>Her Vision 2025</strong> — hosted by <a href="https://www.linkedin.com/company/tech-sisters-kenya"><strong>@TechSisterKE</strong></a>, was nothing short of empowering! I had the privilege of connecting and networking with <strong>bold</strong>, <strong>unstoppable</strong>, and <strong>loud</strong> women in tech.</p><h3>Key Takeaways from the Panel Discussion</h3><p>The panelists <a href="https://www.linkedin.com/in/rose-adhiambo-6b4b47159/">Rose Oketch</a> , <a href="https://www.linkedin.com/in/christine-okoth/">Christine Okoth</a>, <a href="https://www.linkedin.com/in/ngaruiyanjeri/">Njeri Ngaruiya</a> and <a href="https://www.linkedin.com/in/loisekimwe/">Loise Kimwe</a> shared invaluable insights on career growth and personal development. Here are some of the standout tips:</p><ol><li><strong>Specialize</strong> — Find your niche and hone your expertise.</li><li><strong>Identify Your Strengths &amp; Weaknesses</strong> — Self-awareness is key to growth.</li><li><strong>Acquire the Right Skills</strong> — Learn what’s necessary when you plan to branch out.</li><li><strong>Be Open-Minded</strong> — Embrace new opportunities and career shifts.</li><li><strong>Build Your Experience</strong> — Be intentional about gaining hands-on knowledge.</li><li><strong>Let Your Niche Be Known</strong> — Visibility opens doors!</li><li><strong>Look for a Mentor</strong> — Guidance from the right people accelerates growth.</li></ol><h4>Turning an Idea into a Product? Here’s Some Tips!</h4><p>If you’re thinking about bringing your vision to life, keep these in mind:</p><ol><li><strong>Think of the 3 Ds</strong> — <strong>Design, Development, Deployment.</strong></li><li><strong>Join Hackathons</strong></li><li><strong>Engage in Entrepreneurial Spaces</strong></li><li><strong>Just Start</strong> — There’s no perfect time. Begin where you are!</li></ol><h3>Vision Board Creation with Zahra Njoki</h3><p>The <strong>Vision Board creation</strong> session by<a href="https://www.linkedin.com/in/zahra-njoki-64328326b/"> Zahra Njoki</a> was a standout moment. We were challenged to write down <strong>20 things</strong> we aim to achieve, then narrow them down to just <strong>5</strong>. This exercise helped us gain clarity and focus on what truly matters.</p><p>To <strong>actualize your vision</strong>, keep these factors in mind:</p><p>🔹 <strong>Gratitude</strong> — Appreciate where you are and what you have.<br>🔹 <strong>Intention(Why)</strong> — Be clear about what you want to achieve.<br>🔹 <strong>Master the ‘How’</strong> — Develop the right skills:</p><ul><li>Positive self-talk</li><li>Self-awareness</li><li>Emotional intelligence</li><li>Non-violent communication</li><li>Identifying opportunities</li><li>Forming consistent habits</li><li>Journaling for reflection</li></ul><p>🔹 <strong>Gratitude</strong> <strong>(Again!)</strong> — It’s that important!</p><h4>Structuring Your Vision Board</h4><p>To make your vision board, section it into these categories:</p><ul><li>Personal Development</li><li>Career</li><li>Financial</li><li>Health</li><li>Leisure</li><li>Creativity</li><li>Relationships</li></ul><h3>My Biggest Takeaways</h3><p>🔹 As much as you receive from the community, <strong>always find ways to give back</strong>. — A powerful reminder from <a href="https://www.linkedin.com/in/valeriabosibori/">Valeria BosiBori</a>, co-founder <a href="https://www.linkedin.com/company/tech-sisters-kenya"><strong>@TechSisterKE</strong></a>.</p><p>🔹 <strong>Opportunities are everywhere</strong> — you just need to look for them. Another great advice from <a href="https://www.linkedin.com/in/jusu/">Philip Bob Jusu</a></p><p>Opportunities presented at the event :<br> 1. Masterclass in Entrepreneurship by <a href="https://www.linkedin.com/company/builditcommunity">BuildIT Connective</a></p><p>2. Scholarship by <a href="https://www.linkedin.com/school/moringa-school">Moringa School</a></p><p>These opportunities are just a glimpse of what’s possible when you stay engaged with the tech community.</p><h3>Final Thoughts</h3><p>A huge thank you to <a href="https://www.linkedin.com/company/tech-sisters-kenya"><strong>@TechSisterKE</strong></a><strong> </strong>and everyone who made <strong>Her Vision 2025</strong> an impactful experience. The energy, knowledge-sharing, and support in the room were unmatched! Looking forward to many more events like this.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=352f134fd05c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to group a set of values using the Postgresql ARRAY_AGG() function in Ecto Query]]></title>
            <link>https://medium.com/@traceyonim22/how-to-group-a-set-of-values-using-the-postgresql-array-agg-function-in-ecto-query-17b1a27d6b0d?source=rss-80af953d809a------2</link>
            <guid isPermaLink="false">https://medium.com/p/17b1a27d6b0d</guid>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[enum]]></category>
            <category><![CDATA[ecto]]></category>
            <category><![CDATA[query]]></category>
            <dc:creator><![CDATA[Tracey Onim]]></dc:creator>
            <pubDate>Fri, 26 Jul 2024 06:20:04 GMT</pubDate>
            <atom:updated>2024-07-26T06:20:04.013Z</atom:updated>
            <content:encoded><![CDATA[<p>Today, I learned a new function in PostgreSQL called <a href="https://www.postgresql.org/docs/9.5/functions-aggregate.html">array_agg()</a>.</p><h3>Prerequisite:</h3><p>This blog assumes you&#39;re already familiar with working with <a href="https://hexdocs.pm/ecto/Ecto.html#module-query">Ecto Query</a> in Elixir.</p><h4>What I wanted:</h4><p>To obtain a list of data grouped by a specific column.</p><p>Let’s say we have a table for movies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*EPYKhWz-Kbtk32vZR2TtDg.png" /></figure><p>From this table, I want to create a list of movies grouped by their release date to identify movies released on the same date.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*65kcsGYfun7Nd-QsfsZlcg.png" /></figure><h4>1st Solution: The Greedy Approach</h4><pre><br>def movies_grouped_by_released_date do<br>  query = <br>    from m in Movie,<br>    select: {m.released_date, m.title}<br><br>  query<br>  |&gt; Repo.all()<br>  |&gt; Enum.group_by(fn {released_date, _title} -&gt; released_date end)<br>end<br><br><br>   </pre><p>Expected output;</p><pre>iex &gt; movies_grouped_by_released_date()<br><br>      %{2022-07-15 =&gt; <br>            [{2022-07-15, &quot;Click click bang&quot;}, {2022-07-15, &quot;Country Queen&quot;}, {2022-07-15, &quot;Disconnect&quot;}], <br>        <br>        2022-08-14 =&gt; <br>            [{2022-08-14, &quot;Just in Time&quot;}, {2022-08-14, &quot;Morning After&quot;}],<br><br>       2023-08-10 =&gt;<br>            [{2023-08-10, &quot;Uradi&quot;}],<br>        <br>       2023-07-17 =&gt;<br>           [{2023-07-17, &quot;Mvera&quot;}],<br><br>       2024-04-01 =&gt;<br>           [{2024-04-01, &quot;Volume&quot;}]<br>            <br>       }</pre><p>We should be mindful of the potential cost associated with using Enum, especially when dealing with large datasets.</p><p>This is because:<br>1. When data is fetched from the database, it is stored in memory and must be available for the next step in the pipeline to begin processing.<br>2. Subsequently, Enum.group_by/3 processes the data and allocates the output in the memory.</p><p>This method leads to unnecessary memory consumption.</p><h4>Best Approach: Using Postgresql function array_agg() with the group_by/3 query expression</h4><p>The same result above can be achieved by using the PostgreSQL array_agg()function with the<a href="https://hexdocs.pm/ecto/Ecto.Query.html#group_by/3"> group_by/3</a> query expression in the Ecto query.</p><pre>def movies_grouped_by_released_date do<br>  query = <br>    from m in Movie,<br>    group_by: m.released_date,<br>    select: {m.released_date, fragment(&quot;array_agg(?)&quot;, m.title)}<br><br>  <br>  Repo.all(query)<br>  <br>end</pre><h4>Wrapping Up</h4><p>I came across this solution on the <a href="https://elixirforum.com/t/how-to-apply-sql-array-aggregation-function-in-ecto/29649">Elixir Forum</a></p><p>Happy Coding !!!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17b1a27d6b0d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Broadcasting vs sending message from component to parent liveview]]></title>
            <link>https://medium.com/@traceyonim22/broadcasting-vs-sending-message-from-component-to-parent-liveview-8a4e24971971?source=rss-80af953d809a------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a4e24971971</guid>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[phoenix-liveview]]></category>
            <category><![CDATA[pub-sub]]></category>
            <category><![CDATA[broadcast]]></category>
            <category><![CDATA[liveview]]></category>
            <dc:creator><![CDATA[Tracey Onim]]></dc:creator>
            <pubDate>Sun, 26 Jun 2022 13:18:05 GMT</pubDate>
            <atom:updated>2022-06-26T13:18:05.392Z</atom:updated>
            <content:encoded><![CDATA[<p>When adding a feature in your application there are definetly some edge cases that should be put into consideration depending with the purpose of your application.</p><p>Imagine you are creating an application for planning weekly task among people in your house or even at work station.When users visit that page, they should be able to see their task and even task assigned to other people. And if any user make a change to the task or even add a task , other users visiting that page should be able to see the changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1et4AWvLQAIo-X9zMDNQWA.jpeg" /></figure><p>In this blog, I want to demonstrate a scenario where pubsub might be a better option for broadcasting updates instead of sending messages.</p><h4>prerequisite</h4><p>I’ll assume you already know <a href="https://hexdocs.pm/phoenix_live_view/0.17.7">Phoenix.LiveView</a> and <a href="https://hexdocs.pm/phoenix_live_view/0.17.7/Phoenix.LiveComponent.html#summary">Phoenix.LiveComponent</a></p><h4>Roadmap</h4><ol><li>Create a parent LiveView page that will be our board.</li><li>Define a LiveComponent that will act as the card for adding tasks.</li></ol><h4>1. Creating Parent LiveView</h4><p>Let’s go ahead and add the following:</p><pre><em>defmodule MyAppWeb.BoardLive do<br>  use MyAppWeb, :live_view<br>  alias MyAppWeb.CardComponent</em></pre><pre><em>def mount(_params, _session, socket) do<br>  cards = [<br>      %{title: &quot;department1&quot;, tasks: [&quot;deploy to production&quot;], id: 1},<br>      %{title: &quot;department2&quot;, tasks: [&quot;code challenge&quot;], id: 2},<br>      %{title: &quot;department3&quot;, tasks: [&quot;plan community events&quot;], id: 3}<br>    ]</em></pre><pre><em>   {:ok, assign(socket, cards: cards)}<br>  end</em></pre><pre><em>def render(assigns) do<br>    ~H&quot;&quot;&quot;<br>    &lt;%= for card &lt;- </em><a href="http://twitter.com/cards"><em>@cards</em></a><em> do%&gt;<br>    &lt;.live_component module={CardComponent} card={card} id={card.id} /&gt;<br>    &lt;% end %&gt;<br>    &quot;&quot;&quot;<br>  end</em></pre><p>Here I have created a simple board LiveView page that renders each card component.</p><h4>2. Define Card Component</h4><p>We are going to create a stateful component that will be responsible for handling its own events.</p><pre><em>defmodule MyAppWeb.CardComponent do<br>  use MyAppWeb, :live_component</em></pre><pre><em>def render(assigns) do<br>    ~H&quot;&quot;&quot;<br>    &lt;div&gt;<br>    &lt;label&gt;&lt;%= </em><a href="http://twitter.com/card"><em>@card</em></a><em>.title%&gt;&lt;/label&gt;<br>    &lt;%=for task &lt;- </em><a href="http://twitter.com/card"><em>@card</em></a><em>.tasks do%&gt;<br>    &lt;br&gt;<br>     &lt;%= task %&gt;<br>     &lt;% end %&gt;<br>     &lt;.form let={f} for={:task} phx-submit=&quot;Add task&quot; phx-target={</em><a href="http://twitter.com/myself"><em>@myself</em></a><em>}&gt;<br>     &lt;%= textarea f, :task %&gt;<br>     &lt;button&gt;Add task&lt;/button&gt;<br>     &lt;/.form&gt;<br>     <br>    &lt;/div&gt;<br>    &quot;&quot;&quot;<br>  end<br>end</em></pre><p>Since we are handling the add task event inside the component, I’ll annotate the form with phx-target and assign it with @myself which is the internal reference to the component instance.</p><pre><em>%{<br>  __changed__: %{},<br>  card: %{id: 1, tasks: [&quot;deploy to production&quot;], title: &quot;day1&quot;},<br>  flash: %{},<br>  id: 1,<br>  myself: %Phoenix.LiveComponent.CID{cid: 1}<br>}</em></pre><p>Upto to this point, when you open your browser you will see something similar to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FSfzNyVcXO41Zzlpf1nJMQ.png" /><figcaption>Board with cards</figcaption></figure><h4>3. Sending card Updates</h4><p>Let’s handle the add task event. We shall update the card by adding a task to it and then send the updated card to the parent LiveView(Board) as a message.</p><p>The component and the LiveView runs in the same process that means we can be able to retrieve the PID of the current process by invoking self() and send a message from LiveComponent(CardComponent) to the parent LiveView(BoardLive).</p><pre><em>def handle_event(&quot;Add task&quot;, %{&quot;task&quot; =&gt; %{&quot;task&quot; =&gt; task}}, socket) do<br>    send(<br>      self(),<br>      {:updated_card, %{socket.assigns.card | tasks: socket.assigns.card.tasks ++ [task]}}<br>    )</em></pre><pre><em>{:noreply, socket}<br>  end</em></pre><p>The parent LiveView needs to handle the event and update the card list.</p><pre><em>def handle_info({:updated_card, updated_card}, socket) do<br>    filtered_cards = Enum.reject(socket.assigns.cards, fn card -&gt; card.id == updated_card.id end)<br>    cards = Enum.sort_by(filtered_cards ++ [updated_card], fn card -&gt; card.id end)<br>    {:noreply, assign(socket, cards: cards)}<br>  e</em>nd</pre><p>At least now we know that the Board LiveView is in sync with the Card Component since we have informed it about the updates.</p><p>What happens when we update a card in the board?Let us see if sending message from card component to the board LiveView is a better option for our case scenario. I will open two browsers firefox and chrome in my case .You can also open different tabs if opening more than one browser might be troublesome. Different tabs/browsers will act as different users accessing the same page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2D7i2krA7wppGqCtZRPz8Q.gif" /><figcaption>different users accessing the same board</figcaption></figure><p>As you have observed its very clear that whatever user1 has added , user2 cannot see the updates.Likewise, user2 cannot see what user1 has added.This can be conflicting and its contrary in how we want our application to work.</p><h4>4. Publishing Card Updates</h4><p>We can quickly fix this and make it work the way we want by publishing updates. The advantage of using <a href="https://hexdocs.pm/phoenix_pubsub/Phoenix.PubSub.html">PubSub </a>is that updates get distributed to every user who have subscribed to the same topic. For example, lets say we have user1 and user2 connected to the board, if user1 updates department1 card by adding a task, user2 will see those changes. And that is a good thing for our application.</p><p>Replace the initial implementation in our handle_event callback with this:</p><pre><em>def handle_event(&quot;Add task&quot;, %{&quot;task&quot; =&gt; %{&quot;task&quot; =&gt; task}}, socket) do<br>    message = {:updated_card, %{socket.assigns.card | tasks: socket.assigns.card.tasks ++ [task]}}</em></pre><pre><em>Phoenix.PubSub.broadcast(<br>      MyAppWeb.PubSub,<br>      &quot;board:1&quot;,<br>      message<br>    )</em></pre><pre><em>{:noreply, socket}<br>  end</em></pre><p>Our Board(parent LiveView) has to subscribe to the topic for it to receive updates.I have used board:1 as the topic . Invoke the Phoenix.PubSub.subscribe/2 at the mount so that when user visits the board page , they will be subscribed to board:1 topic.</p><pre>def mount(_params, _session, socket) do<br>    Phoenix.PubSub.subscribe(MyAppWeb.PubSub, &quot;board:1&quot;)<br>    .<br>    .<br>    .<br>{:ok, assign(socket, cards: cards)}<br>  end</pre><p>The parent LiveView needs to handle the event and update the card list.Therefore we shall maintain the handle_info callback defined earlier.</p><p>We are done with our implementation , we can now observe what happens this time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6BESPDq7DhKUgEmuYYcccQ.gif" /><figcaption>different users accessing the same board</figcaption></figure><p>Both users can see each others update. This is exactly what we wanted</p><h4>Wrap</h4><p>Whether to use PubSub to broadcast updates or sending messages, purely depends with the end goal of your application.</p><p>I hope you’ll find this post helpful. Happy Coding !!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a4e24971971" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Avoid Re-writing the Same HTML Syntax in Phoenix LiveView]]></title>
            <link>https://medium.com/@traceyonim22/how-to-avoid-re-writing-the-same-html-syntax-in-phoenix-liveview-3e450aa3cb06?source=rss-80af953d809a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e450aa3cb06</guid>
            <category><![CDATA[function-component]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[components-phoenix]]></category>
            <category><![CDATA[phoenix-liveview]]></category>
            <category><![CDATA[slot]]></category>
            <dc:creator><![CDATA[Tracey Onim]]></dc:creator>
            <pubDate>Wed, 08 Jun 2022 21:34:48 GMT</pubDate>
            <atom:updated>2022-06-08T21:34:48.953Z</atom:updated>
            <content:encoded><![CDATA[<p>Sometimes it can be tedious to re-write the same code multiple times in your application unless its for learning purposes. Not only is it tedious, but also makes the module look bulky more so if the implementation is on the same page.</p><p>Let’s make my previous blog of<a href="https://medium.com/@traceyonim22/how-to-create-tabs-in-phoenix-liveview-caf960b7c517"> how to create tabs</a> a bit lively by displaying a list of items in each tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*URD8NrH2--vLWkpZce3hoQ.gif" /></figure><p>I’ll go ahead and modify each function component defined earlier like this:</p><pre><em>def tab_one(assigns) do<br>    ~H&quot;&quot;&quot;<br>    &lt;p id=&quot;one&quot;&gt;Types of fruits&lt;/p&gt;<br>    &lt;ul&gt;<br>    &lt;li&gt;Apple&lt;/li&gt;<br>    &lt;li&gt;Orange&lt;/li&gt;<br>    &lt;li&gt;Kiwi&lt;/li&gt;<br>    &lt;/ul&gt;</em></pre><pre><em>    &quot;&quot;&quot;<br>  end</em></pre><pre><em>def tab_two(assigns) do<br>    ~H&quot;&quot;&quot;<br>    &lt;p id=&quot;two&quot;&gt;Types of veges&lt;/p&gt;<br>     &lt;ul&gt;<br>    &lt;li&gt;Spinach&lt;/li&gt;<br>    &lt;li&gt;Kales&lt;/li&gt;<br>    &lt;li&gt;Cabbage&lt;/li&gt;<br>    &lt;/ul&gt;</em></pre><pre><em>    &quot;&quot;&quot;<br>  end</em></pre><pre><em>def tab_three(assigns) do<br>    ~H&quot;&quot;&quot;<br>    &lt;p id=&quot;three&quot;&gt;Types of drinks&lt;/p&gt;<br>    &lt;ul&gt;<br>    &lt;li&gt;Soda&lt;/li&gt;<br>    &lt;li&gt;Juice&lt;/li&gt;<br>    &lt;li&gt;Water&lt;/li&gt;<br>    &lt;/ul&gt;</em></pre><pre><em>    &quot;&quot;&quot;<br>  end</em></pre><p>I have added a list of items in each tab and I have used similar HTML syntax in each function component. We can avoid rewriting the syntax only to display different type of items by taking advantage of <strong>slots - </strong><em>a mechanism to give HTML blocks to function components as in regular HTML tags</em>.</p><p>Let’s go ahead and restructure our code; I’ll add a function component called unordered_list/1 in <em>SampleWeb.SampleLiv</em>e module which will be responsible for displaying a list of items passed to it.</p><pre>def unordered_list(assigns) do<br>~H&quot;&quot;&quot;<br>&lt;ul&gt;<br>&lt;%= for item &lt;- @items do %&gt;<br>&lt;li&gt;&lt;%= render_slot(@inner_block, item)%&gt;&lt;/li&gt;<br>&lt;% end %&gt;<br>&lt;/ul&gt;</pre><pre>&quot;&quot;&quot;<br>end</pre><p>We shall then invoke undordered_list/1 in tab_one/1 , tab_two/1, tab_three/1 as like this:</p><pre><em>def tab_one(assigns) do<br>    ~H&quot;&quot;&quot;<br>    &lt;p id=&quot;one&quot;&gt;Types of fruits&lt;/p&gt;<br>    &lt;.unordered_list let={item} items={~w(Apple Orange kiwi)}&gt;<br>    #Content to display<br>    &lt;%= item %&gt;<br>    &lt;/.unordered_list&gt;</em></pre><pre><em>&quot;&quot;&quot;<br>  end</em></pre><pre><em>def tab_two(assigns) do<br>    ~H&quot;&quot;&quot;<br>    &lt;p id=&quot;two&quot;&gt;Types of veges&lt;/p&gt;<br>    &lt;.unordered_list let={item} items={~w(Spinach Kales Cabbage)}&gt;<br>   #Content to display <br>   &lt;%= item %&gt;<br>    &lt;/.unordered_list&gt;</em></pre><pre><em>&quot;&quot;&quot;<br>  end</em></pre><pre><em>def tab_three(assigns) do<br>    ~H&quot;&quot;&quot;<br>    &lt;p id=&quot;three&quot;&gt;Types of drinks&lt;/p&gt;<br>     &lt;.unordered_list let={item} items={~w(Soda Juice Water)}&gt;<br>     #Content to display<br>     &lt;%= item %&gt;<br>    &lt;/.unordered_list&gt;</em></pre><pre><em>&quot;&quot;&quot;<br>  end</em></pre><p>As you can see, the unordered_list/1 has easen our work since it contains the HTML syntax that we need to display the items. When invoking it we only need to pass the list of items to be rendered on each tab.</p><p>Inside our unordered_list/1 I have passed the <em>@items</em> assigns which has been added when invoking the function</p><pre><em>&lt;.unordered_list let={item} items={~w(Soda Juice Water)}&gt;</em></pre><p>Secondly, I have used <a href="https://hexdocs.pm/phoenix_live_view/0.17.7/Phoenix.LiveView.Helpers.html#render_slot/2">Phoenix.LiveView.Helpers.render_slot/2</a> which takes in a slot and an optional argument to render the content passed to the component. The first argument is a default slot<em> @inner_block</em> assign which is assigned with the content passed to <em>unordered_list/1</em>. The second argument<em> item</em>, is the content that we are displaying therefore we shall pass it inside unordered_list/1 .</p><h4>Wrap-up</h4><p>In our example, we have seen how we can take advantage of the<a href="https://hexdocs.pm/phoenix_live_view/0.17.7/Phoenix.Component.html#module-slots"> <strong>slot</strong> </a>feature in function components to create reusable functions .</p><p>I hope you’ll find this post helpful. Happy Coding !!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e450aa3cb06" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Create Tabs in Phoenix LiveView]]></title>
            <link>https://medium.com/@traceyonim22/how-to-create-tabs-in-phoenix-liveview-caf960b7c517?source=rss-80af953d809a------2</link>
            <guid isPermaLink="false">https://medium.com/p/caf960b7c517</guid>
            <category><![CDATA[tabs]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[liveview]]></category>
            <category><![CDATA[phoenix-liveview]]></category>
            <dc:creator><![CDATA[Tracey Onim]]></dc:creator>
            <pubDate>Mon, 30 May 2022 15:17:33 GMT</pubDate>
            <atom:updated>2022-05-30T15:17:33.727Z</atom:updated>
            <content:encoded><![CDATA[<p>LiveView has been one of the exciting library that developers can use to make interactive applications without Javascript.</p><p>In this article, I will show you how you can create a tab using LiveView feature <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.JS.html"><strong><em>Phoenix.LiveView.JS</em></strong></a><strong><em> </em></strong><em>.</em> This feature was added in <strong><em>LiveView v0.17.0</em></strong>, <em>it provides commands for executing JS utility operations on the client.</em></p><p>Let’s begin:</p><p>In our template we are going to add the following:</p><pre><em>&lt;a phx-click={JS.show(to: &quot;#one&quot;) |&gt; JS.push(&quot;switch_tab&quot;, value: %{tab: &quot;one&quot;})}&gt;show one&lt;/a&gt;<br>|<br>&lt;a phx-click={JS.show(to: &quot;#two&quot;) |&gt; JS.push(&quot;switch_tab&quot;, value: %{tab: &quot;two&quot;})}&gt;show two&lt;/a&gt;<br>|<br>&lt;a phx-click={JS.show(to: &quot;#three&quot;) |&gt; JS.push(&quot;switch_tab&quot;, value: %{tab: &quot;three&quot;})}&gt;show three&lt;/a&gt;</em></pre><pre><em>&lt;%= if </em><a href="http://twitter.com/tab"><em>@tab</em></a><em> == &quot;one&quot; do %&gt;<br>&lt;.tab_one/&gt;<br>&lt;% end %&gt;<br>&lt;%= if </em><a href="http://twitter.com/tab"><em>@tab</em></a><em> == &quot;two&quot; do %&gt;<br>&lt;.tab_two/&gt;<br>&lt;% end %&gt;<br>&lt;%= if </em><a href="http://twitter.com/tab"><em>@tab</em></a><em> == &quot;three&quot; do %&gt;<br>&lt;.tab_three/&gt;<br>&lt;% end %&gt;</em></pre><p>In the anchor tag, I have used a phx-click binding this is because <em>LiveView bindings support a JS command interface via </em><strong><em>Phoenix.LiveView.JS</em></strong><em> module which allows you to specify utility operations that execute on the client when firing phx-binding events.</em></p><p>Here we want to show the content of each tab when clicked. Therefore we are going to use the<strong><em> JS show </em></strong>and <strong><em>push</em></strong> commands.</p><p>i) show command is used to display the content in each tab</p><p>ii) push command is used to push an event to the server where the socket will be updated so that the user can switch from one tab to another.</p><p>The <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.JS.html#show/1"><strong>show/1</strong></a> passed has one argument which is the <strong>:to</strong> option that points to the DOM containing the content to display. In my case I have specified the DOM ID.</p><p>The <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.JS.html#push/3"><strong>push </strong></a>command has been passed with 3 arguments, that is the piped <strong>js struct</strong> , <strong>event name</strong>(“switch_tab”) and an <strong>option</strong>(<em>:value</em> which specifies the map of values to send to the server).</p><p>In addition, I have added an<strong> if statement</strong> whereby a function component defined in the server will be invoked only if the tab clicked matches.</p><p>Lets go ahead to the server side and implement the following:</p><pre><em>defmodule SampleWeb.SampleLive do<br>  use SampleWeb, :live_view<br>  alias Phoenix.LiveView.JS</em></pre><pre><em>def mount(_params, _session, socket) do<br>    {:ok, assign(socket, tab: &quot;one&quot;)}<br>  end</em></pre><pre><em>def handle_event(&quot;switch_tab&quot;, %{&quot;tab&quot; =&gt; tab}, socket) do<br>    {:noreply, assign(socket, tab: tab)}<br>  end</em></pre><pre><em>def tab_one(assigns) do<br>    ~H&quot;&quot;&quot;<br>    &lt;p id=&quot;one&quot;&gt;tab one displayed&lt;/p&gt;<br>    &quot;&quot;&quot;<br>  end</em></pre><pre><em>def tab_two(assigns) do<br>    ~H&quot;&quot;&quot;<br>    &lt;p id=&quot;two&quot;&gt;tab two displayed&lt;/p&gt;<br>    &quot;&quot;&quot;<br>  end</em></pre><pre><em>def tab_three(assigns) do<br>    ~H&quot;&quot;&quot;<br>    &lt;p id=&quot;three&quot;&gt;tab three displayed&lt;/p&gt;<br>    &quot;&quot;&quot;<br>  end<br>end</em></pre><p>Here I have aliased <strong>Phoenix.LiveView.JS, </strong>so that we can use its functions.</p><p>Notice that in our <strong>mount/3</strong>, I have added a tab assign and give it the value “one” which points to the first tab.This is because, we want tab one to be the default tab whereby, when the user lands on the page they can see the contents inside the tab.</p><p>I have also handled the “switch_tab” event which updates the assign tab with the value of the tab clicked. For example , if tab two is clicked, a push event will be sent to the server with this map value (%{“tab” =&gt; “two”}).</p><p>Inside our server, I have also defined three function components that is <strong><em>tab_one/1</em></strong> , <strong><em>tab_two/1</em></strong> and <strong><em>tab_three/1</em></strong> which contains the content of each tab.</p><p>In the browser you should see something similar to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5uKOemB1wPso3AmAW8uu7A.gif" /></figure><p>Now that you have had a glimpse of what LiveView can do, Ihope you will find this blog helpful and it will guide you in creating complex interactive tabs.</p><p>Happy codding!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=caf960b7c517" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>