<?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 Christian Tovar on Medium]]></title>
        <description><![CDATA[Stories by Christian Tovar on Medium]]></description>
        <link>https://medium.com/@christiantovar?source=rss-1de6f7d35f1f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ho7f66h2LAZX7dXR2lsDOA.jpeg</url>
            <title>Stories by Christian Tovar on Medium</title>
            <link>https://medium.com/@christiantovar?source=rss-1de6f7d35f1f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 10:28:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@christiantovar/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[Improving TechLead’s Big Canvas]]></title>
            <link>https://medium.com/kommit-software-developers/improving-techleads-big-canvas-1fca6806c0ac?source=rss-1de6f7d35f1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fca6806c0ac</guid>
            <category><![CDATA[phoenix-framework]]></category>
            <category><![CDATA[liveview]]></category>
            <category><![CDATA[html-canvas]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[pub-sub]]></category>
            <dc:creator><![CDATA[Christian Tovar]]></dc:creator>
            <pubDate>Wed, 24 Feb 2021 20:18:01 GMT</pubDate>
            <atom:updated>2021-02-26T16:40:04.873Z</atom:updated>
            <content:encoded><![CDATA[<h4>From LAMP stack to Phoenix + LiveView</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7wx6mvkUCFTP6RMC" /><figcaption>Photo by <a href="https://unsplash.com/@steve_j?utm_source=medium&amp;utm_medium=referral">Steve Johnson</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>A few days ago I saw a <a href="https://www.youtube.com/watch?v=t1aXuJkmTg8">Youtube video from the TechLead</a> (former ex-Google, ex-Facebook engineer) where he developed a full web application for drawing on HTML canvases. This application is called <strong>Big Canvas</strong>, and it resembles something like the <a href="http://www.milliondollarhomepage.com/">million-dollar website</a>. In the sense that users are able to draw on a canvas grid, but without any overwriting restrictions. As I saw the video, I understood the fun/educational purposes of it. However, there were several aspects where I felt that the application lacked and was not able to fully deliver. So, following that same educational pattern, let me show how I developed a <strong>Better Big Canvas</strong> and improved the original Big Canvas by rebuilding it from scratch with <a href="https://dockyard.com/blog/2018/12/12/phoenix-liveview-interactive-real-time-apps-no-need-to-write-javascript">Phoenix LiveView</a> and <a href="https://hexdocs.pm/phoenix_pubsub/Phoenix.PubSub.html">PubSub</a>.</p><p>In case you are not aware yet, <a href="https://www.phoenixframework.org/">Phoenix</a> is a web framework written in <a href="https://elixir-lang.org/">Elixir</a> for building scalable and performant applications that provide real-time communication, via web sockets. On the other hand, <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html">Phoenix LiveView</a> is a server-side rendering library that enables rich, real-time user experiences.</p><p>The aspects I’ll be addressing are the following, which I consider can be either improved or that were not fully delivered at all:</p><ol><li><em>Modularity</em></li><li><em>Soft Real-Time</em></li></ol><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F12458983&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fgonna-be-great-lets-do-it-encourage-inviting-motivate-cheer-gif-12458983&amp;image=https%3A%2F%2Fmedia.tenor.com%2Fimages%2Fbf08dbdfbbd4432b9556ac19172b639b%2Ftenor.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/67ca2e0ee0c773e60bc249c09de1436c/href">https://medium.com/media/67ca2e0ee0c773e60bc249c09de1436c/href</a></iframe><h4>Modularity</h4><p>The original Big Canvas was developed using primarily PHP and JavaScript (obviously), plus some Python for gluing up the persistence of the pixels from the canvas. Following that same 2-page design, I decomposed the app into 2 main interfaces. One for the main grid, which is the one that offers a preview of every individual canvas and, another one, for each of the several canvases where the users will draw.</p><p>There was not any framework at all involved in the development of the original Big Canvas, which is fine. However, I believe a better app can be achieved with the Phoenix Framework (in case you haven’t noticed before, that’s where the “better” actually comes from in <strong>Better Big Canvas</strong>).</p><p>First of all, instead of relying on my dusty geometry knowledge, I have achieved modularity by creating a board of “squares”. Somewhat like a chessboard. This board is easily achieved by rendering <em>Live Components </em>on a parent Live View, in a sort of matrix, using embedded Elixir (HTML + Elixir):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b7ce6dc62f124c5e9224ba72c24bf3e/href">https://medium.com/media/2b7ce6dc62f124c5e9224ba72c24bf3e/href</a></iframe><p>As for the actual Live Components, these will basically render a preview of whatever a user draws for that specific board square. Each board square is, in fact, a single canvas element that will hold the actual content that will be drawing on:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/24eebaba2a87523f2203be0e5a02fd8e/href">https://medium.com/media/24eebaba2a87523f2203be0e5a02fd8e/href</a></iframe><p>Clicking on a board square will send an event to the Live Component and will lead to a redirect to the second view available, which is the actual drawing screen. Take a look at the click event being handled on a random square:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hpimr8zII95lcoo9ODzUqA.gif" /><figcaption>Clicking any board square redirects to the drawing page</figcaption></figure><p>For the drawing page the plan was very similar. We have a Live View that renders a board of Live Components, which just like in the preview board will have different events to react to such as clicks or held click in order to give that sense of “stroke” that drawing applications usually deliver.</p><p>For the parent Live View (CanvasLive) it’s not only in charge of rendering the Live Components but also handling the current value of the color picker. Just like on the original Big Canvas, I used the exact same library which was <a href="https://github.com/Simonwep/pickr"><strong>pickr</strong></a><strong> </strong>for selecting the current color that will be applied to the clicked squares:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c478f426e408246e26e9241c794887bd/href">https://medium.com/media/c478f426e408246e26e9241c794887bd/href</a></iframe><p>Since this library is in JavaScript we can achieve interoperability via web-sockets with Live View hooks. Therefore, we can handle the selection of colors and assign it to each child component that is being clicked. The color change event is triggered on the client and dispatched as an event to the parent Live View using the <em>pushEvent</em> function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/371aef3134a69ae48b903c705ef257a7/href">https://medium.com/media/371aef3134a69ae48b903c705ef257a7/href</a></iframe><p>Every time a new color is picked, the parent Live View will hold that hex value as the current color for assigning the background of each clicked square:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*agRPGBRBYB1uvRrzd9BM-g.gif" /><figcaption>Selecting different colors with pickr</figcaption></figure><p>By using Live View and Live Components the 2-page distribution is no longer a slew of code where everything is handled on a single file. Instead, the code has been isolated to the corresponding concern, which will lead to real modularity and is easier to maintain and scale with more features when needed.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F4890836&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Farnold-schwarzenegger-thats-better-better-ooh-gif-4890836&amp;image=https%3A%2F%2Fmedia.tenor.com%2Fimages%2F02e1e27e4f75f12b0936e5cfd09d2019%2Fraw&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce484829888c6d8ffc2468d9dc6b095c/href">https://medium.com/media/ce484829888c6d8ffc2468d9dc6b095c/href</a></iframe><h4>Real-Time Issue</h4><p>The original Big Canvas was described on YouTube as a:</p><blockquote>“multiplayer drawing app”</blockquote><p>Having the word multiplayer implies that users will interact with each other in some way. It also implies that the user experience will happen in some sort of real-time events, where users can at least collaborate in some way. Just to get straight to the point, the “multiplayer” was never delivered, at least not in a manner I would consider valid.</p><p>The reason I consider that multiplayer or Real-Time as said explicitly on the video is not present is because, in order to perceive changes on the main preview board (of Big Canvas), the user is forced to refresh in order to obtain any changes. A user might have an open tab of Big Canvas for a long time, and unless the browser is actually refreshed, the preview board will remain still until that refresh occurs.</p><p>The Real-Time portion of Big Canvas is supposed to be the persistence of the data (the pixels of the canvases) on a Firebase Database. We can actually agree that the persistence on something like Firebase is quick enough to be considered as Real-Time, but how does that even affect the users if the browser has to be refreshed in order for those new changes to actually take place? Can kids these days even call that “multiplayer”?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F19994873&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fconfusion-confused-look-confused-face-visible-confusion-perplexed-gif-19994873&amp;image=https%3A%2F%2Fmedia.tenor.com%2Fimages%2Ff0176a35dc1377aa4f99135b485d9857%2Ftenor.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/8855e62339d7e70ccfba875837302d19/href">https://medium.com/media/8855e62339d7e70ccfba875837302d19/href</a></iframe><p>In case you don’t like refreshing your browser either, don’t worry because…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YnMWrcJnkgM1XZfgk38lTA.png" /><figcaption>Phoenix PubSub ready to deliver!</figcaption></figure><h4>Real-Time Improved</h4><p>Phoenix PubSub is a Real-time Publisher/Subscriber service that in conjunction with Elixir can lead to what I actually desire, which is a drawing application where every user can preview in Soft Real-Time what is actually being modified to absolutely every single canvas from the preview board.</p><p>In order to add <strong>PubSub,</strong> we require 2 things, which are the publishing of a topic and the subscription to that topic. Every time a user clicks on a canvas component (the little squares that change color) an <em>“update”</em> message should be broadcasted to every user that has an open tab with the preview board on a browser:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5a4191d5c24d34a8bd4b0739af3f0aa/href">https://medium.com/media/e5a4191d5c24d34a8bd4b0739af3f0aa/href</a></iframe><p>Now the only thing that’s missing is the subscription to the topic, which will have to happen on the preview board, because every time any user modifies at least one pixel from any canvas, the server will re-render only those board components that are previewing a modified canvas at the moment, therefore delivering a soft real-time experience and somehow a more realistic sense of a multiplayer game by today standards at least.</p><p>In order to subscribe the preview board to the topic, we just need to add that subscription when the parent Live View is actually mounted. Now every time the topic is updated, an event will be received and the handling of it is just sending an update to the corresponding component, which will update its assigns and lead to a re-render because the current assigns differ from the previous ones. It’s quite convenient, in order to prevent the entire board, to re-render, because only those squares that are changing should be re-rendered after all:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f232f6d886ff8fb1409bc3876084232b/href">https://medium.com/media/f232f6d886ff8fb1409bc3876084232b/href</a></iframe><p>With the PubSub in place, we can now have subscribed every user that has an open tab with the preview board. Every update will broadcast the message which will lead to an update on the preview of the corresponding component, take a look:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cxvwuc_tddc8JEuYdxt1fQ.gif" /><figcaption>Soft Real-Time taking place on 2 separate browsers</figcaption></figure><p>And just like that, we have improved substantially the original application. We have a proper application with much more structured code/entities, as well as a fully functional soft real-time that actually impacts the user’s experience. And that’s why I have named it <strong>Better Big Canvas</strong>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F15747035&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fokay-yeah-ok-chris-hemsworth-sure-ok-gif-15747035&amp;image=https%3A%2F%2Fmedia.tenor.com%2Fimages%2F32d2b74b550e93dafc6ebe05a56d98db%2Ftenor.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b9fb8c6e92c0e1b90f44e8191a92c99/href">https://medium.com/media/2b9fb8c6e92c0e1b90f44e8191a92c99/href</a></iframe><h4>Conclusion</h4><p><strong>Better Big Canvas </strong>is just a remake of TechLead’s original implementation. Therefore, it’s not intended as a way of underestimating his work but instead of leveraging the original idea with Open Source cutting edge technologies that are available to any developer.</p><p>I hope you’ve liked these new improvements that <strong>Big Canvas</strong> received as much as I did. Don’t forget to check the <a href="https://github.com/ChristianTovar/better-big-canvas">Better Big Canvas repo</a> for more details regarding the complete code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fca6806c0ac" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kommit-software-developers/improving-techleads-big-canvas-1fca6806c0ac">Improving TechLead’s Big Canvas</a> was originally published in <a href="https://medium.com/kommit-software-developers">kommit</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>