<?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 Tsavo van den Berg, Knott on Medium]]></title>
        <description><![CDATA[Stories by Tsavo van den Berg, Knott on Medium]]></description>
        <link>https://medium.com/@tsavo?source=rss-2ae99fdda607------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*IuGyt_LnPooVC3kMmPkeiw.jpeg</url>
            <title>Stories by Tsavo van den Berg, Knott on Medium</title>
            <link>https://medium.com/@tsavo?source=rss-2ae99fdda607------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 22:32:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tsavo/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[(PrismJS || HighlightJS || CodeMirror 6) + CodeDetectionAPI = ❤️]]></title>
            <link>https://tsavo.medium.com/prismjs-highlightjs-codemirror-6-codedetectionapi-%EF%B8%8F-af99dc13d83b?source=rss-2ae99fdda607------2</link>
            <guid isPermaLink="false">https://medium.com/p/af99dc13d83b</guid>
            <category><![CDATA[syntax-highlighting]]></category>
            <category><![CDATA[prismjs]]></category>
            <category><![CDATA[highlightjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[codemirror]]></category>
            <dc:creator><![CDATA[Tsavo van den Berg, Knott]]></dc:creator>
            <pubDate>Tue, 08 Mar 2022 20:49:12 GMT</pubDate>
            <atom:updated>2022-03-08T20:49:12.031Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f7b_0f8UxN4K6NFpjbPjgA.png" /><figcaption>CodeDetectionAPI + HighlightJS + PrisimJS + CodeMirror6 Logos</figcaption></figure><h3>Intro: A Quick Rant On Code Snippets</h3><p>As a developer, code snippets and technical language are absolutely everywhere. They’re in developer docs, shared in messengers like Slack or Teams, written in productivity tools like Notion or Google Docs, they’re unfortunately still sent via email sometimes… and, of course, they’re in our IDEs.</p><p>These apps just aren’t well built to identify and handle this code, leading to a series of frustrating experiences as a user.</p><p>THE WORST experience is to encounter code snippets that are unlabeled, unclassified and not syntax highlighted 🤦‍♂️…and if I may say so myself, developers are often lazy and hence every day I see more and more of the latter.</p><p>Close behind in annoyance is SLOW DEVELOPER DOCS SITES.</p><p>And last but certainly not least, snippets that get lost in the avalanche of Slack/Team/Discord messages. Good luck finding that typescript snippet later, ESPECIALLY if it’s not classified or syntax highlighted.</p><p>Today, I’m throwing out some power tips on how to up your game when building a docsite, web app or chat bot that is going to be dealing with lots of code snippets, code editing, syntax highlighting and/or documentation.</p><h3>The Classic Solutions — HighlightJS, PrismJS and CodeMirror</h3><h4>An old time favorite — <a href="https://highlightjs.org/">HighlightJS</a> — but it’s not without shortcomings…</h4><p>For some context, earlier in my career I was building a messaging platform for my university and I REALLY wanted to add a feature where users could paste a code snippet into the send input, press send, and the system would automagically think, “Hey, this is isn’t natural language, it’s actually <em>technical</em> language,” and, “Not only is this code, but it’s actually Kotlin or Dart or Typescript,” and, “I should syntax highlight this and do some additional tagging/sanitization/security…”</p><p>This would be an amazing experience for users sharing code in my communications platform. Truly, this would be magical for forums, blogs, comments and threads as well!</p><p>Alas, the code and technical language generated by our users was unstructured and unlabeled, and therefore <strong>oftentimes neither syntax-highlighted nor formatted.</strong> 😥</p><p>In search of a solution, <a href="https://highlightjs.org/">HighlightJS</a> stood out — it has <strong>Automatic Language Detection</strong> and <strong>Multi-Language Code Highlighting. </strong>That’s perfect, right!?</p><p>Well, somewhat…</p><p><strong>Problem 1:</strong> You still need to know if the user input <strong><em>is</em></strong> code / technical language vs plain text / natural language. (This turns out to be quite difficult to solve, but there’s a solution below.)</p><p><strong>Problem 2:</strong> If it’s code, you need to know what language it is, and then, of course, syntax highlight it!</p><p><a href="https://highlightjs.org/">HighlightJS</a> <strong><em>does not</em></strong> solve Problem 1, and for Problem 2, <a href="https://highlightjs.org/">HighlightJS</a> can <strong><em>attempt</em></strong> to determine the coding language but at an expensive network and compute cost.</p><p>The caveat in solving Problem 2 is that <a href="https://highlightjs.org/">HighlightJS</a> introduces several megabytes when loading the Automatic Language Detection system. For reference, when you go to the <a href="https://highlightjs.org/">HighlightJS</a> website and download source for their default 34 languages, depending on your build process, you’ll likely end up adding <strong>~1.6 Megabytes</strong> to your bundle size, and — yes, this is minified — for full language support, your bundle size clocks in at <strong>~2.5 Megabytes</strong>. Further, when looking at <a href="https://bundlephobia.com/package/highlight.js@11.4.0">HighlightJS’s Bundlephobia</a> and taking into account variable network speeds, we’re looking at somewhere between 300 to ~5600 milliseconds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lcjxpcsIuK1Qglpb" /><figcaption><a href="https://bundlephobia.com/package/highlight.js">https://bundlephobia.com/package/highlight.js</a></figcaption></figure><p>If you take a conservative load time for HighlightJS, say 1500 milliseconds, you’re already negatively impacting your users’ experience.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CrjMLXxc46efl-NS" /><figcaption><a href="https://www.websitebuilderexpert.com/building-websites/website-load-time-statistics">https://www.websitebuilderexpert.com/building-websites/website-load-time-statistics</a></figcaption></figure><p>Beyond page load, HighlightJS is using regex under the hood so you can wreck your <a href="https://web.dev/interactive/">Time to Interactive</a> and Frame Rates. If you’re not careful, <a href="https://javascript.info/regexp-catastrophic-backtracking">too much regex processing can easily freeze the user’s window</a> or drop frames below the target 60fps.</p><p>Long story short — props to HighlightJS for attempting to solve the Problem 2 around Language Detection, but we can do better.</p><h4>A New and Improved Stack? PrismJS + CodeDetectionAPI</h4><p>Given HighlightJS’s limitations, my team at <a href="http://code.pieces.app/">Pieces</a> built and published the <a href="https://codedetectionapi.runtime.dev/">CodeDetectionAPI</a> to solve Problems 1 and 2 in our app with machine learning while achieving optimal network and compute performance.</p><p><a href="https://codedetectionapi.runtime.dev/">CodeDetectionAPI</a> is open and accessible through our API platform at <a href="http://runtime.dev/">runtime.dev</a> and via our friends at <a href="http://apilayer.com/">apilayer.com</a>.</p><p><a href="http://codedetectionapi.runtime.dev/">CodeDetectionAPI</a> is gloriously simple and performant. It can determine whether a given string/input is natural language or code/technical language. If it detects code, it will classify it with a high level of accuracy in up to 30 programming languages. And, it does all of this in approximately 250 milliseconds while minimizing the requirements of on-device compute.</p><p>And with that, <a href="http://codedetectionapi.runtime.dev/">CodeDetectionAPI</a> is finally the silver bullet I’ve been looking for, allowing me to explore other syntax highlighting solutions…</p><p>This is where <a href="https://prismjs.com/">PrismJS</a> comes into play.</p><p>PrismJS has a very small core, ~ 2 kilobytes, which results in significantly faster load times than HighlightJS. Further, if we know the language of the code snippet that we want to highlight, we can utilize <a href="https://prismjs.com/plugins/autoloader/">PrismJS’s Autoloader Plugin</a> to specifically <a href="https://web.dev/third-party-facades/">lazy-load</a> stylesheets for particular languages on demand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iM_g5YUTsgpWC8zS" /><figcaption><a href="https://bundlephobia.com/package/prismjs@1.27.0">https://bundlephobia.com/package/prismjs@1.27.0</a></figcaption></figure><p>Take a look at <a href="https://bundlephobia.com/package/prismjs@1.27.0">PrismJS’s Bundlephobia</a> — <a href="https://prismjs.com/">PrismJS</a> clocks in at significantly faster load times!</p><p>When deploying <a href="https://prismjs.com/">PrismJS</a> with <a href="http://codedetectionapi.runtime.dev/">CodeDetectionAPI</a>, the hope is that your users will have a significantly improved experience both around page/product performance but also around ease of use! Code can finally and automagically be treated as code with the beautiful syntax highlighting it deserves.</p><p>As an aside, it’s worth mentioning that you can actually utilize a similar technique with <strong><em>HighlightJS by</em></strong> <strong><em>loading specific dependencies without</em></strong> <strong><em>the Autodetection features</em></strong> and supplement those with <a href="http://codedetectionapi.runtime.dev/">CodeDetectionAPI</a>, similar to what I do with PrismJS.</p><p>Finally, there are times when you’re building a product where you not only want code to be highlighted, but also editable. Problem 2 around Language Detection and Syntax Highlighting also applies in this case.</p><p>I want to give a quick shoutout to <a href="https://codemirror.net/6/">CodeMirror 6</a>, which is doing a great job of building a modular and performant Code Editor for the browser. <a href="http://codedetectionapi.runtime.dev/">CodeDetectionAPI</a> can be used in conjunction with <a href="https://codemirror.net/">CodeMirror</a> to automatically detect and set the language as the user begins writing. No dropdowns or selections necessary! In practice, this is actually pretty smooth and users enjoy simply being able to write code without configuring anything. 🎩 🪄</p><h3>Icing on the Cake — All-around Better UX</h3><p>Whatever you’re building — perhaps a chatbot, messenger, documentation site, forum, online code editor or a developer productivity tool like <a href="http://code.pieces.app/">code.pieces.app</a>, the CodeDetectionAPI is fundamental to leveling up the performance and user experience around writing, sharing, reading and searching the technical language and code within your product.</p><p>No more labeling code snippets, no more dropdowns, no more unnecessary loading of large javascript bundles, no more regex parsing on the main thread. At Runtime.dev, we’re creating automagical experiences around code and technical language. The <a href="http://codedetectionapi.runtime.dev/">CodeDetectionAPI</a> coupled with something like <a href="https://prismjs.com/">PrismJS</a> or <a href="https://codemirror.net/6/">CodeMirror 6</a> is a mega-step in the right direction.</p><h3>Where to next?</h3><p>To see the <a href="http://codedetectionapi.runtime.dev/">CodeDetectionAPI</a> in production in the wild, check out the <a href="http://code.pieces.app/">Pieces</a> app, which also includes some really innovative work around Technical Language Processing, NLP and extracting text from screenshots (OCR).</p><p><a href="http://codedetectionapi.runtime.dev/">CodeDetectionAPI</a> is a debut API for the <a href="http://runtime.dev/">runtime.dev</a> platform. In the coming weeks, look for some fantastic new APIs, including auto-tag generation from a code snippet and the extraction of code snippets from images.</p><p>When these capabilities land in the <a href="http://runtime.dev/">runtime.dev</a> platform, it’s going to open another set of opportunities for app developers to improve Search, SEO and Accessibility. Being able to automatically generate meta-tags for Search and Alt-Text is a game changer for SEO and Accessibility. Furthermore, being able to automatically extract code from images on a webpage is going to level up in-browser features like Find in Page or Copy and Paste.</p><p>All in all, I hope you found some of these insights useful and perhaps reconsider your user experience and performance around code snippets!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af99dc13d83b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Considerate Decorators & Convenient Proxies — Metaprogramming for everyone.]]></title>
            <link>https://tsavo.medium.com/considerate-decorators-convenient-proxies-metaprogramming-for-everyone-8da4c2eb6e22?source=rss-2ae99fdda607------2</link>
            <guid isPermaLink="false">https://medium.com/p/8da4c2eb6e22</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[decorators]]></category>
            <category><![CDATA[metaprogramming]]></category>
            <category><![CDATA[cincijs-meetup]]></category>
            <dc:creator><![CDATA[Tsavo van den Berg, Knott]]></dc:creator>
            <pubDate>Mon, 08 Mar 2021 19:58:12 GMT</pubDate>
            <atom:updated>2021-03-10T20:06:13.557Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yHmtjp3--WmT4GGEWpvWTw.png" /></figure><p>Considerate Decorators &amp; Convenient Proxies — Metaprogramming for everyone.</p><p><strong>Event Link:</strong></p><p><a href="https://www.meetup.com/Cincinnati-Javascript-User-Group/events/xpbsdsyccfbnb/">CinciJS Virtual Meetup — March 10, 2021</a> (COMPLETED)</p><p><a href="https://docs.google.com/presentation/d/1f_nFkWiUrfRZ6j7kaDoamzVy6mXpQkyp2XqHWsruaWM/edit?usp=sharing">Google Slides Presentation</a></p><p><a href="https://github.com/tsavo-vdb-knott/TC39-Decorator-Augmentation-Through-Proxies">GitHub Repo for Decorators Playground (Includes Babel Legacy, Babel TC39, Typescript)</a></p><p><strong>Overview:</strong></p><p>Metaprogramming is magic. The ability to remove redundancy, ensure consistency, and seamlessly integrate design patterns is every developer’s dream. Executed well, metaprogramming is the embodiment of 10x engineering, it is the code you never have to write but always get to use, it is the code that does your work for you, it is the best type of code. As programming languages have evolved, metaprogramming has become the forefront of developer experience. This presentation aims to highlight several metaprogramming techniques, through the use of Javascript Decorators and Proxies, to further enhance the developer experience.</p><p><strong>Presentation Introduction:</strong></p><p>Metaprogramming is magic. The ability to remove redundancy, ensure consistency, and seamlessly integrate design patterns is every developer’s dream. Executed well, metaprogramming is the embodiment of 10x engineering, it is the code you never have to write but always get to use, it is the code that does your work for you, it is the best type of code. As programming languages have evolved, metaprogramming has become the forefront of developer experience.</p><p>As a contemporary web developer and framework author I am so pleased to see not only the tremendous evolution of the Javascript spec, but also, the explosive adoption of Typescript. In this wave of language maturity, one thing has been clear to me — the focus on developer experience, through the implementation of metaprogramming features, has been at the core of these dramatic technological progressions.</p><p>With the completion of the ES6 spec a few years ago, Javascript developers gained several key metaprogramming tools. Adding to the classics of Call, Bind, and Apply, the new spec introduced Anonymous/Arrow Functions, Classes &amp; Modules, Import standardization, and Proxies. Additionally, during this time, the Javascript Community also saw a major adoption of a very useful yet non-standard feature, Decorators.</p><p>From libraries such as LitElement &amp; NgXS to frameworks/toolchains such as Angular &amp; Stencil, to syntactical supersets such as Typescript &amp; Babel, Decorators are simply being used everywhere.</p><p>Decorators turned out to be so useful that they have become a fundamental go-to mechanism for metaprogramming. Through compilers/transpilers such as Typescript and Babel, developers now have the ability to augment methods, classes, and properties in Javascript with abstracted functionality in an elegant and seamless regard.</p><p>This proliferation of Decorators has been tremendous for Developer Experience; however, its acceleration outside of a standardized spec, over time, has made life difficult for the authors of such Decorators. There is a growing challenge in supporting Decorators throughout existing code, and planning a transition to the future standard.</p><p>In looking ahead at the highly anticipated TC39 proposal, we see a maturing Stage 2 Decorators specification — rounding out a standardized quintessential toolkit for metaprogramming. Although the future is near, there is a lot of work yet to be done.</p><p>That being said, the following presentation aims to highlight several metaprogramming techniques with Decorators and Proxies that developers can utilize today regardless of a rapidly changing environment. Furthermore, I will outline how we can safely push the boundaries of our development experience through these two complementary Javascript capabilities.</p><p><strong>About the Speaker:</strong></p><p>Tsavo van den Berg, Knott is a local Entrepreneur, Creator, and Computer Scientist here in Cincinnati, Ohio. Tsavo is a co-founder at Pieces.app, an upcoming product focused on atomic-level cloud storage and collaboration for professional creators. Tsavo is also the inventor of Runtime.dev, an isomorphic Javascript framework designed to address high data volume and velocity problems typically found within complex web applications. He has an extensive background in lower level Javascript/client-side technologies including Web Components, Web/Service Workers, DOM Virtualization and Task/Execution Management. Today, Tsavo spends most of his day-to-day supporting his team on product centric technologies such as Typescript, Angular, Web Assembly, Google Cloud/Firebase, and Developer Tooling/Bundling Systems.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8da4c2eb6e22" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LitElement & Differential Rendering with the Component-Controller Model]]></title>
            <link>https://tsavo.medium.com/litelement-differential-rendering-with-the-component-controller-model-e9eb3cb8f6a7?source=rss-2ae99fdda607------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9eb3cb8f6a7</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[web-components]]></category>
            <category><![CDATA[litelement]]></category>
            <category><![CDATA[lit-html]]></category>
            <dc:creator><![CDATA[Tsavo van den Berg, Knott]]></dc:creator>
            <pubDate>Sat, 05 Oct 2019 08:30:35 GMT</pubDate>
            <atom:updated>2019-10-10T18:01:51.005Z</atom:updated>
            <content:encoded><![CDATA[<h3>LitElement &amp; Differential Rendering with the Component-Controller Model</h3><p>When architecting and building large web applications using web components, it can be overwhelming to manage the multitude of factors that go into it — state management, rendering, styles and animations, and etc.</p><p>For instance, data layers tend to become coupled with component logic, property computation, data transformation, and rendering. Throw animation choreography and dynamic styling into the mix and you have some beautiful code soup — or at least a large, confusing file.</p><p>Beyond challenges with the organization and readability of the code, these large, mixed files begin to impact the performance of components and the application as a whole. This is why we developed the Component-Controller Model. The model was developed to enhance application performance in many ways. Whether you need to incrementally lazy load functionality, pre-process data before an initial render, or access various component states, such as animation promises and data changes, the component-controller model sets the groundwork for effectively achieving and optimizing all of the aforementioned.</p><p>The general idea of the Component-Controller Model is to inject a data-layer object (the Controller) into a web component, and have that component react to the least amount of data-layer changes, which saves and defers most of its render costs for DOM-related activity, such as styling and animations.</p><p><strong>TL;DR: The goal of the Component-Controller Model is as follows:</strong></p><ul><li>Organize and decouple the logic of components from rendering, styling, and animations;</li><li>Ensure a pre-render data boot-up permitting computation to happen before and independently to renders</li><li>General optimization and performance through the overall reductions of renders</li><li>Reduction in total number of data-bindings necessary to inject data into components</li><li>Create a pattern that enables complex multi-component interactions, with the intent to efficiently coordinate data changes, animations, renders, and user interactions</li><li>Only affect the components that are directly connected to the data changes/interactions</li></ul><p>The rest of the article will compare and contrast, traditional methods of using Web Components vs. the Component Controller Model, analyze naive multiple component interactions vs. interactions built on top of component-controller model, and speculate on the scaled implications of implementation and adoption component-controller model within your application.</p><p>Throughout the remainder of this article, we will compare and contrast the Component-Controller Model against traditional methods of using web components. This includes multi-component interactions and the various scalability implications of each.</p><p>Additionally we will look at how, in some cases, the component-controller model makes typically non-performant render patterns as optimal as possible, without additional code, even to the point of reducing renders from <em>O(n log(n)) or O(n²) to O(n) or O(1).</em></p><p>One example will be reducing the time complexity of rendering, adding to, and updating a list of items with the javascript Array.prototype.map() — O(n) down to the same time complexity of lit-html’s repeat directive — O(log(n)) or even O(1).</p><h3>Synchronizing Changes within Multi-Component Interactions</h3><p>To get started, let’s look at how one might build and implement a set of Tabs using traditional methods. A complete Tabs component requires a collection of components that need to consistently interact with one another and stay in sync at both the Interface layer and data layer.</p><p>The basis of the next three diagrams is as follows: The View contains a Tabs Container. The View also contains four Tabs which are slotted into the Tabs Container Light DOM. The objective here is to keep in-sync all Tab Elements and their selected state with the Tabs Container Element when the user selects a tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q1j2fYuvnliVhxNberXCvw.png" /><figcaption>Selected Key Based Sync</figcaption></figure><p>In the figure above, Example A, the synchronization is achieved through a view-level property, “SelectedTabKey”, which is updated through a user engagement. This creates a waterfall-like chain reaction, through the view, inevitably syncing related components in on the change.</p><p>On bootup, there are six total renders: one for the view, one for the Tabs Container, and one for each of the four Tabs.</p><p>When a new Tab is clicked, the view must first update its’ SelectedTabKey property, which causes a re-render of the view. Then, the Tabs Container must update its’ SelectedTabKey property, which causes an internal re-render. Lastly, the previously selected Tab becomes de-selected, while the clicked Tab becomes selected, which adds two more renders to the total reaction.</p><p><strong>Pros with “Example A ” Strategy</strong></p><ul><li>No DOM querying</li><li>Simple Model</li></ul><p><strong>Cons with “Example A ” Strategy</strong></p><ul><li>Generally involves the view too much</li><li>Redundant properties and functions on the view level</li><li>Too many renders per tab engagement</li><li>Five total lit-html ${} data-bindings/update locations. Additional ‘part’ management overhead added.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hP5IbOjApD6JkwgR6LcUtg.png" /><figcaption>Direct Sync through Element References</figcaption></figure><p>As represented in Example B above, the synchronization between components is managed by accessing elements directly with DOM querying. The view queries its’ shadowRoot for the Tabs Container, and internally, the Tabs Container queries its’ renderRoot DOM for slotted Tabs. This means the Tabs Container holds references to all child Tab elements; as well as, a reference to the currently selected Tab.</p><p>When a new Tab is clicked, we access the view’s reference to the Tabs Container and call its’ internal updateSelectedTab function with a reference to the Tab that was clicked as its’ parameter. We achieve this reference through event properties such as path, target, or srcElement (depending on the browser or polyfill).</p><p>From there, the Tabs Container deselects the previously selected Tab and sets the new selected Tab. As a result, this one change requires a minimum of two renders — one for each updated tab. Furthermore, this implies the Tabs Container results in no re-renders through this update.</p><p>More shortcomings of Example B can be seen on bootup due to the fact it requires a render in order to gain access to all element references. This is especially costly when setting a default selected Tab, which requires at least one full sub-tree render before it can sync.</p><p><strong>Pros with Example B Strategy</strong></p><ul><li>Reduced overall renders per Tab engagement</li><li>Less View Involvement</li><li>No lit-html ${} data-bindings. Reduced ‘part’ management overhead.</li></ul><p><strong>Cons with Example B Strategy</strong></p><ul><li>Must await First Render before updating and setting initially selected tab</li><li>DOM Querying Required</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LCvCDU6rfwamx7WepHf2eA.png" /><figcaption><strong>The same interactions as outlined in Examples A and B but while using the Component-Controller Model.</strong></figcaption></figure><p>Using the Component-Controller Model, we use the minimum number of bootup renders, six, and the minimum number of renders per Tab engagement — all without any DOM querying.</p><p>The Component-Controller Model allows all data-layers to be connected and fully in sync before they are injected into their respective components at render time. This allows inter-reactivity at the data-layer independent to the render-layer.</p><p>The Component-Controller Model ensures the data layer (Controller) for all interdependent components are connected and fully in-sync prior to being injected into their respective components at render time. This results in complete component data layer reactivity and computing truly independent of the render layer and DOM activity — This is what allows for what we refer to as differential rendering.</p><p><strong>Pros with Component-Controller Strategy</strong></p><ul><li>Reduced overall renders per Tab engagement</li><li>No View Involvement</li><li>De-coupled data-layer code from render code</li><li>Minimal number of Boot-up renders</li><li>Zero DOM Querying, and no element references — allowing for complex controller classes to be used both in a web-worker/server environment and in the client.</li><li>No lit-html ${} data-bindings as all linking of data happens pre-render and controllers are injected into constructors of components. Again, reduced ‘part’ management overhead for lit-html.</li></ul><p><strong>Cons with Component-Controller Model</strong></p><ul><li>Potentially higher learning curve</li><li>Let me know if you find more :)</li></ul><h3>Rendering, Adding, and Updating Items &amp; Data in Large Lists</h3><p>In this section I will overview the optimality of the Component-Controller model in the context of rendering lists; and further, updating data within components post initial render.</p><p>Consider the following code. Which renders a list of items, 10 of which are controlled, and 10 of which are simple.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vu3S7yytWTCWbQuTaCaoqg.png" /></figure><p>As you can see, in the code sample above, the controllers and controlled components are booted and connected ahead of render time. Additionally, 10 simple-runtime-components are booted during render time and the value, foo, is bound and injected by lit-html.</p><p>Note that this binding of property “foo” in the map creates 10 locations to be managed by lit-html in the event that you want to pass in 10 pieces of data. You have now created 100 total locations to be managed by lit-html.</p><p>With the Component-Controller Model, you only create a maximum of one data-bound location. In the example above, there are no data bindings on the controlled component since the controller is injected into the component through the component’s constructor prior to render.</p><h3>Comparing the process of updating items in each list.</h3><h4>Process of updating an item in the case of ‘items’ as a mutable array. Also ensuring an ‘old’ value to be provided for LitElement’s requestUpdate()</h4><h4>Total Renders: 2</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*kk6KpoHGMFu_e0MsiPfeJw.png" /></figure><ul><li>Access Item In Array and Update Value</li><li>Request update in the view for “items”</li><li>View Re-Renders</li><li>Item Re-Renders</li></ul><h4>Process of updating an item in the case of ‘items’ as an immutable array. This will allow for an ‘old’ value from requestUpdate()</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*xRv7cmyX2AZxnyWMTYCbOQ.png" /></figure><ul><li>Set ‘items’ to a new array through Slicing and Spreading parts of the old array.<strong> Total Renders: 2</strong></li><li>View Re-Renders</li><li>Item Re-Renders</li></ul><h4>Process of updating a controlled item. Total Renders: 1</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*DYtJp9McgDz9jiQDESWcrA.png" /></figure><ul><li>Update Controller of Item To be Updated</li><li>Item Internally Re-Renders Independently of View</li></ul><p><strong>TL;DR: Take away here is that the component-controller model minimizes overall renders; as well as, removes overhead of managing data-bindings for Lit-Html.</strong></p><h3>THE MAGIC — Comparing the process of adding items to each list.</h3><h4>Process of adding an item to the front of “items” as a mutable array. Also ensuring an ‘old’ value to be provided for LitElement’s requestUpdate() Total Renders: O(n) + 1 where N is a render per item in list, and 1 is the required View render. 12 Total Renders</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*UHM33KXl9e4nfyvD5sr9JQ.png" /></figure><ul><li>Item added to front of items array</li><li>requestUpdate triggers View re-render</li><li>&lt;simple-runtime-components .foo=${foo}&gt; bindings are updated for all 11 components.</li></ul><h4>Process of adding an item to the front of “items” as an immutable Total Renders: O(n) + 1 where N is a render per item in list, and 1 is the required View render. 12 Total Renders</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qGseuLZIuzLRokv-6V5hpw.png" /></figure><ul><li>Item added to front of items array</li><li>Because of immutability Lit-Element change detection kicks in and re-renders the View</li><li>&lt;simple-runtime-components .foo=${foo}&gt; bindings are updated for all 11 components.</li></ul><h4>Process of adding a new ControlledComponent to the front of “controlledComponents” — Also ensuring an ‘old’ value is passed into requestUpdate. Total Renders O(1) + 1. A render for the view and a render for the newly added ControlledComponent.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cukD3KIxG_PiS5jAhT3rzA.png" /></figure><ul><li>A Controller is created and injected into the constructor of a new ControlledComponent</li><li>ControlledComponent added to front of controlledComponents array.</li><li>An update is requested to re-render the View.</li><li>Because there are no data-bindings. <strong>No other ControlledComponents Render.</strong></li></ul><h4>The Truth is in the Logs!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*UNVtIqp5W5jpkiA61ztHKQ.png" /></figure><h4>.map() + Component Controller Model === repeat() Directive from lit-html</h4><p>Alas, we have arrived, in replacing our Array.prototype.map() functions with lit-html’s repeat directive we are able to avoid the full re-rendering of the simple-runtime-components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PdX7p3yDx-tMByOUJTKQfQ.png" /></figure><p>The repeat directive allows for smart key-based reordering and updates; however, it is still an added level of execution overhead and more code imported into your ES module. Why bother when you can achieve the same result with the ComponentController Model?</p><p>All Code is available for educational purposes only at:<a href="https://github.com/T-Knott-Mesh/RuntimeLabs"> https://github.com/T-Knott-Mesh/RuntimeLabs</a></p><p><strong>What does all of this mean?</strong></p><p>In the context of web components, Lit-Element, and the forthcoming Runtime Framework, the Component-Controller Model creates opportunities for new application architectures, allowing developers to do more with less code, less computational cost, and more organization.</p><p>The Component-Controller Model can be applied in many ways. The examples shared in this article are just the tip of the iceberg. We are extremely excited to share the Runtime Framework and libraries with you. Our hope is that developers will gain inspiration to bring new ideas to life, contribute improvements, and become increasingly excited about Javascript, Lit-Element, Web Components, and the Web Platform as a whole.</p><p><strong>About the Runtime Framework</strong></p><p>The Runtime Framework is designed to have the most-amount of flexibility in expression — thanks in large to LitElement — be able to run all data-level operations within a web-worker or on a server while differentially and precisely re-rendering applications DOM subtrees, and lastly have a great runtime 🙃.</p><h4>About The Author</h4><p>My name is Tsavo van den Berg — Knott. At 22 years old, I am the oldest of 5 and reside in Cincinnati, Ohio. I am a proud dual citizen of both the United States and the Netherlands. My passions lie in web technologies &amp; (performance and intelligence), animation, design, and user experience. The love affair with the web started while I was an undergraduate at Miami University (OH) studying Computer Science and Interactive Media. My professors allowed me to complete all of my web-based projects using Polymer v0.5. Now, here we are with Lit-Element. How far we have come!</p><p>Today, I am the Co-Founder of Mesh Intelligent Technology, a tech company based here in Cincinnati focused on building information-age cloud products at scale using the Runtime Framework, which I have been architecting for over a year now in parallel to the development of Lit-Element (dating back to v0.4.3).</p><p>I consistently work to advance technology opportunities to the Midwest and am very excited about where the web is going. It is a thrill to help push these technological innovations forward and drive the web component movement.</p><p>I’m always looking to have conversations with new people, get constructive feedback, and learn of new opportunities for growth. Don’t hesitate to get in contact with me via <a href="https://twitter.com/KnottTsavo">Twitter</a> or <a href="https://www.linkedin.com/in/tsavoknott/">LinkedIn</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9eb3cb8f6a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>