<?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 Charuka Herath on Medium]]></title>
        <description><![CDATA[Stories by Charuka Herath on Medium]]></description>
        <link>https://medium.com/@charuka95?source=rss-6d47b99e463c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*VIfuZSA2I9rYnGtQggjaGQ.png</url>
            <title>Stories by Charuka Herath on Medium</title>
            <link>https://medium.com/@charuka95?source=rss-6d47b99e463c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 19:33:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@charuka95/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[Why Microservices Should use Event Sourcing]]></title>
            <link>https://medium.com/bitsrc/why-microservices-should-use-event-sourcing-9755a54ebfb4?source=rss-6d47b99e463c------2</link>
            <guid isPermaLink="false">https://medium.com/p/9755a54ebfb4</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Charuka Herath]]></dc:creator>
            <pubDate>Mon, 20 Jun 2022 06:46:07 GMT</pubDate>
            <atom:updated>2022-06-22T10:05:51.034Z</atom:updated>
            <content:encoded><![CDATA[<h4>6 Reasons where you need to use Event Sourcing in Micro-services</h4><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*ea0SaTnK1Zp-sxk032ZO-Q.jpeg" /></figure><p>Microservices play a vital role when migrating from monolithic applications. They help improve applications’ scalability, manageability, agility, or speed of delivery.</p><p>However, there are some challenges in using microservices, such as state handling. As developers, it is indispensable for us to know how to overcome these issues to get the maximum out of microservices.</p><p>Using event sourcing is a great solution for most of these issues. So, in this article, I will discuss why we should use event sourcing with microservices and the advantages of using it.</p><h3>What is Event Sourcing</h3><p>Event Sourcing is an alternative way to persist data. Compared to other state persistence methods like state-oriented persistence, event sourcing stores all the state mutations as a separate record called an event.</p><p>For example, when a customer puts items to a cart in an online buying platform, event sourcing saves all the state changes in the cart as a list of state-changing events. Whenever the state of an entity changes, a new event is appended to the list of events.</p><h3><strong>1. Smooth Transition from Domain-Driven Design</strong></h3><p>When it comes to the designing stage of a project, developers and designers analyze the domain and do event storming/event modeling. The objective here is to identify the project from a pure design standpoint.</p><p>However, a part of the conversation is highly event-oriented. So the outcome of the effort is microservices that developers will build. Therefore, the commands and events go into these different microservices.</p><p>Event sourcing comes in the stage of implementation. First, the code and the system’s data flow are implemented using event sourcing as the design has been done with the event mindset.</p><h3><strong>2. Reducing Coupling</strong></h3><p>Assume a scenario where two microservices loosely couple. If a design, implementation, or behavior change happens in one microservice, it won’t cause another change.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*TGgCI6xrjj0cHjp0Ogq0gg.png" /></figure><p>However, when it comes to microservices, the coupling can happen. For example, if a change is made to a microservice, it will cause all other microservices to collaborate with the first one directly or indirectly.</p><h3><strong>3. Optimizes the Read vs. Write performance Bottleneck</strong></h3><p>Imagine a typical system with many operations that are probably built over the years and managed by a single database. However, the database can be optimized for reads and writes when performing CRUD operations.</p><p>But it’s always a trade-off. If you optimize for reads, it comes with the expense of writes. If you optimize for writes, it comes with expensive reads. So there are obvious, significant trade-offs that are going on.</p><p>However, event sourcing solves the problem. When it comes to event sourcing, it uses <strong>segregated persistence</strong>. That is to say, we have got the event store that is inserting events. All the CRUD operations become just storage and events. All those events aggregate to this current operation state that developers need to execute.</p><p>The real advantage of the event store here is the expense of the user, and the bottleneck of read-write operations will decrease.</p><h3><strong>4. Elevate the concurrency barrier</strong></h3><p>There is a greater probability of getting a traffic spike in large enterprise applications. Such scenarios can affect the application database and solving them can be painful.</p><p>Yes, these issues can be solved by spending three or four weeks. But, you can still run into a situation where the database is just pushed to its limit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*WdiYLsKTwz6dTkzWpTeP-w.png" /></figure><p>This is another reason why event sourcing is increasingly becoming a popular approach. Event sourcing handles this issue by writing and inserting records in the spike into the event log and not letting the read-side wait.</p><h3><strong>5. Simplify and harden messaging</strong></h3><p>The semantics of messaging in microservices can be broken down into three categories.</p><ul><li><strong>In most once</strong> — Cases where a message might not get delivered, and you will lose messages under certain circumstances. When thinking about the microservice we build, this is not an acceptable feature.</li><li><strong>At least once</strong> — The category is the easiest to be implemented. In this case, a message can be delivered at least once. On the other hand, a certain message can be delivered more than twice.</li><li><strong>Exactly once</strong> — A reasonably mythical method and hard to implement but still doable from the consumer perspective.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*AWrb1e8LBKuWLu0in5oLvg.png" /></figure><p>There are some scenarios where messages do not deliver the first time. So the solution will be implementing a retry logic.</p><p>When developers implement a retry logic, they have to start thinking about cases like producer services trying to publish data. It has to be capable of being in that mode where some messages haven’t been delivered.</p><p>Also, cases like the service go down. And when that service comes back, can it pick up where it left off and continue to retry sending those messages? Such situations bring much complexity to the producer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*96RGwqE8CXZIPSi7yNTIsw.png" /></figure><p>Also, imagine a scenario where a service does a database transaction first, and then it makes a call to Kafka. Since these are two separate transactions, first the database transaction will occur. However, the message in Kafka will not pass. So that’s a leak in the pipe, and the consumers have a potential vulnerability. When the service goes down during that exposure period, the messages will be lost.</p><p>When using event sourcing, developers do not need to worry about failing messages. So here, the messages aren’t pushed to Kafka consumers. Kafka consumers pull, and it is easier to implement this pull pattern.</p><h3><strong>6. Eliminate service coupling</strong></h3><p>Imagine a situation where we have customer service helping a few other services. If the customer service goes down, additional services will also go down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*-CGkGUtUwP-C9b01UyC4rg.png" /></figure><p>When using event sourcing, the approach is that the customer publishes and the other services consume. In such a case, if the customer service goes out, there is no harm until it gets back.</p><h3><strong>Conclusion</strong></h3><p>Microservices architecture is one of the commonly used architectures in backend development. However, it is crucial to know how to use it in a much optimized and hassle-free manner.</p><p>In this article, I have explained 06 reasons why you should use event soucing with microservice to avoid common pitfalls.</p><p>I hope this article will help you develop microservices in a much more optimized way. Thank you for reading.</p><h3>Bit: Feel the power of component-driven dev</h3><p>Say hey to <a href="https://bit.cloud/"><strong>Bit</strong></a>. It’s the #1 tool for component-driven app development.</p><p>With Bit, you can create any part of your app as a “component” that’s composable and reusable. You and your team can share a toolbox of components to build more apps faster and consistently together.</p><ul><li>Create and compose “<strong>app building blocks</strong>”: UI elements, full features, pages, applications, serverless, or micro-services. With any JS stack.</li><li>Easily <strong>share, and reuse</strong> components as a team.</li><li>Quickly <strong>update</strong> <strong>components</strong> across projects.</li><li>Make hard things simple: <a href="https://bit.cloud/blog/painless-monorepo-dependency-management-with-bit-l4f9fzyw">Monorepos</a>, <a href="https://blog.bitsrc.io/how-we-build-our-design-system-15713a1f1833">design systems</a> &amp; <a href="https://blog.bitsrc.io/how-we-build-micro-front-ends-d3eeeac0acfc">micro-frontends</a>.</li></ul><p><a href="https://bit.cloud/"><strong>Try Bit open-source and free→</strong></a></p><figure><a href="https://bit.cloud/"><img alt="" src="https://cdn-images-1.medium.com/max/376/1*p3UFa6xnmmbrkTzfRm_EmQ.png" /></a></figure><h3>Learn more</h3><ul><li><a href="https://blog.bitsrc.io/how-we-build-micro-front-ends-d3eeeac0acfc">How We Build Micro Frontends</a></li><li><a href="https://blog.bitsrc.io/how-we-build-our-design-system-15713a1f1833">How we Build a Component Design System</a></li><li><a href="https://bit.cloud/blog/how-to-reuse-react-components-across-your-projects-l3bhezsg">How to reuse React components across your projects</a></li><li><a href="https://bit.cloud/blog/painless-monorepo-dependency-management-with-bit-l4f9fzyw">Painless monorepo dependency management with Bit</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9755a54ebfb4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bitsrc/why-microservices-should-use-event-sourcing-9755a54ebfb4">Why Microservices Should use Event Sourcing</a> was originally published in <a href="https://medium.com/bitsrc">Bits and Pieces</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Homomorphic Encryption and Machine Learning]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://charuka95.medium.com/homomorphic-encryption-and-machine-learning-8ba407da129f?source=rss-6d47b99e463c------2"><img src="https://cdn-images-1.medium.com/max/2600/1*QOadxxT0DccQGEfZByu8yQ.jpeg" width="2880"></a></p><p class="medium-feed-snippet">How Machine learning + Homomorphic Encryption will revolutionize privacy-preserving techniques?</p><p class="medium-feed-link"><a href="https://charuka95.medium.com/homomorphic-encryption-and-machine-learning-8ba407da129f?source=rss-6d47b99e463c------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://charuka95.medium.com/homomorphic-encryption-and-machine-learning-8ba407da129f?source=rss-6d47b99e463c------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ba407da129f</guid>
            <category><![CDATA[homomorphic-encryption]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[data-privacy]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Charuka Herath]]></dc:creator>
            <pubDate>Wed, 15 Jun 2022 06:21:16 GMT</pubDate>
            <atom:updated>2022-06-15T06:21:16.860Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Babel vs. TypeScript in 2022]]></title>
            <link>https://medium.com/bitsrc/babel-vs-typescript-in-2022-b8e859a9fefc?source=rss-6d47b99e463c------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8e859a9fefc</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[babel]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Charuka Herath]]></dc:creator>
            <pubDate>Thu, 31 Mar 2022 09:02:30 GMT</pubDate>
            <atom:updated>2022-03-31T09:02:30.090Z</atom:updated>
            <content:encoded><![CDATA[<h4>What is the best Compiler for JavaScript?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*n2kRbPADewJS1QrL8HTwXg.jpeg" /></figure><p>Code splitting is widely used in JavaScript-based web development to improve the productivity and the maintainability of the code base with growth. However, we need to bundle and transpile these files when we execute them.</p><p>Bundling creates a set of optimized files by removing unused code snippets and transpiring converts all the new JavaScript syntaxes and features to ES5 syntax to make them backward compatible.</p><p>TypeScript and Babel are the two most used tools for Transpiling and Polyfilling, and this article will discuss the differences between them and help you choose the best for your project.</p><h3><strong>What is TypeScript?</strong></h3><p>TypeScript is one of the most used programming languages among web developers. It works as a linting layer on top of JavaScript and enforces types to help developers minimize common errors.</p><p>Most importantly, TypeScript has its own compiler. As a result, it can convert .ts files into .js files and makes it easier for browsers to execute them.</p><h3><strong>What is Babel?</strong></h3><p>Babel is another popular compiler that converts modern JavaScript syntax and features into ES5. It has significant features like syntax transformation, Polyfilling, code transformations.</p><p>Out of these, polyfilling is one of the most valuable features, and it makes sure that your application is universally compatible across different browser versions.</p><p>Furthermore, Babel supports the latest version of JavaScript through syntax transformers and allows developers to use new syntax without waiting for browser support.</p><h3><strong>Understand the Differences</strong></h3><p>Although Babel and TypeScript are compilers, they have some significant differences. Understanding these differences will help you find the best compiler for your project.</p><h4><strong>1. Type checking is not available in Babel</strong></h4><p>Typescript is strongly typed, which means developers can check the validity of their variable values. However, Babel compiles codes without checking the types.</p><pre>var typeCheckString : string = 11111;</pre><p>The above code will compile in Babel without any errors. But in TypeScript, you will see a type error like the below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*8_nwaY2R68t01Ok1_MU0sg.png" /></figure><p>When the types are not correctly initialized, removing types and compiling the code is a quick method to emit JS. But, if the developers need to use the correct types, it is essential to cross-check them.</p><p>Since Babel does not type-check your code, it has a faster emit time. However, you can also configure TypeScript without type checking by running the tsc -- noEmit command.</p><h4><strong>2. Auto polyfill is not available in TypeScript</strong></h4><p>Babel includes a polyfill that has a custom regenerator runtime and core-js. This will emulate a complete ES5+ environment to be used in applications rather than a library/tool. So, a polyfill is automatically loads when using Babel.</p><p>TypeScript only downgrades some language features when targeting earlier ECMAScript versions. The syntax is the main norm used to determine if a feature will be emitted as a downgraded code or if it needs a polyfill. If the new language feature is syntactically invalid in the targeted JS version, it will be downgraded, or you will get a compile-time warning.</p><h4>3. Babel is more extensible than TypeScript</h4><p>If you need to use custom transformation, Babel is the best solution. It supports a variety of plugins to optimize your code, while TypeScript only supports its own Transformer API with lesser features.</p><h4>4. Use of decorators</h4><p>Decorator support is one of the highlighted features in TypeScript. However, the decorator proposal for JavaScript is not yet finalized, and there are some mismatches between ECMAScript spec and TypeScript about decorator behaviors.</p><p>So, able does not compile the decorators similar to TypeScript, and we have to use the legacy mode. The legacy mode will compile decorators with old behavior, and we need to use @babel/plugin-proposal-decorators plugin and set the legacy option to true in the config file.</p><h4>5. Identical performance</h4><p>When it comes to performance, both TypeScript and Babel are identical. Although TypeScript takes some additional time for type checking, it does not significantly affect performance. Also, there are third-party plugins like <a href="https://github.com/TypeStrong/fork-ts-checker-webpack-plugin">fork-ts-checker-webpack-plugin</a> to speed up the type checking process.</p><h3><strong>What should you choose?</strong></h3><p>As discussed, both the TypeScript compiler and Babel have their own way of handling things. So, developers have many opinions, and choosing one over the other can be a challenging task.</p><p>With the latest update of Babel, it has improved a lot, and the only disadvantage I see is its inability to do type checks. You need to use s custom process for that. With all the other aspects, both Babel and TypeScript compiler seem similar, and that’s why many developers suggest using them together.</p><h3>Build composable web applications</h3><p>Don’t build web monoliths. Use <a href="https://bit.dev/"><strong>Bit</strong></a> to create and compose decoupled software components — in your favorite frameworks like React or Node. Build scalable and modular applications with a powerful and enjoyable dev experience.</p><p>Bring your team to <a href="https://bit.cloud/"><strong>Bit Cloud</strong></a> to host and collaborate on components together, and speed up, scale, and standardize development as a team. Try <strong>composable frontends</strong> with a <strong>Design System</strong> or <strong>Micro Frontends</strong>, or explore the <strong>composable backend</strong> with <strong>serverside components</strong>.</p><p><a href="https://bit.dev/"><strong>Give it a try →</strong></a></p><figure><img alt="https://cdn-images-1.medium.com/max/800/1*ctBUj-lpq4PZpMcEF-qB7w.gif" src="https://cdn-images-1.medium.com/proxy/1*ctBUj-lpq4PZpMcEF-qB7w.gif" /></figure><h3>Conclusion</h3><p>Having Babel and TypeScript do part of the source transform seems unnecessarily complicated. So, if you are using both, it is better to use Babel for transpiling and the TypeScript compiler for type checking.</p><p>The TypeScript documentation also recommends this approach, and it is widely used for projects that may have been ported from JavaScript to TypeScript.Here, you can use Babel’s <a href="https://babeljs.io/docs/en/babel-preset-typescript">preset-typescript</a> to generate your JS files, and then use TypeScript to do type checking and .d.ts file generation.</p><p>However, if your build output is similar to the source files, it is better to use TypeScript to make things simpler.</p><h3>Learn More</h3><ul><li><a href="https://blog.bitsrc.io/how-we-build-micro-front-ends-d3eeeac0acfc">How We Build Micro Frontends</a></li><li><a href="https://blog.bitsrc.io/how-we-build-our-design-system-15713a1f1833">How we Build a Component Design System</a></li><li><a href="https://blog.bitsrc.io/the-composable-enterprise-a-guide-609443ae1282">The Composable Enterprise: A Guide</a></li><li><a href="https://blog.bitsrc.io/7-tools-for-faster-frontend-development-in-2022-43b6f663c607">7 Tools for Faster Frontend Development in 2022</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8e859a9fefc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bitsrc/babel-vs-typescript-in-2022-b8e859a9fefc">Babel vs. TypeScript in 2022</a> was originally published in <a href="https://medium.com/bitsrc">Bits and Pieces</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Atomic Design in Modern React Development]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://charuka95.medium.com/implementing-atomic-design-in-modern-react-development-d58d743a0f0b?source=rss-6d47b99e463c------2"><img src="https://cdn-images-1.medium.com/max/2600/1*1udIFcyWMbfzgTfFKUQYJw.jpeg" width="2880"></a></p><p class="medium-feed-snippet">Using Atomic Design principals with component libraries for modern web development</p><p class="medium-feed-link"><a href="https://charuka95.medium.com/implementing-atomic-design-in-modern-react-development-d58d743a0f0b?source=rss-6d47b99e463c------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://charuka95.medium.com/implementing-atomic-design-in-modern-react-development-d58d743a0f0b?source=rss-6d47b99e463c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d58d743a0f0b</guid>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[atomic-design]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Charuka Herath]]></dc:creator>
            <pubDate>Thu, 23 Sep 2021 19:16:20 GMT</pubDate>
            <atom:updated>2021-10-10T04:47:29.028Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Building realtime React Applications using Reactron]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/sysco-labs/building-realtime-react-applications-using-reactron-a14893b792e8?source=rss-6d47b99e463c------2"><img src="https://cdn-images-1.medium.com/max/2600/1*MXvbL0feT0hWHNXArMRm1g.jpeg" width="2880"></a></p><p class="medium-feed-snippet">Manage and test React apps in a visualized environment.</p><p class="medium-feed-link"><a href="https://medium.com/sysco-labs/building-realtime-react-applications-using-reactron-a14893b792e8?source=rss-6d47b99e463c------2">Continue reading on Sysco LABS Sri Lanka »</a></p></div>]]></description>
            <link>https://medium.com/sysco-labs/building-realtime-react-applications-using-reactron-a14893b792e8?source=rss-6d47b99e463c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a14893b792e8</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[reactron]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Charuka Herath]]></dc:creator>
            <pubDate>Wed, 01 Sep 2021 11:33:38 GMT</pubDate>
            <atom:updated>2021-09-01T11:33:38.171Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Using BLoC Pattern with React]]></title>
            <link>https://medium.com/bitsrc/using-bloc-pattern-with-react-cb6fdcfa623b?source=rss-6d47b99e463c------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb6fdcfa623b</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[web-design]]></category>
            <dc:creator><![CDATA[Charuka Herath]]></dc:creator>
            <pubDate>Tue, 27 Jul 2021 16:41:09 GMT</pubDate>
            <atom:updated>2025-03-04T14:57:37.126Z</atom:updated>
            <content:encoded><![CDATA[<h4>Make Your Business Logic Independent From UI Components</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_x7UbeBdjCqJd3oA5ADpUg.jpeg" /></figure><p>Initially, the Business Logic Component (BLoC) pattern was introduced by Google as a solution to handle states in Flutter applications. It allows you to reduce the workload on UI components by separating the business logic from them.</p><p>Over time, other frameworks also started to support the BLoC pattern. And, in this article, I will discuss how we can use this BLoC pattern with React.</p><h3>Benefits of Using BLoC Pattern with React</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BaiP-jhLnxgXA1XSU8YY_A.jpeg" /><figcaption>BLOC architecture diagram</figcaption></figure><p>The concept behind the BLoC pattern is straightforward. As you can see in the above figure, business logic will be separated from UI components. First, they will send events to the BLoC using an observer. And then, after processing the request, UI components will be notified by the BLoC using observables<em>.</em></p><p>So, let’s look at the advantages of this approach in detail.</p><figure><a href="https://bit.cloud/"><img alt="Build in AI speed — Compose enterprise-grade applications, features, and components" src="https://cdn-images-1.medium.com/max/1024/1*yX0vq3scSudyT61IuWFuEg.png" /></a><figcaption>Build in AI speed — Compose enterprise-grade applications, features, and components</figcaption></figure><h4>1. Flexibility to update application logic</h4><p>When the business logic is standalone from UI components, the impact on the application will be minimum. You will be able to change the business logic any time you want without affecting the UI components.</p><h4>2. Reuse logic</h4><p>Since the business logic is in one place, UI components can reuse logic without duplicating the code so that the simplicity of the app will increase.</p><h4>3. Ease of testing</h4><p>When writing test cases, developers can focus on the BLoC itself. So the code base is not going to be messed up.</p><h4>4. Scalability</h4><p>Over time, application requirements may change, and business logic can keep growing. In such situations, developers can even create multiple BLoCs to maintain the clarity of the codebase.</p><p>Moreover, BLoC patterns are platform<em> </em>and environment independent so that developers can use the same BLoC pattern in many projects.</p><h3>Concept into Practice</h3><p>Let’s build a small counter app to demonstrate the usage of the BLoC pattern.</p><h4>Step 01: Create a React application and structure it.</h4><p>First, we need to start by setting up a React app. I will name it bloc-counter-app. Also, I will be using rxjs as well.</p><pre>// Create React app<br>npx create-react-app bloc-counter-app</pre><pre>// Install rxjs<br>yarn add rxjs</pre><p>Then you need to remove all unnecessary code and structure the application as follows.</p><ul><li>Blocs — Keep all the bloc classes we need.</li><li>Components — Keep the UI components.</li><li>Utils — Keep utility files of the project.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*NGsidZ0MP3iREtYL1mDHUg.png" /><figcaption>Solder Structure</figcaption></figure><h4>Step 02: Implementation of the BLoC.</h4><p>Now, let’s implement the BLoC class. The BLoC class will be responsible for implementing all subjects related to business logic. In this example, it is responsible for the counter logic.</p><p>So, I have created a file named CounterBloc.js inside the bloc directory and used a pipe to pass the counter to the UI components.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ee9006cf075ab90a6a9cb1db6f42a5a/href">https://medium.com/media/3ee9006cf075ab90a6a9cb1db6f42a5a/href</a></iframe><p>As you can see, there is simple logic in this class. However, when an app grows in size, imagine the complexity if we do not separate the business logic.</p><h4>Step 03: Adding more beauty to the BLoC by an intermediate class.</h4><p>In this step, I will create the StreamBuilder.js inside the utils directory to handle the counter request from the UI. Moreover, developers can handle errors and implement customer handlers within this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ce2b5fde1c224859a73dfb94ca5e07b/href">https://medium.com/media/5ce2b5fde1c224859a73dfb94ca5e07b/href</a></iframe><p>In the AsyncSnapshot class, we can initialize a constructor, handle our data (check availability, etc. ), and handle errors. But in this example, I have only returned the data for ease of demonstration.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0268c8c56a400864e268979785794286/href">https://medium.com/media/0268c8c56a400864e268979785794286/href</a></iframe><p>The initial data is passed into AysncSnapshot class and stored in the snapshot state for each subscription. Then it will get rendered in the UI components.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6feee543b89ed3bc28c211845bfc79cd/href">https://medium.com/media/6feee543b89ed3bc28c211845bfc79cd/href</a></iframe><blockquote><strong>Note:</strong> Ensure to unsubscribe from all the observables and dispose of the BLoCs upon unmounting UI components.</blockquote><h4>Step 04: Implementing UI components.</h4><p>As you can see now, increase() and decrease() methods are called directly within the UI component. However, output data is handle by a stream builder.</p><blockquote>It is better to have an intermediate layer to implement custom handlers to handle errors.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ffe5e6a8b132e773a707983ed0a45829/href">https://medium.com/media/ffe5e6a8b132e773a707983ed0a45829/href</a></iframe><p>In the app.js file, the BLoC is initialized using the CounterBloc class. Thus, the Counter component is used by passing the BLoC as a prop.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3f7cdb741cbea23867eed6a7008f11f/href">https://medium.com/media/c3f7cdb741cbea23867eed6a7008f11f/href</a></iframe><p>That’s it. Now you can treat your business logic as a separate entity outside your UI components and change it as you need.</p><p>To use and improve this example app please refer to the project <a href="https://github.com/Charuka09/react-counter-bloc">repository</a> and do not forget to make a PR. 😃</p><h3>Final Thoughts</h3><p>Based on my experience, the BLoC pattern could become an overhead for small-scale projects.</p><blockquote>But, as the project grows, using BLoC patterns helps to build modular applications.</blockquote><p>Also, you must have a basic understanding of rxjs and how observables work to implement the BLoC pattern for your React projects.</p><p>So, I invite you to try out BLoC pattern and share your thoughts in the comment section.</p><p>Thank you for Reading !!!</p><h3>Build better Component Libs and Design Systems</h3><p>Share components across teams and projects to speed up development and make sure your users experience a consistent design at every touchpoint.</p><p>OSS Tools like <a href="https://bit.dev/">Bit</a> offer a great dev experience for building, sharing, and adopting components across teams and applications. Create a component hub for free <a href="https://github.com/teambit/bit">give it a try →</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*N5fUmljTtoa_XT_f.png" /><figcaption>An independently source-controlled and shared “card” component (on the right, its dependency graph, auto-generated by Bit)</figcaption></figure><h3>Read More</h3><ul><li><a href="https://blog.bitsrc.io/independent-components-the-webs-new-building-blocks-59c893ef0f65">Bit Components: The Web’s New Building Blocks</a></li><li><a href="https://blog.bitsrc.io/redux-free-state-management-with-jotai-2c8f34a6a4a">Redux-free state management with Jotai</a></li><li><a href="https://blog.bitsrc.io/middleware-for-the-async-flow-in-redux-175256668981">Middleware for the Async Flow in Redux</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb6fdcfa623b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bitsrc/using-bloc-pattern-with-react-cb6fdcfa623b">Using BLoC Pattern with React</a> was originally published in <a href="https://medium.com/bitsrc">Bits and Pieces</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why is NanoID Replacing UUID?]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/bitsrc/why-is-nanoid-replacing-uuid-1b5100e62ed2?source=rss-6d47b99e463c------2"><img src="https://cdn-images-1.medium.com/max/2600/1*o7-WnAbmlrLnDmfRhl3opQ.jpeg" width="2880"></a></p><p class="medium-feed-snippet">A Tiny, URL-Friendly Unique String Generator for JavaScript.</p><p class="medium-feed-link"><a href="https://medium.com/bitsrc/why-is-nanoid-replacing-uuid-1b5100e62ed2?source=rss-6d47b99e463c------2">Continue reading on Bits and Pieces »</a></p></div>]]></description>
            <link>https://medium.com/bitsrc/why-is-nanoid-replacing-uuid-1b5100e62ed2?source=rss-6d47b99e463c------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b5100e62ed2</guid>
            <category><![CDATA[nanoid]]></category>
            <category><![CDATA[uuid]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Charuka Herath]]></dc:creator>
            <pubDate>Tue, 29 Jun 2021 16:41:41 GMT</pubDate>
            <atom:updated>2025-03-05T12:39:49.804Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Web Development in 2021: Dynamic vs. Static vs. Single-Page Architecture]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/better-programming/web-development-in-2021-dynamic-vs-static-vs-single-page-architecture-399d0c3defe6?source=rss-6d47b99e463c------2"><img src="https://cdn-images-1.medium.com/max/1497/1*ZS7eve8C4O7O5_Gt5sdzNw.png" width="1497"></a></p><p class="medium-feed-snippet">Know the architecture that best suits your website</p><p class="medium-feed-link"><a href="https://medium.com/better-programming/web-development-in-2021-dynamic-vs-static-vs-single-page-architecture-399d0c3defe6?source=rss-6d47b99e463c------2">Continue reading on Better Programming »</a></p></div>]]></description>
            <link>https://medium.com/better-programming/web-development-in-2021-dynamic-vs-static-vs-single-page-architecture-399d0c3defe6?source=rss-6d47b99e463c------2</link>
            <guid isPermaLink="false">https://medium.com/p/399d0c3defe6</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Charuka Herath]]></dc:creator>
            <pubDate>Tue, 20 Apr 2021 07:50:56 GMT</pubDate>
            <atom:updated>2021-04-20T07:50:56.693Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Building Microfrontends Using Single-SPA Framework]]></title>
            <link>https://medium.com/bitsrc/building-microfrontends-using-single-spa-framework-94019ca2fb4d?source=rss-6d47b99e463c------2</link>
            <guid isPermaLink="false">https://medium.com/p/94019ca2fb4d</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Charuka Herath]]></dc:creator>
            <pubDate>Tue, 06 Apr 2021 23:05:05 GMT</pubDate>
            <atom:updated>2023-06-11T08:44:49.804Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building Micro Frontends Using Single-SPA Framework</h3><h4>Step-by-step guide to developing Micro frontends using JavaScript router framework</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oA3eTuUFNoHts4goNQOM-g.jpeg" /></figure><p>Modern web apps are becoming more and more complex over time. It makes it challenging to release software quickly without sacrificing quality.</p><p>As a solution, <a href="https://blog.bitsrc.io/creating-seamless-user-experiences-a-comprehensive-guide-to-micro-frontend-architectural-patterns-9118a70386b7">Micro frontends</a> came into the picture with the objective of building, testing, and deploying pieces of the frontend independently.</p><p>In this article, I will show you the steps of developing a Micro frontend App using single-SPA.</p><blockquote><strong>Also watch this demo showing how to extract a feature as an independent component and integrating it back as an MFE in runtime and build time:</strong></blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FzBuBlExo3xA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DzBuBlExo3xA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FzBuBlExo3xA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/498daab38d12fea3093ca743e25a26b3/href">https://medium.com/media/498daab38d12fea3093ca743e25a26b3/href</a></iframe><h3>Introduction to Single-SPA</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4gdF_0upZcewy7o4B3atsQ.png" /><figcaption>Screenshot by the Author</figcaption></figure><blockquote>“Single-SPA is a JavaScript framework for building, testing, and deploying multiple JavaScript Micro frontends independently in a single frontend application.”</blockquote><p><a href="https://single-spa.js.org/">Single-SPA</a> Apps consist of two main parts:</p><ul><li><strong>The container App — single-SPA-root-config</strong></li></ul><p>The container App is responsible for rendering the HTML page <em>and</em> the JavaScript that applications(second part).</p><ul><li><strong>Applications</strong></li></ul><p>Single-page applications are packaged up into modules and combine with the container app. These applications can be built on top of different frameworks and libraries such as React, Angular, Vue, Ember, etc. However, each application should know how to load mount and unmount itself from the DOM.</p><p><strong>Also read:</strong></p><p><a href="https://blog.bitsrc.io/module-federation-vs-single-spa-47da53b67ed0">Module Federation vs Single-SPA</a></p><h3>Architecture</h3><h4>Runtime MFs vs Build-time MFs</h4><p>In my demo app, I will have three Micro frontends: the App header, home page, and a test page. All three Microfrontends are independent React applications.</p><p>Using the Single SPA framework acts as a container to compose these Micro frontends at <strong>runtime</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5PcRhmFCLu6QcUC9F61wTg.png" /><figcaption>Application Architecture</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ucfh_lOhsE98bzI1rVrEcQ.png" /><figcaption>Graphical view</figcaption></figure><p>Even though I chose a runtime composition of MFs, it is important to note that a composition of <a href="https://blog.bitsrc.io/independent-components-the-webs-new-building-blocks-59c893ef0f65">independent micro-apps</a> during build-time is still a valid solution. In many cases, it even makes more sense than the alternatives.</p><p>You can read more about build-time MFs, in Bit’s blog post about <a href="https://blog.bitsrc.io/how-we-build-micro-front-ends-d3eeeac0acfc">building their product with MFs</a> using their own tool — <a href="https://bit.dev/">Bit</a>.</p><p><a href="https://bit.dev/blog/bit-components-build-time-and-runtime-consumption-lgmaprww/">Bit Components: Build Time and Runtime Consumption</a></p><figure><a href="https://bit.dev/harmony-mfe/scopes"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZWfLw6QnGxExakxKQLKrYA.png" /></a></figure><figure><a href="https://bit.dev/harmony-mfe/people/ui/pages/user-profile"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*urm47jYcmkosHw6zWga-Vw.png" /></a><figcaption>Example: The dependency graph of a Micro Frontend (showing other components developed in the same Bit workspace)</figcaption></figure><h3>Step-by-Step Guide</h3><h4>Step 01: Creating the Root Configuration Application</h4><p>First, we need to start by setting up the Root configuration application using<br>create-single-SPA CLI tool, which is provided by Single-SPA.</p><pre>npm install -g create-single-spa<br>yarn global add create-single-spa</pre><blockquote>However, it is not mandatory to install create-single-spa globally.</blockquote><p>Next, create the root configuration App using the following commands.</p><pre>//create a directory for the App<br>mkdir single-spa-demo-root-config<br>cd single-spa-demo-root-config</pre><pre>//initializing the single-SPA<br>npx create-single-spa</pre><p>After running these commands, you will need to config the single-SPA as the root config application. So, you can choose the given options as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a1bpMcF--GkFtJ9misU0HQ.png" /><figcaption>Configuring the APP</figcaption></figure><ul><li>Keep the <strong>directory</strong> for the new project as the current directory.</li><li>Select single-SPA roof config (out of the three options appear) as the <strong>type to generate</strong>.</li><li>Select the <strong>package manager</strong> (yarn or npm). Here I chose yarn.</li><li>I only selected <strong>JavaScript</strong> for the project language.</li><li>Since this APP will be a simple single-SPA, I do not choose the <strong>Layout Engine</strong>.</li><li>You can give any name to your <strong>Organization name</strong>.</li></ul><p>Then relevant application setup will be configured, and you are good to go.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*ICtjspCnpckej42goaxv2g.png" /><figcaption>The folder structure of the APP</figcaption></figure><blockquote><strong>charuka95-root-config.js: </strong>File, which will be used to register all Microfrontends using in the application.</blockquote><blockquote><strong>Index.ejs:</strong> he file which will be using as an index.html file after compilation. The file keeps common modules that can be used by different applications, navigation codes, etc.</blockquote><p>Run yarn start , and the App will start to serves locally on the browser port 9000.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I8DKdAMIqKiF0zfDR5BxaQ.png" /><figcaption>Single-SPA root config App</figcaption></figure><h4>Step 02: Registering Three Applications</h4><p>Here we are using the same commands we used to initialize the root-config application except selecting single-SPA roof config as the type to select. Instead, select single-SPA application/parcel and give appropriate project names.</p><blockquote><strong>Note: </strong>organization name should be the same name which used in the root-config App configuration.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*332i7EHJo4q76-sPP-6YhA.png" /><figcaption>Creating single-SPA for header APP</figcaption></figure><p>Here, I have created 03 new folders for the header, home, and the test page in the root folder for my Microfrontends and initialize three react single-SPA applications for each.</p><p>The final file structure for the Microfrontends APP can be seen below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*gfA72loiX7CULkneWj6_3A.png" /><figcaption>Final file structure for the APP</figcaption></figure><p>Then three Apps can be served at 03 separate ports.</p><pre>yarn start --port 9001<br>yarn start --port 9002<br>yarn start --port 9003</pre><h4>Step 03: Configuring the Root App — Add Shared Dependencies</h4><p>Navigate into the root-config App in the browser and find below two lines of code and add them into the systemjs-import map import map in the root-config project’s index.ejs file.</p><pre>&quot;react&quot;: &quot;https://cdn.jsdelivr.net/npm/react@16.13.1/umd/react.production.min.js&quot;,<br>&quot;react-dom&quot;: &quot;https://cdn.jsdelivr.net/npm/react-dom@16.13.1/umd/react-dom.production.min.js&quot;</pre><blockquote>“Here, we add entries for modules that will be shared across your dependencies. For example, a React application generated with create-single-SPA will need to add React and ReactDOM to the import map.”</blockquote><p>The output can be seen as below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*94aunx6K-UTgjCtFanHTsw.png" /><figcaption>index.ejs file</figcaption></figure><h4>Step 04: Register Applications</h4><p>First, navigate into one of your Microfrontend APPs. Here, I will take mine spa-demo-header as the first APP. Then, locate the package.json file and find and copy the project name. (Mine is @charuka95/spa-demo-home )</p><p>Go back to the root-config App and locate the @organization_name-root-config.js file(Mine ischaruka95-root-config.js ) Then copy and paste the <strong>registerApplication()</strong> function in the file.</p><pre>registerApplication({<br>    name: “@charuka95/spa-demo-home”,<br>    app: () =&gt; System.import(“@charuka95/spa-demo-home”),<br>    activeWhen: [“/”]<br>});</pre><blockquote>The <strong>registerApplication()</strong> function is the function that is responsible for registering Microfrontend Apps to single-SPA.</blockquote><p>There are three arguments in the function:</p><ol><li><strong>name</strong> Project identifier, which has a format of @organization/project</li><li><strong>app</strong>: SystemJS import call that makes a call to the App in order which helps bring into the root-config application.</li><li><strong>activeWhen</strong>: Manage when the single-SPA application should be activated or deactivated.</li></ol><h4>Step 05: Add the Single-SPA Application into the Import Map</h4><p>Finally, locate back the index.ejs file in the root-config app and add the registered Microfrontend App to the import map of the root-config App.</p><pre>“@charuka95/root-config”:“//localhost:9000/charuka95-root-config.js”</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yicFItKSCUT8d98DHhbJrA.png" /><figcaption>Add the single-SPA application into the import map</figcaption></figure><p>After that, you need to follow steps 04 and step 05 for all other Microfrontend applications.</p><blockquote>And <strong>BOOM</strong> you are done!!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3IjIi-rfPdhnYqpnqar-xw.png" /><figcaption>Final output in the browser</figcaption></figure><p>You can clone the full code from my project repositories listed below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3mcDzeAHqcsBA8OaagXy8w.png" /><figcaption>Final App</figcaption></figure><ul><li><a href="https://github.com/Charuka09/demo-microfrontend-app">spa-demo-app-root-config</a></li><li><a href="https://github.com/Charuka09/spa-demo-header">spa-demo-header</a></li><li><a href="https://github.com/Charuka09/spa-demo-home">spa-demo-home</a></li><li><a href="https://github.com/Charuka09/spa-demo-test-page">spa-demo-test-page</a></li></ul><h3>Summary</h3><p>As we saw throughout the article, there are a massive amount of benefits such as:</p><ul><li>Can be to handle each Microfrontend independently.</li><li>Can deploy independently.</li><li>Ownerships can be distributed.</li><li>Testing is faster than the traditional approaches.</li><li>Each Microfrontend can use a framework of choice.</li></ul><p>However, the main challenge here is the upfront efforts to create the structure of the application.</p><blockquote><em>💡 </em>Note: You could use<em> </em><a href="https://bit.cloud/"><strong>Bit</strong></a> to make this easier. Bit provides an <a href="https://bit.dev/docs/getting-started/composing/dev-environments/"><strong>integrated dev environment</strong></a> (compiler, tester, linter, documentation, CI, dev server, and packaging/dependency management/bundler all-in-one) for building applications. With Bit, you can easily <a href="https://bit.dev/docs/getting-started/composing/creating-components/"><strong>create</strong></a>,<strong> </strong><a href="https://bit.dev/blog/-extracting-and-reusing-pre-existing-components-using-bit-add-l28qlxpz/"><strong>share, and reuse components</strong></a>, making it easier to maintain and update your microfrontend architecture.</blockquote><h4>Learn more:</h4><ul><li><a href="https://blog.bitsrc.io/leveraging-microfrontend-architecture-using-bit-components-3cd4d0b1d34e">Leveraging Microfrontend Architecture Using Bit Components</a></li><li><a href="https://blog.bitsrc.io/how-we-build-micro-front-ends-d3eeeac0acfc">How We Build Micro Frontends</a></li></ul><p>Thank you for reading. Feel free to leave a comment down below and share your experience.</p><h4>Build Microfrontends with reusable components</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*lRXC6qrZExpbTnNj.png" /></figure><p><a href="https://bit.cloud/"><strong>Bit</strong></a><strong>’s open-source tool </strong>help 250,000+ devs to build apps with components.</p><p>Turn any UI, feature, or page into a <strong>reusable component</strong> — and share it across your applications. It’s easier to collaborate and build faster.</p><p><strong>→ </strong><a href="https://bit.dev/"><strong>Learn more</strong></a></p><p>Split apps into components to make app development easier, and enjoy the best experience for the workflows you want:</p><h4>→ <a href="https://blog.bitsrc.io/how-we-build-micro-front-ends-d3eeeac0acfc">Micro-Frontends</a></h4><h4>→ <a href="https://blog.bitsrc.io/how-we-build-our-design-system-15713a1f1833">Design System</a></h4><h4>→ <a href="https://bit.cloud/blog/how-to-reuse-react-components-across-your-projects-l4pz83f4">Code-Sharing and reuse</a></h4><h4>→ <a href="https://www.youtube.com/watch?v=5wxyDLXRho4&amp;t=2041s">Monorepo</a></h4><h4>Learn More</h4><ul><li><a href="https://blog.bitsrc.io/creating-a-developer-website-with-bit-components-3f4083a7f050">Creating a Developer Website with Bit components</a></li><li><a href="https://blog.bitsrc.io/mastering-component-driven-development-improving-maintainability-and-collaborative-efficiency-6ee4b3dc5de7">Mastering Component-Driven Development: Improving Maintainability and Collaborative Efficiency</a></li><li><a href="https://blog.bitsrc.io/independent-components-the-webs-new-building-blocks-59c893ef0f65">Bit Components: The Web’s New Building Blocks</a></li><li><a href="https://blog.bitsrc.io/how-we-build-micro-front-ends-d3eeeac0acfc">How We Build Micro Frontends</a></li><li><a href="https://blog.bitsrc.io/how-to-develop-microfrontends-using-react-step-by-step-guide-47ebb479cacd">How to Develop Microfrontends Using React: Step by Step Guide</a></li><li><a href="https://blog.bitsrc.io/how-we-build-our-design-system-15713a1f1833">How we Build a Component Design System</a></li><li><a href="https://bit.dev/blog/how-to-reuse-react-components-across-your-projects-l4pz83f4/">How to reuse React components across your projects</a></li><li><a href="https://bit.dev/blog/how-to-create-a-composable-react-app-with-bit-l7ejpfhc/">How to Create a Composable React App with Bit</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94019ca2fb4d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bitsrc/building-microfrontends-using-single-spa-framework-94019ca2fb4d">Building Microfrontends Using Single-SPA Framework</a> was originally published in <a href="https://medium.com/bitsrc">Bits and Pieces</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Will React Server Components Replace SSR?]]></title>
            <link>https://medium.com/better-programming/will-react-server-components-replace-ssr-f2f772347109?source=rss-6d47b99e463c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f2f772347109</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Charuka Herath]]></dc:creator>
            <pubDate>Tue, 06 Apr 2021 17:19:41 GMT</pubDate>
            <atom:updated>2021-04-06T17:19:41.263Z</atom:updated>
            <content:encoded><![CDATA[<h4>The birth of React Server Components and their effect on SSR</h4><figure><img alt="Team creating app" src="https://cdn-images-1.medium.com/max/1024/1*ALXwcND3MAaJNI-pByP7vw.jpeg" /><figcaption>Photo by the author.</figcaption></figure><p><a href="https://reactjs.org/blog/2020/12/21/data-fetching-with-react-server-components.html">React Server Components</a> are a brand new feature that was recently introduced to React. It’s one of the most awaited features and allows you to use client and server components in harmony.</p><p>Though it’s still experimental, there is a lot to take away from its capabilities.</p><p>However, some of you might be thinking, “We already have server-side rendering (SSR), and here comes another alternative.”</p><h3>What About SSR?</h3><p>It’s important to understand that React server-side rendering and Server Components have different purposes.</p><p>React SSR is there to speed up the initial loading of the React application. To achieve that, SSR provides a mechanism to define what you need to show to the end-users as soon as they visit the application URL.</p><p>It could range from a loading icon to a content-filled page depending on the application’s UX (User Experience) requirements. But the interactions become active after bootstrapping the React application.</p><p>Still, you might be wondering why we need Server Components. Before answering that question, let’s find out more about them.</p><h3>React Server Components</h3><p>React’s new Server Components render on the server side.</p><p>You can even write a Server Component to fetch data from the database and render its content using Node.js. How cool is that?</p><p>You can also use Server Components and Client Components together in a single React application.</p><figure><img alt="Drawing of React Server Components and Client Components working together" src="https://cdn-images-1.medium.com/max/1024/1*vJMaop0HWzyr6YDEr9lXlg.jpeg" /><figcaption>React Server Components and Client Components working together</figcaption></figure><p>Let’s look at some of the other advantages that come with React Server Components.</p><h4>Control over JavaScript bundle size</h4><p>With Server Components, you will get better control over your bundle sizes. Let’s take an example. Suppose you have ten dependencies in your project. What if you only need to download five of them into the browser and the rest remain in the server?</p><p>You have the option to reduce some of the dependencies considering their size by moving them to Server Components.</p><h4>Zero-bundle-size components are possible</h4><p>What is most exciting is that, in some applications, you might not need to keep any of the dependencies in the browser. The bundle size will be smaller than ever.</p><h4>Increase code reuse</h4><p>Since you get the ability to choose the Client and Server Components, you get to choose the right one for the right job.</p><p>For example, you can choose a Server Component to render an invoice on the server side and show the preview while using the same output to generate a PDF.</p><p>You can also share JavaScript libraries with SSR and Server Components for specific use cases.</p><h4>Compatible with many JavaScript frameworks</h4><p>Server Components were developed from the start to be used with any JavaScript meta-framework, such as Next.js and Gatsby.</p><p>They allow developers to use a single language and a single framework to write an application. Most importantly, developers can share code across both the server and client.</p><h4>Reuse Client and Server Components across projects</h4><p>You can also share both Client and Server Components using the <a href="https://bit.dev/">Bit</a> open source platform across multiple projects. It will help to maximize code reuse and keep a consistent design across the product portfolio.</p><p>However, if you are already using a Bit collection, you can create a separate collection for Server Components supporting Node.js.</p><p>This, way you can keep them separated and define where to inject them into the Server Component tree in any of your projects.</p><h4>Known limitations</h4><p>Though Server Components are brand new, the React team has done a remarkable job of prioritizing this much-needed feature. However, there are some limitations that you should know about.</p><p>In some cases, it’s not possible to place all the components as Server-Only Components. Also, the lack of support with React Hooks (useState(), useEffect()) will limit their adoption for specific use cases.</p><p>Since the feature is new, there are several optimizations to be addressed with Server Components.</p><p>For example, currently, the same code is re-run and components will re-render on every request.</p><p>Also, Server Components require a considerable amount of attention to work out, including routing and re-fetching. So it is premature to think about how a “current SPA” can be ported to them. They have essential implications on architecture and are not precisely drop-in.</p><h3>Server Components, SSR, or Both?</h3><p>As you are already aware, Server Components and SSR are complementary to each other.</p><p>If we look at SSR closely, we can instruct the webserver to render a component upon loading a single page. For example, if we use Node.js, we can install the ‘react-dom/server’ NPM library and use it to render the App component:</p><pre>ReactDOMServer.renderToString(&lt;App /&gt;);</pre><p>As you can see, it’s a single-time operation. After the initial load of the application, we don’t have the luxury to render any other components from the server side.</p><p>Therefore, as I’ve explained before, SSR improves the initial page load time and shows an early output to the users — even before JavaScript bundles get loaded.</p><p>On the other hand, Server Components work in combination with React Client-Side Components (Identifying Client Component Tree and Server Component Tree). This happens after the JavaScript bundle gets loaded.</p><p>Moreover, there are differences in how they render content. For example, Server Components do not render HTML. They are rendered in a particular format similar to JSON.</p><pre>J0:{&quot;$&quot;,&quot;div&quot;,&quot;null&quot;,{&quot;className&quot;:&quot;main-class&quot;}}</pre><p>So let’s answer the burning question: Will Server Components replace SSR?</p><p>In short, no! I hope you already understand why.</p><p>Let’s look at a few places where you can consider using React Server Components:</p><ul><li>If the library we need for a particular component is heavy in size but not used in other places.</li><li>Complex components that take time to render in mobile devices.</li><li>Places where the code is reusable for the frontend and backend (e.g. PDF preview and download).</li></ul><p>On the other hand, you still need to rely on SSR for the following:</p><ul><li>Initial loading, layout, or even rich content that users see until the React application is loaded.</li><li>SEO-friendly content.</li><li>Provide any seed data for React application to render instantly (e.g. logged-in user details) without server calls.</li></ul><p>So it’s important that you get the best of both worlds by using SSR and React Server Components.</p><figure><img alt="Table comparing Server Components to SSR" src="https://cdn-images-1.medium.com/max/1024/1*jSpGN1OATUHQwWjbdfqUnw.png" /><figcaption>Comparison between Server Components and SSR</figcaption></figure><p>However, in practice, you will still mostly use Client Components and SSR in your projects. You will only consider React Server Components in the places where it matters.</p><p>Thanks for reading! Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f2f772347109" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/will-react-server-components-replace-ssr-f2f772347109">Will React Server Components Replace SSR?</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>