<?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 Ryan Hoffnan on Medium]]></title>
        <description><![CDATA[Stories by Ryan Hoffnan on Medium]]></description>
        <link>https://medium.com/@hopemanryan?source=rss-4a80812e7382------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dbPh5-fX4wm2WqivjYncRQ.jpeg</url>
            <title>Stories by Ryan Hoffnan on Medium</title>
            <link>https://medium.com/@hopemanryan?source=rss-4a80812e7382------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 08:05:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hopemanryan/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[Imperative handlers the tricky parts]]></title>
            <link>https://itnext.io/imperative-handlers-the-tricky-parts-58b8e211b197?source=rss-4a80812e7382------2</link>
            <guid isPermaLink="false">https://medium.com/p/58b8e211b197</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[hooks]]></category>
            <dc:creator><![CDATA[Ryan Hoffnan]]></dc:creator>
            <pubDate>Mon, 12 Feb 2024 20:46:51 GMT</pubDate>
            <atom:updated>2024-02-12T23:00:33.702Z</atom:updated>
            <content:encoded><![CDATA[<p>Imperative handlers in React are a powerful tool for exposing a component’s functionality to the outside world. They essentially enable one component to control another component remotely by passing a reference (ref) to it.</p><p>To illustrate, consider the following code snippet. Here, we demonstrate a straightforward implementation where a component is designed to accept a ref as a prop. The component then forwards this ref to a button element, enabling external control over its behavior. This pattern is a classic example of imperative handling in React</p><h4><strong>For the next example please ignore Reacts re-render update time.</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P4lBlq_5mHPZ4iXe_lyPKw.png" /></figure><p>With the provided code snippet, we gain the ability to access the underlying HTML button element externally. This capability empowers the parent component to exercise control over the button’s click event from outside its immediate scope. Consequently, this approach enhances the overall functionality of our codebase, promoting a more functional programming paradigm over a reactive one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SIxu5yg5YDBH7Q8OnBqXwA.png" /></figure><p>While the approach of accessing the button element externally seems promising, it comes with its own set of challenges. One notable issue is that if there’s any logic tied to the click event, it won’t be triggered when the button is clicked from the HTML tag element. This discrepancy arises because the invocation bypasses the logic associated with the onClick function defined within MyComponent.</p><p>To address this issue, we turn to imperative handlers. In the following snippet, we introduce a hook called useImperativeHandle. This hook accepts the ref as its first parameter and returns a list of predefined functions accessible via the ref. In this particular case, we utilize the imperativeClick function.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Lqy-JVrLOHb0cCLsiUIwQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3-FJ0P9kdjR96iP6PAA1Kw.png" /></figure><p>Now, by employing imperative handlers, both MyComponent and any consumer utilizing its ref will execute the same logic. This alignment between the component&#39;s behavior and its external control offers significant benefits, reducing the need for duplicating logic across different parts of the application.</p><p>Consider the scenario where a component encapsulates complex logic that has already been implemented. Why rewrite the same logic multiple times when imperative handlers allow us to reuse it effectively?</p><p>However, when it comes to retrieving values from the ref component, the process is both straightforward and maybe confusing to some. The mechanism itself is simple but there are certain quirks to be mindful of during implementation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oSwMZ0eXazyMFspWubSUGg.png" /></figure><p>Observe that our getClickCount function returns the same value as before the click event. Why does this occur? Well, similar to useEffect, useMemo, and other hooks, useImperativeHandle also utilizes a dependency array, which is not automatically included in every code snippet.</p><p>This dependency array is crucial as it needs to encompass any values that the imperative handler references internally. By adding our count value to the dependency array, we unlock the magic. With this adjustment, each update to the count state triggers a corresponding update to the imperative handler, enabling us to retrieve the latest values accurately.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j1LIjNvy5MR1_gjB38MVsA.png" /></figure><h3>Overview in points:</h3><h4>The Good</h4><ol><li>Encapsulation of Logic: useImperativeHandle allows for the encapsulation of imperative functionality within a component. This promotes a cleaner separation of concerns, as imperative operations can be confined to specific components.</li><li>Controlled Exports: It enables components to selectively expose certain functions or properties to their parent components. This controlled export mechanism fosters a more structured and predictable interface between parent and child components.</li><li>Reusability: By exposing imperative functions through the ref, components can encapsulate complex logic and make it reusable across different parts of the application. This reduces code duplication and promotes maintainability.</li><li>Alignment with React’s Paradigm: Leveraging useImperativeHandle aligns with React&#39;s philosophy of declarative and functional programming. It encourages developers to favor explicit function calls over direct DOM manipulation, leading to more predictable and easier-to-maintain code.</li></ol><h4>The Bad</h4><ol><li>Complexity: Implementing useImperativeHandle can introduce additional complexity to the codebase, particularly when managing dependencies and ensuring proper synchronization between imperative functions and component state.</li><li>Potential for Abuse: While useImperativeHandle can be a powerful tool, misuse or overuse may lead to code that is harder to understand and maintain. Developers should exercise caution and consider whether imperative handling is truly necessary for a given use case.</li><li>Performance Concerns: Depending on the implementation, using imperative handlers may introduce performance overhead, especially if not optimized correctly. Developers should be mindful of potential performance implications and strive to optimize their code where possible.</li></ol><p>Performance concerns in React applications are a fascinating topic, especially when it comes to imperative handlers. While some concerns overlap with those of hooks that utilize dependency arrays, such as excessive rerenders and memory consumption, imperative handlers introduce unique challenges.</p><p>One of the standout issues is the storage of callbacks. Unlike objects, React doesn’t optimize the handling of functions. Yep, everything is technically an object in JavaScript, but storing unoptimized functions in imperative handlers can lead to memory leaks and sluggish performance. Therefore, it’s crucial to exercise caution when deciding what to export externally.</p><p>To ensure optimal performance, developers should be mindful of the callbacks and other resources stored in imperative handlers, keeping an eye on memory usage and overall application speed.</p><p>In essence, useImperativeHandle offers valuable control and reusability but should be approached with caution to avoid complexity and performance issues. Developers should prioritize efficiency and maintainability when utilizing imperative handlers in React applications.</p><p>Happy coding ! and watch out for useImperativeHandle</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58b8e211b197" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/imperative-handlers-the-tricky-parts-58b8e211b197">Imperative handlers the tricky parts</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Is React becoming opinionated ?]]></title>
            <link>https://itnext.io/is-react-becoming-opinionated-da5b99fe2641?source=rss-4a80812e7382------2</link>
            <guid isPermaLink="false">https://medium.com/p/da5b99fe2641</guid>
            <category><![CDATA[web]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Ryan Hoffnan]]></dc:creator>
            <pubDate>Sun, 27 Aug 2023 20:04:17 GMT</pubDate>
            <atom:updated>2023-08-27T20:46:15.033Z</atom:updated>
            <content:encoded><![CDATA[<h3>Is React becoming opinionated?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*i3Wmkb0SqHCrhJlRSIoj0Q.gif" /></figure><h4>What is an opinionated framework</h4><p>In simple terms, an opinionated framework is an ecosystem that if consumed by listening to the guidelines set by the ecosystem everything will work as expected.</p><p>The guidelines are there to remove the guess and grunt work and focus on bringing the product to the consumer’s hands as fast as possible. Sounds good right ? so why are people against it ? from my experience the <em>learning curve</em> is what makes people annoyed and as a result slows down the development. Many companies (mostly startups) decided to use React in order to develop fast and with as small as a learning curve there can be.</p><h4>Is React Becoming Opinionated?</h4><p>React has long been known as an “unopinionated” framework, meaning that it does not dictate how developers should structure their code or use third-party libraries. This has been one of React’s strengths, as it allows developers to have more flexibility and control over their projects.</p><p>However, in recent years, React has become more opinionated in some ways. For example, the official React documentation now recommends using Next.js or Remix for server-side rendering (SSR). These frameworks provide a number of features that can help developers build more efficient and scalable React applications, but they also come with a set of opinionated choices about how code should be structured and organized.</p><p>There are several reasons why React may be becoming more opinionated. One reason is that the React community has matured over the years, and there is now a wider range of third-party libraries and tools available. This can make it difficult for developers to choose the right tools for their projects, and opinionated frameworks can help to simplify this decision-making process.</p><p>Another reason for React’s increasing opinionatedness is that companies are increasingly looking for ways to reduce development costs and time to market. Opinionated frameworks can help to achieve these goals by providing developers with a pre-configured set of tools and libraries that are known to work well together.</p><p>Of course, there are also some potential downsides to using opinionated frameworks. For one, they can limit developers’ flexibility and creativity. Additionally, opinionated frameworks can be more difficult to learn and use, especially for developers who are new to React.</p><h4>Example of an opinion: Folder Tree as a Router</h4><p>One of the ways in which React is becoming more opinionated is through the use of folder trees as routers. This is a technique that is used by frameworks like Next.js and Remix to automatically generate routes based on the folder structure of your code.</p><p>For example, let’s say you have a folder called pages with two subfolders, home and about. If you were to use a folder tree router, then the route for the Home page would be /pages/home and the route for the About page would be /pages/about.</p><p>This technique can be very helpful for organizing your code and making it easy to navigate your application. It can also help to improve performance by reducing the number of requests that need to be made to the server.</p><p>However, it is important to note that folder tree routers can be restrictive. If you need to have a route that does not correspond to a folder in your code, then you will need to use a different routing strategy.</p><h4>Is this a good thing?</h4><p>That depends on your perspective. If you value flexibility and creativity, then you may be concerned about the increasing opinionatedness of React. However, if you are looking for ways to reduce development costs and time to market, then opinionated frameworks can be a valuable tool.</p><p>Ultimately, the decision of whether or not to use an opinionated framework is a personal one. There is no right or wrong answer, and the best choice for you will depend on your specific needs and preferences.</p><h4>So, what does all of this mean for the future of React?</h4><p>It is still too early to say for sure, but it is clear that React is evolving. The framework is becoming more opinionated, but it is also becoming more powerful and efficient. Only time will tell how React will continue to change in the years to come.</p><p>In the meantime, developers can continue to enjoy the benefits of React’s flexibility and creativity. They can also choose to use opinionated frameworks like Next.js and Remix if they are looking for ways to reduce development costs and time to market.</p><p>The future of React is bright, and it is an exciting time to be a React developer.</p><h4>Summary</h4><p>React is a popular JavaScript framework that has long been known for its flexibility and creativity. However, in recent years, React has become more opinionated in some ways. This has led to some debate about whether or not React is still the best choice for all developers.</p><p>There are several reasons why React may be becoming more opinionated. One reason is that the React community has matured over the years, and there is now a wider range of third-party libraries and tools available. This can make it difficult for developers to choose the right tools for their projects, and opinionated frameworks can help to simplify this decision-making process.</p><p>Another reason for React’s increasing opinionatedness is that companies are increasingly looking for ways to reduce development costs and time to market. Opinionated frameworks can help to achieve these goals by providing developers with a pre-configured set of tools and libraries that are known to work well together.</p><p>Of course, there are also some potential downsides to using opinionated frameworks. For one, they can limit developers’ flexibility and creativity. Additionally, opinionated frameworks can be more difficult to learn and use, especially for developers who are new to React.</p><p>Ultimately, the decision of whether or not to use an opinionated framework is a personal one. There is no right or wrong answer, and the best choice for you will depend on your specific needs and preferences.</p><p>If you value flexibility and creativity, then you may want to stick with using React in its unopinionated form. However, if you are looking for ways to reduce development costs and time to market, then an opinionated framework like Next.js or Remix may be a better choice for you.</p><p>The future of React is bright, and it is an exciting time to be a React developer. The framework is constantly evolving, and it will be interesting to see how it continues to change in the years to come.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da5b99fe2641" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/is-react-becoming-opinionated-da5b99fe2641">Is React becoming opinionated ?</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Signals — How far can we take it ? what are it’s limits]]></title>
            <link>https://itnext.io/signals-how-far-can-we-take-it-what-are-its-limits-f784abd37329?source=rss-4a80812e7382------2</link>
            <guid isPermaLink="false">https://medium.com/p/f784abd37329</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Ryan Hoffnan]]></dc:creator>
            <pubDate>Sun, 05 Mar 2023 18:49:01 GMT</pubDate>
            <atom:updated>2023-03-05T20:38:14.358Z</atom:updated>
            <content:encoded><![CDATA[<h3>Signals — How far can we take it ? what are it’s limits</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*tUk36TzQoLGqGzrYdfwx7A.png" /></figure><p>Signals the new kid on the block, it is literally a game changer by changing how applications render and re-redner data in components.<br>But how far can we go ? lets check out how far we can take this early stage solution and see its limitations. We will be looking at both React and Angular (master, not the angular-signal branch)</p><h3>React is pretty simple</h3><h4>Can Signals store basic components?</h4><p>TLDR: Yes<br>Storing simple React components inside A Signal is possible. and even changing them in runtime works as expected. nothing special.</p><pre>const Comp1 = () =&gt; {<br>    return &lt;&gt;Hello world comp 1&lt;/&gt;<br>}<br>const Comp2 = () =&gt; {<br>    return &lt;&gt;Hello world comp 2&lt;/&gt;<br>}<br><br><br>let signalComponent = signal(Comp1)<br>function App() {<br>  return (<br>    &lt;div className=&quot;App&quot;&gt;<br>        {signalComponent.value()}<br>        &lt;button onClick={() =&gt; signalComponent.value = Comp2}&gt;Switch&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><p>Since a component is a function and we want to render the UI only on demand, we will trigger the component function in the html. notice how we access the .value in order to register it as a listener and enjoy the change detection changes.</p><h4>Can Signals Store complex (with Hooks) components</h4><p>TLDR: No…. its complex</p><p>Hooks are triggered as life cycle event, changing the value of the signal doesn’t trigger it unfortunately</p><pre>function App() {<br><br>    const Comp1 = () =&gt; {<br>        useEffect(() =&gt; {<br>            console.log(&quot;in 1&quot;)<br>        }, [])<br><br>        return &lt;&gt;Hello world comp 1&lt;/&gt;<br>    }<br>    const Comp2 = () =&gt; {<br>        useEffect(() =&gt; {<br>            console.log(&quot;in 2&quot;)<br>        }, [])<br>        return &lt;&gt;Hello world comp 2&lt;/&gt;<br>    }<br>// eslint-disable-next-line react-hooks/rules-of-hooks<br>    let signalComponent = useSignal(Comp1)<br><br><br>    return (<br>    &lt;div className=&quot;App&quot;&gt;<br>        {signalComponent.value()}<br>        &lt;button onClick={() =&gt; signalComponent.value = Comp2}&gt;Switch&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><p>In the example above, the first console.log(“in 1”) will trigger as a part of the initial React render. but changing the value to Comp2 will not trigger the the useEffect hook of the Comp2. (I found this disappointing but pretty expectable). If you want to manually run the change detection function than yes, it will work…</p><p>So how do we do achieve it ? like the code block below, move the Comp components outside of the main component and render a component by the value of the signal (note that using a signal as a depdency for a hook won’t work.</p><pre><br>const Comp1 = () =&gt; {<br>    useEffect(() =&gt; {<br>        console.log(&quot;in 1&quot;)<br>    }, [])<br><br>    return &lt;&gt;Hello world comp 1&lt;/&gt;<br>}<br>const Comp2 = () =&gt; {<br>    useEffect(() =&gt; {<br>        console.log(&quot;in 2&quot;)<br>    }, [])<br>    return &lt;&gt;Hello world comp 2&lt;/&gt;<br>}<br><br><br>let signalComponent = signal(true)<br><br>function App() {<br><br><br><br>    return (<br>    &lt;div className=&quot;App&quot;&gt;<br>        signalComponent: {`${signalComponent}`} &lt;br/&gt;<br>        {signalComponent.value ? &lt;Comp1 /&gt; : &lt;Comp2 /&gt;}<br>        &lt;button onClick={() =&gt; signalComponent.value = false}&gt;Switch&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App; </pre><h3>Angular is vastly different</h3><h4>Initiating a signal and showing its value</h4><pre>@Component({<br>  selector: &#39;app-root&#39;,<br>  template: `<br>    &lt;div&gt;<br>      value is: {{aValue()}}<br>      &lt;button (click)=&quot;onClick()&quot; &gt;Switch&lt;/button&gt;<br>    &lt;/div&gt;<br>  `,<br>  styleUrls: [&#39;./app.component.scss&#39;],<br>})<br>export class AppComponent {<br>  constructor() {<br>  }<br>  <br>  a = signal(2); &lt;-- initiate the signal<br>  aValue  = () =&gt; computed(() =&gt; { &lt;-- this is a must !! <br>    return this.a.value<br>  })<br>  <br>  onClick() {<br>    this.a.value++; &lt;-- update the signal<br><br>  }<br>}</pre><p>Angular runs it re-render function when it detects something internally has changed or something happened that it guess will require a re-render.<br>Due to how Angular interacts between the “html” and the javascript we need to initiate the computed function. See how the html directly runs the aValue as a function, if not it will not update on click. This entire hacky solution is pretty funny, but lets keep going. We can see that Angular is very strict about what triggers its change detection. while is causes less re-renders it makes us use funny code to make Signals work.<br>I hated how this code looked, having a function call from the html in Angular is a big no no (horrible performance). So what do we do ? continue doing hacky things to try and make something out of it. I wanted to make it seamless “Angular” interaction with the access to the Signal.</p><pre>@Component({<br>  selector: &#39;app-root&#39;,<br>  template: `<br>    &lt;div&gt;<br>      value {{a?.value}}<br>      &lt;button (click)=&quot;onClick()&quot; &gt;Switch&lt;/button&gt;<br>    &lt;/div&gt;<br>  `,<br>  styleUrls: [&#39;./app.component.scss&#39;],<br>  changeDetection: ChangeDetectionStrategy.OnPush &lt;-- on push, which means no automatic refresh<br>})<br>export class AppComponent implements OnInit{<br>  a: any<br>  constructor() {<br>    this.a = new Object();<br>    this.a._signal = null &lt;-- empty initializer<br>    Object.defineProperty(this.a,&quot;value&quot;,  { &lt;-- this is the magical part<br>      get() {<br>        if(this.a._signal) { &lt;-- if the signal is initiated return its value<br>          return computed(() =&gt; this.a._signal.value);<br>        } else {<br>          return null<br>        }<br>      },<br>      set(value: any) {<br>        if(this.a?._signal) { &lt;-- if singal initated sets its value<br>          this.a._signal.value = value<br>        } else { &lt;-- if not , initiate a new signal<br>          if(!this.a) this.a = {};<br>          this.a._signal = signal(value);<br>        }<br>      }<br>    })<br>  }<br><br><br>  ngOnInit() {<br>    this.a.value = 2;<br>  }<br><br><br>  onClick() { &lt;-- triggers the on change detection of angular<br>    this.a.value++; <br><br>  }<br>}</pre><p>While not a generic solution it does what I wanted. remove Signal from the lexicon of the template but keep it internally (I wonder if I would make the effort to make it a generic function… <br>The way its done actually provides us the ability to not need the change detection mechanism.<br>This is the most POC thing ever made so obviously there are still many things to learn and do.</p><p>I truely belive in Signals to be the future of DOM manipulation and will create a unified pattern to create components. while the future is amazing, it currenly still needs many iterations and battle testing. <br>There are many PRs open that come to improve this amazing project.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f784abd37329" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/signals-how-far-can-we-take-it-what-are-its-limits-f784abd37329">Signals — How far can we take it ? what are it’s limits</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Signals — whats going on behind the scenes]]></title>
            <link>https://itnext.io/signals-whats-going-on-behind-the-scenes-ec858589ea63?source=rss-4a80812e7382------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec858589ea63</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[signal]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[state-management]]></category>
            <dc:creator><![CDATA[Ryan Hoffnan]]></dc:creator>
            <pubDate>Tue, 28 Feb 2023 17:52:04 GMT</pubDate>
            <atom:updated>2023-03-02T04:18:48.460Z</atom:updated>
            <content:encoded><![CDATA[<h3>Signals — whats going on behind the scenes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*oK6agWK2d64ztX6YVy9_pQ.jpeg" /></figure><p>If you’re into web development, you may have heard about the buzz around Signals lately. But what exactly are Signals, and how do they work? And, more importantly, how do they differ from the lifecycle-oriented frameworks we use today?</p><h3>What are signals?</h3><p>At its core, Signals is an event-driven programming paradigm that enables developers to create custom events and event listeners within their JavaScript code. This means that they can trigger callbacks or functions when certain events occur within their application, such as user input or data changes. What’s great about Signals is that it allows for complete decoupling between logic and UI, making code more modular and easier to maintain.</p><p>Signals is actually a library created by the Pre-React team, who were looking for an alternative to React’s hooks mechanism as a state management solution. As a result, they’ve brought back event-driven programming to JavaScript, reducing dependency on the framework’s change detection/lifecycle mechanism. But here’s the best part: Signals are framework agnostic! Although there are implementations for popular frameworks, the core library is as vanilla as can be.</p><h3>So, how does Signals work behind the scenes?</h3><pre>const count = signal(0);</pre><p>when you invoke a signal, you get back the context of the invocation (i.e., this).<br>this context has some unique properties that are important to know (note: underscore before variable means internal API).</p><ul><li>_value : the raw value.</li><li>peek : return the internal _value (does not invoke change detection)</li><li>value.get : get the internal _value and add signal to change detection listener</li><li>value.set : set internal _value and run change detection update on signal</li></ul><p>When we access the count signal, it will add a subscription to change, and when we set a value for the count, it will add it as another listener to changes.</p><pre>import { signal, computed } from &quot;@preact/signals&quot;;<br><br>const count = signal(0);<br>const double = computed(() =&gt; {<br>return count.value * 2 &lt;-- when count._value changes it will re-run this calculation<br>});<br><br>function Counter() {<br>  return (<br>    &lt;button onClick={() =&gt; count.value++}&gt; &lt;-- when setting the count it will notify in all places on the change<br>      {count} &lt;-- when accessed (count == count.get) will add it as another listener to changes<br>    &lt;/button&gt;<br>  );<br>}</pre><h3>How does it differ than today’s lifecycle oriented frameworks.</h3><p>One of the key differences between Signals and lifecycle-oriented frameworks is that the latter use a passive lifecycle, which means they wait for something to change before re-rendering relevant components. Angular, for example, has introduced a hybrid pattern in which you need to tell it to re-render the UI now. Signals, on the other hand, uses a pro-active, event-driven update system, meaning that they trigger an update when the value changes. This represents a promising shift towards a unified solution/ideology for re-rendering that focuses on updating only the elements related to the signals changed.</p><p>It’s worth noting that while Signals is a cool and promising solution, it’s still very young and untested. The Pre-React team has done a great job dealing preemptively with scaling issues, such as what happens when there are a lot of signals in one place or if there is a circular dependency issue that creates a ping-pong of updates signals. But it’s important to keep this in mind and continue testing and refining this event-driven pattern as a potential future replacement for passive lifecycle events.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec858589ea63" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/signals-whats-going-on-behind-the-scenes-ec858589ea63">Signals — whats going on behind the scenes</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Use Mock Data Without Changing Internal Logic]]></title>
            <link>https://itnext.io/how-to-use-mock-data-without-changing-internal-logic-bc7488f329af?source=rss-4a80812e7382------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc7488f329af</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[debugging]]></category>
            <dc:creator><![CDATA[Ryan Hoffnan]]></dc:creator>
            <pubDate>Fri, 27 Jan 2023 13:59:25 GMT</pubDate>
            <atom:updated>2023-01-27T15:58:39.830Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*CtbBJe_dKx_h-69nvT1mIg.png" /></figure><p>In every job and every company, that day always comes where you find that you…actually need to do some work. And by that, I mean finding new innovative solutions to tasks and projects instead of going with the tried-and-true methods. Recently, my team, of full stack developers were tasked with building a webview app to support our <a href="https://www.rookout.com/solutions/live-debugger/">live debugging</a> IDE plugin. This would allow us to align the user experience with our pre-existing web app. Using the IDE plugin’s UI framework meant we would need to rewrite a lot of the code, which would also result in a very different user experience due to the differences between frameworks and a lot of engineering time which means a lot of money.</p><p>Obviously, that’s not the ideal choice. So we decided to take a bit of a different approach. You know, one that would make our lives easier and help us create a better product, faster, and maintain the high-level of user experience our customers expect.</p><h3>A New Approach</h3><p>In order to be aligned with our web application we decided to shift from using our plugin’s UI system (Swing in Jetbrains case) and use a modern frontend framework (React) which is much better at rendering — and more importantly, re-rendering — a lot of UI elements. The decision also brought about many smiles in our team as it was easier for us to develop due to us having more experience developing with Javascript than Java Swing. Our goal and mindset was to develop quickly, efficiently, and with as little friction as possible and not be coupled to the plugin by having to rerun the plugin with every change to the UI code.</p><p>With that goal in mind, well..we all know the saying of ‘people plan…’, right? As with every good new feature or product, we encountered problems which were unrelated to the webview but impacted development efficiency.</p><h3>Speeding Up Code Development</h3><p>In order to overcome these issues we chose to take an unconventional route of building mock data responses. These are predefined data sets that mimic the data we would have received from other services, while overriding native communication functions such as “fetch”. This solution dealt with many of the issues we wanted to tackle, such as keeping our code clean and allowing each part of the whole system to be developed separately.</p><p>Keeping services decoupled from one another is a best practice in backend development when working with microservices.It allows complete autonomy of development and deployment per service, which means that as long as we are backwards compatible it is possible to continue to advance and deploy our UI without taking into account the missing correspondent changes from the plugin (other services). When using mock data, it’s common to succumb to the pull of changing your code so as to be aware that mock responses are being used. However, this dirties up the code and can cause future bugs.</p><p>For example, the code block below demonstrates specifically how the code is aware of the usage of mock responses. We indicated that if we are in a development environment it should return mock data.</p><pre>if (env === &quot;development&quot;){<br>  return  {...mockData} &lt;-- local response<br>} else {<br> return fetch(...)<br>}</pre><p>In contrast to what we see in the code block above, what we would like to achieve is the ability to return mock data and <strong>not</strong> make our internal logic aware of the fact that it is getting mock data.</p><h3>So What Do We Do?</h3><p>Using mock responses has been a great tool for me as it has allowed me to continue developing my features or fixing bugs without being dependent on the development and prioritization of others. For example, what might be a major issue on my end could be a minor issue on their end and vice versa. Specifically at <a href="https://www.rookout.com/">Rookout</a>, we develop the IDE plugin at the same time as the Web UI, which acts as an individual service that is dependent on data received from the plugin. With the mock responses I don’t have to wait for development on the plugin to finish before I can start working on my own tasks.</p><p>The top two options that I personally employ when I need to use mock responses are:</p><ol><li>Creating a local web server that will take all requests and return the data as if it was the missing agent. While this solution works great, it requires some setup and for the developer to have a certain level of knowledge (basic as it may be) in backend development.</li></ol><p>If the logic is kept untouched it will always point to whatever env.backendUrl stores, which by environment will point to your local machine or production machine.</p><pre>// dev: localhost://...<br>// prod: https://...<br>const url = env.backendUrl<br>return fetch(url</pre><p>2. The second option — and my main focus for this article — is overriding the original behavior of the api we are looking to use (i.e fetch).</p><p>In modern frameworks we have a main.js/ts file which handles the initial load of our web application. This is the area where we can do our magic.</p><pre>window.fetch = function (request) {<br>   return new Promise(resolve =&gt; {<br>     if(typeof request === &quot;string&quot;) {<br>       return resolve({<br>         isGetMethod: true<br>       })<br>     } else {<br>       const response  = {<br>         isGetMethod: request.method === &quot;GET&quot;,<br>       }<br>       if(request.method === &quot;POST&quot;) {<br>           response[&quot;body&quot;] = async () =&gt; {<br>             return {<br>               ...mockData<br>             }<br>           }<br>       }<br>       return resolve(response)<br>     }<br><br>   })<br> }<br><br>const root = ReactDOM.createRoot(<br> document.getElementById(&#39;root&#39;) as HTMLElement<br>);<br><br>root.render(<br> &lt;StrictMode&gt;<br>   &lt;App /&gt;<br> &lt;/StrictMode&gt;<br>);<br><br></pre><p>In the code block before the app loads, we override the fetch api with our custom behavior. Any fetch done in our react app will get to our new implementation instead of the original fetch api.</p><p>An explanation of what the demo above does:</p><ol><li>If the request’s method is “GET”, return {isGetMethod: true}</li><li>If the method is “POST” , return as an async function (implementation of res.body()) which returns the mock data we want to receive.</li></ol><p>In order to show the result let’s take a look at the simple component:</p><pre>export const Comp = () =&gt; {<br><br>useEffect(() =&gt; {<br> fetch({<br>   url: &quot;https://jsonplaceholder.typicode.com/todos/1&quot;,<br>   method: &#39;GET&#39;<br> }).then(console.log) &lt;-- example of response with get<br><br> fetch({<br>   url: &quot;https://jsonplaceholder.typicode.com/todos&quot;,<br>   method: &#39;POST&#39;,<br>   body: {<br>     &quot;title&quot;: &quot;demo&quot;<br>   }<br> }).then(console.log) &lt;-- example of response with post<br><br> fetch({<br>   url: &quot;https://jsonplaceholder.typicode.com/todos&quot;,<br>   method: &#39;POST&#39;,<br>   body: {<br>     &quot;title&quot;: &quot;demo&quot;<br>   }<br> }).then(async (res) =&gt; {<br>   console.log(await res.body()) &lt;-- example of parsing body response<br> })<br><br>}, [])<br><br><br>return (&lt;div&gt;A Comp&lt;/div&gt;)<br>}<br><br></pre><p>The component sends requests to “production” endpoints, but the response is dealt with locally. Amazingly, no internal code change was made and reduced probability to produce new bugs while deploying to production.</p><h3>WAIT A MOMENT!</h3><p>A change in main.js/ts was made! How do we deal with it?</p><p>Popular Frontend frameworks as React/Angular (and NX as a mono-repo manager) supports using different “main” files when using different configurations for building and serving our application, and thus we can make two “main” files:</p><ol><li>main.js/ts</li><li>main-mock.js/ts</li></ol><pre>&quot;mock&quot;: {<br>         &quot;extractLicenses&quot;: false,<br>         &quot;optimization&quot;: false,<br>         &quot;sourceMap&quot;: true,<br>         &quot;vendorChunk&quot;: true,<br>         &quot;main&quot;: &quot;apps/demo/src/main-mock.tsx&quot;,<br>         &quot;fileReplacements&quot;: [<br>           {<br>             &quot;replace&quot;: &quot;apps/demo/src/environments/environment.ts&quot;,<br>             &quot;with&quot;: &quot;apps/demo/src/environments/environment.mock.ts&quot;<br>           },<br><br>         ]<br>       },</pre><p>The default is our main.js/ts (kept untouched) and it is our main-mock for when we build with the mock configuration.</p><p>This will provide two big benefits:</p><ol><li>The original main file is kept untouched.</li><li>Code added for mock responses will not be bundled when building production configurations and as a result will not affect customer facing bundle size (will not impact performance.</li></ol><h3>Why is all this work worth it?</h3><p>Simply put? It’s a game-changer for quick and efficient development.</p><p>When we want as a team to develop multiple features simultaneously, we need the ability to work as independently as possible from one another but to also be aware of the fact that in production all parts will be — and are — connected. Each of us affects the other, whether we see it or not.</p><p>Using mock data responses by overriding our communication functions (such as fetch) allows us to keep our code unaware of the fact that its being fed mock data and will allow us to develop new features quickly and safely while also giving us the opportunity to debug issues that might occur.</p><p>A happy bonus to this pattern is that usually, as a result of the separation of concerns in development, the code we write is much less error prone and can handle almost any data thrown at it. Therefore, it is also much easier to replicate edge cases and create unique handlers for such cases. And if a bug does somehow occur, well that’s what Rookout is for: production debugging, so that you can see what caused the bug and replicate it with mock responses.</p><p>The idea of parallel work is something we all wish to achieve as a team, but very hard to implement. By using mock data, we are now one step closer to achieving it.</p><p>Give it a try. Happy coding 😉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc7488f329af" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/how-to-use-mock-data-without-changing-internal-logic-bc7488f329af">How To Use Mock Data Without Changing Internal Logic</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Un-Opinionated vs Opinionated Within Frameworks]]></title>
            <link>https://itnext.io/un-opinionated-vs-opinionated-within-frameworks-f6ceb88a21a2?source=rss-4a80812e7382------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6ceb88a21a2</guid>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Ryan Hoffnan]]></dc:creator>
            <pubDate>Fri, 20 May 2022 11:58:41 GMT</pubDate>
            <atom:updated>2022-05-20T11:58:41.004Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*zpbzfn3saE_mV02T63Jl4w.jpeg" /></figure><p>One of the first pros and cons of each framework like Angular or React spits out is that it is “Opinionated” or that it is “Un-Opinionated”, and that is a huge reason to use that framework and a huge reason not to use the other. <br>For the longest time, the project file structure has seemed to me like the main attribution to the opinionated nature of a framework, But there is so much more to it.</p><p>The Opinionated nature of a utility is also defined by how rich the “Swiss army knife (SAF)” it provides the developer.<br>Each framework will supply some SAF for us the developers to use to write our code in a specific manner.</p><p>Examples : <br>1. React — Functional components, Hooks, JSX/TSX <br>2. Angular — HttpClient, RouterModule, I18N, Two-way binding</p><p>I love using these two frameworks as the prime examples for this due to the polarising differences between them.</p><blockquote>The less opinionated a utility is, the more diverse it becomes, but as a result it is less structured.</blockquote><p>One of the simplest examples one can provide is fetching the query parameters from a route.</p><h3>The Diffrences</h3><p><strong>Angular</strong> <br>The code block shows the “Angular way” of fetching the query params, ~99% of tutorials are written as seen below, but notice how both ways use the “ActivatedRoute” utility provided by Angular.</p><pre>import {ActivatedRoute} from &#39;@angular/core&#39;<br>constructor(private <strong>route</strong>: ActivatedRoute) {</pre><pre>     const queryParams = <strong>route</strong>.snapshot.queryParams;</pre><pre>     <strong>route</strong>.queryParams.subscribe(console.log)</pre><pre>}</pre><p><strong>React<br></strong>We have 2 different optional ways to render the component which each gives a slightly different way to fetch the query. Yes, there is a lot of similarity between the patterns, and maybe behind the scenes they use the same solution, but this way gives us flexibility and high diversity to do things that perform better in <strong><em>our</em></strong> application.<br>In the solutions given we use vanilla JS or an open-source library</p><pre>import {useSearchParams} from &#39;react-router-dom&#39; </pre><pre>export const Component = () =&gt; {<br>  const [searchParams, setSearchParams] = useSearchParams();<br>  const id = searchParams.get(&quot;id&quot;)</pre><pre>   const search = window.location.search;<br>   const params = new URLSearchParams(search);<br>   const id2= params.get(&quot;id&quot;);</pre><pre>}</pre><pre>export class ComponentClass {<br>   constructor() {</pre><pre> const search = this.props.location.search;      URLSearchParams(search).get(&quot;id&quot;); <br>}</pre><pre>}</pre><p>The example of getting the query parameters is silly and very small, but it shows us a simple example of how the swiss knife that was given can benefit or hurt us. I am not saying that one is better than another, but what I am saying is: <strong>Be aware of the tools that are given in your Swiss army knife.</strong></p><p><em>Knowing what you have or don’t have can increase your coding speed and quality of work.</em></p><p>Having an opinionated or unopinionated framework is an idealogy that strives from the orientation of the framework. Angular for example is a framework that targets enterprises which means it idealizes shared knowledge base and <strong>predictive code.<br></strong>This decision has its payoffs, for example, bundle size and performance but for an enterprise, these payoffs are maybe worth it.</p><h3><strong>Predictive Code</strong></h3><p>Predictive code is the ability to assume correctly, or with high accuracy, how something is written and implemented. It is one way to validate how consolidated a team/group and the code-base is.<br>Predictive code can be broken down into main areas: <br>1. Naming conversions<br>2. Community-wide Best Practices<br>3. Team/Group agreed-upon Best Practices<br>4. Common Utilities<br>5. Linting and static code analysis<br>6. Typings (or some solution that helps the IDE like JsDocs)</p><p>All 6 criteria can be done in any framework. Although the opinionated level of a framework will determine how many of the items listed above are dealt with through the framework and how many the team/group has to handle on its own.</p><p>The results of Predictive Code are:<br>1. New team/group members will adjust quickly to the coding style of the pre-existing team.<br>2. Code reviews are simpler since agreed-upon standards make it easier to accept or reject PRs.<br>3. Debugging is much easier as we can predict bug location and vulnerable points.<br>4. Creating schematics (code that generates code) can be achieved to increase development speed and “force” the agreed-upon best practices upon the team.</p><h3>Summary (TLDR)</h3><p>Opinionated and Unopinated frameworks can be changed to “<em>More</em> Opinionated and <em>less</em> opinionated”. the level of the framework opinion can be measured and perceived by how many utilities it provides and enforces upon its users.<br>The result of the amount of the utilities is how predictive our code becomes.<br>Any codebase can, and should, become structured and “opinionated”, due to the framework and/or the team handling the codebase.</p><p>Good luck with your projects :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6ceb88a21a2" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/un-opinionated-vs-opinionated-within-frameworks-f6ceb88a21a2">Un-Opinionated vs Opinionated Within Frameworks</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generic UI Component Development]]></title>
            <link>https://itnext.io/generic-ui-component-development-33cecd7a7139?source=rss-4a80812e7382------2</link>
            <guid isPermaLink="false">https://medium.com/p/33cecd7a7139</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[lit]]></category>
            <dc:creator><![CDATA[Ryan Hoffnan]]></dc:creator>
            <pubDate>Fri, 11 Mar 2022 18:27:23 GMT</pubDate>
            <atom:updated>2022-03-11T20:31:34.819Z</atom:updated>
            <content:encoded><![CDATA[<p>At some point in our application development a decision is made. To create a component library. This decision is accepted by all, and development starts. <br>We start with the requirements given from product/design and we create what we think at that point is the entire component. But with in time the requirements of the component grow, and as a result, the complexity increases and maintainability decreases.<br>Most designers/products don’t know/care about the development process and see each element as a unique instance and therefore they feel free to make crazy requirements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*0lWTHzL5FIXizTOXaWpVpw.jpeg" /></figure><p>I will Use a Button component for the ongoing example. I use Angular in this example but this pattern can be done with every framework.</p><pre>@Component({<br>  selector: &#39;demo-button&#39;,<br>  template: `<br>        &lt;button (click)=&quot;onClick.emit($event)&quot;&gt;<br>          {{text}}<br>        &lt;/button&gt;<br>  `,<br>})<br>export class ButtonComponent {<br>  @Input() text: string<br>  @Output() onClick: EventEmitter&lt;any&gt; = new EventEmitter&lt;any&gt;();<br>}</pre><p>This how every button component ever made begins. This is amazing, it works just as expected. It gets a text that will be present in the button and has an on-click that will emit to the consumer <br>Then the designer asks to add a loading indicator… and as a result we add the loading parameter and state.</p><pre>@Component({<br>  selector: &#39;demo-button&#39;,<br>  template: `<br>        &lt;button (click)=&quot;onClick.emit($event)&quot;&gt;<br>          {{loading ? &#39;loading...&#39; : text}}<br>        &lt;/button&gt;<br>  `,<br>})<br>export class ButtonComponent {<br>  @Input() text: string<br>  @Output() onClick: EventEmitter&lt;any&gt; = new EventEmitter&lt;any&gt;();<br>  @Input() loading: boolean<br>}</pre><p>Here begins the interesting part.<br>Why does the button component need to know the text that is inside the button? The answer: it shouldn’t.<br>The button component gives us an accepted behaviour and design which we accept once we agree to use the component. The content is by definition replaceable and changeable, and more importantly, the component doesn’t care, <strong>as it doesn’t have an affect or impact on it.</strong></p><pre>@Component({<br>  selector: &#39;demo-button&#39;,<br>  template: `<br>   &lt;button (click)=&quot;onClick.emit()&quot;&gt;<br>     &lt;ng-content&gt;&lt;/ng-content&gt; &lt;--- will put what ever i want inside<br>   &lt;/button&gt;<br>  `,<br>})<br>export class ButtonComponent {<br>  @Output() onClick: EventEmitter&lt;any&gt; = new EventEmitter&lt;any&gt;();<br>}<br><br><br>// consumer component</pre><pre>// just text<br>&lt;demo-button&gt;<br>   {{loading ? &#39;loading&#39; : text}}<br>&lt;/demo-button&gt;</pre><pre>// example of passing on a different component<br>&lt;demo-button&gt;<br>    &lt;demo-other-component&gt;&lt;/demo-other-component<br>&lt;/demo-button&gt;</pre><p>Now we have a generic button, the consumer can put anything they want, and is not limited to specific type of content which will give us quicker development on UI elements in the future and keeps our component lean and clean.</p><p>The upcoming question is… “ why do we need a shared component if we pass all the hard work?“<br>Good question, The shared component has 2 main agendas.<br>1. Force a systematic design and behaviour<br>2. Have a single job which is handled internally , which at some point will update the consumer with information.</p><p>The component will have wrapper elements which will create an agreed upon layout.(see code bellow) Regardless the content, my button will always have padding 5px and background red. any additional content will be affected by this design forced by the component. We can define different sizes and responsive layouts in order to keep our accepted design.</p><pre>@Component({<br>  selector: &#39;demo-button&#39;,<br>  template: `<br>        &lt;button (click)=&quot;onClick.emit($event)&quot; style=&quot;padding: 5px; background: red&quot;&gt;<br>            &lt;ng-content&gt;&lt;/ng-content&gt;<br>        &lt;/button&gt;<br>  `,<br>})<br>export class ButtonComponent {<br>  @Output() onClick: EventEmitter&lt;any&gt; = new EventEmitter&lt;any&gt;();<br>}</pre><h4>Specific use case which is handled internally</h4><p>All the our button component needs to do, is to tell the consumer that it was clicked (very simple in our example), nothing else is important nothing else matters. What we can do is pass into the button component helpers that modify that single job (modifiers). For example : Disabled</p><pre>@Component({<br>  selector: &#39;demo-button&#39;,<br>  template: `<br>        &lt;button<br>         (click)=&quot;!disabled ?? oClick.emit() : void&quot;<br>          style=&quot;padding: 5px; background: red&quot;<br>         [ngClass]=&quot;size&quot;&gt;<br>            &lt;ng-content&gt;&lt;/ng-content&gt;<br>        &lt;/button&gt;<br>  `,<br>})<br>export class ButtonComponent {<br>  @Input() disabled: boolean; &lt;--- helper<br>  @Input() size: ButtonSize = ButtonSize.Default &lt;--- ButtonsSizes<br>  @Output() onClick: EventEmitter&lt;any&gt; = new EventEmitter&lt;any&gt;();<br>}</pre><h4>Its not about practices, it’s a MENTALITY</h4><p>Components are built to be used. We Preach about reusability but in reality we develop for a specific use case which as a result are not reusable. <br>The button is a simple example, but components can be complex elements with moving parts (Still with one job), but the ideas stay the same.<br> I would like to reiterate the second point from before.</p><blockquote>A Shared Component must have a single job which is handled internally, which at some point will update the consumer with information.</blockquote><p>If we understand what is that single job, we can separate between the job requirements and everything else. <br>Anything that isn’t coupled to that single job, should not be in the component’s responsibility ( i.e the text in our example), and should be handled one level above.<br>Only then can we make truly reusable components that are easy to use, read and maintain.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33cecd7a7139" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/generic-ui-component-development-33cecd7a7139">Generic UI Component Development</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Improving video load performance (JS)]]></title>
            <link>https://itnext.io/improving-video-load-performance-js-8f24c7d6a85e?source=rss-4a80812e7382------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f24c7d6a85e</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Ryan Hoffnan]]></dc:creator>
            <pubDate>Thu, 30 Dec 2021 13:41:21 GMT</pubDate>
            <atom:updated>2021-12-30T16:48:37.601Z</atom:updated>
            <content:encoded><![CDATA[<p>Video elements are used constantly around the web to allow videos, stored in your s3, or any other alternative, to be streamed to your website. <br>While we are not YouTube and don’t want to create many small chunks for the video to allow faster time to play, we need to find a solution for our a more generic use case.</p><pre>&lt;video&gt;<br>  &lt;source src=&quot;<a href="https://link/">https://link</a>&quot;&gt; &lt;/source&gt;<br>&lt;/video</pre><p>This is the simple way to add a video to our website, basic html. In this case, once the url for the video is set in our source tag, the video will start to load, While this does work, the user gets a pretty slow behaviour, they already see the video element, the user has to wait the longest amount of time in order to watch the video.</p><p>So what can we do to improve this? Use native JS (Yes, native)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1iolCQ0rWNrsibiwElMMNQ.png" /></figure><p>So lets go step by step:<br>1. createElement(‘video’) will create an html element of type video (has all its attributes<br>2. createElement(‘source’) will create a source element. <br>3. Append the source to the video (for reference see the html snippet above).<br>4. Set video preload strategy as ‘auto’ (it will start building the video buffer as soon as it gets a url.<br>5. Set the video url. the video will start fetching the url it due to the preload strategy (even before being append to our HTML.<br>6. Append video to HTML(or any other element for that matter) to make video player visible on screen.</p><p>— — — — —</p><p>So why does this work ?</p><p>Appending to the DOM is an “Expensive” event, it takes time. time we can take advantage of in-order to create a feeling of “perceived performance”.<br>We want to show our uses 2 things <br>1. Our website loads as fast as possible<br>2. Once something is visible its usable.</p><p>Loading video will usually be the first thing on the page, and our users already kind of know this. But having an un-actionable interfaces is one of the worst experiences a user can have. So we Delay the time the video is set in the our DOM but at least when its there, its ready to go (or at worst case, in less time).</p><p>Youtube is a video platform, it will do all in their power in order to make the load time as quick as possible, in most websites this is not the case.<br>So we can do the best we can to improve our websites with the tools we already have.</p><p>This has been tested in production on a pretty large scale platform and works faster (sadly I can’t publish numbers)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f24c7d6a85e" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/improving-video-load-performance-js-8f24c7d6a85e">Improving video load performance (JS)</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Moving a company to microfront-end environment (kind of)]]></title>
            <link>https://itnext.io/moving-a-company-to-microfront-end-environment-kind-of-ae1587dc103c?source=rss-4a80812e7382------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae1587dc103c</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[webdev]]></category>
            <category><![CDATA[micro-frontends]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Ryan Hoffnan]]></dc:creator>
            <pubDate>Sun, 14 Nov 2021 17:01:05 GMT</pubDate>
            <atom:updated>2021-11-15T07:59:17.617Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*XwszRu3kC-MpuVLoP6fDbQ.png" /></figure><p>As a company grows, it’s UI grows as well, and becomes a huge monolith with so many moving parts and entanglements it becomes unbearable, the development experience is horrible and the development team is scared of touching the code base. <br>Development experience is something we look for in our computer environment (IDE/terminal/etc…) but usually not in our code base.<br>Moving to micro-front end architecture is something that will greatly improve our development experience. being in-charge of a smaller domain makes changes easier and development faster. But a large company may not see what you see, sayings like “<em>it works…. why change it</em>” are often thrown around.<br>What do we do ?</p><h3>Fake it till you make it</h3><p>When we develop a new part of code we like to mock the data structure to make our lives easier and to get your code running as fast as possible.<br><strong><em>This same idea can be also done on the architecture level of your project.</em></strong><em><br></em><a href="https://nx.dev/">NX</a> is an amazing project that exists mainly to manage your monolith. <br>It has the ability to create multiple Angular/React/Vue projects with ease. why is this important ? <br>We can create our new widgets (domain-driven) as a new applications. which are encapsulated with their own logic and and UI components. Each application exports the required classes/functions/whatever, in order to be consumed by others. <br><strong>Essentially a Micro-frontend with out the remoteEntry part.</strong></p><h3><strong>Benefits</strong></h3><ol><li>Multiple teams can work on the same monolith in separate domains and will never <strong>(almost never) clash (git merge conflicts).</strong></li><li>allows us to refactor old code and improve our applications behavior widget by widget.</li><li>This is<strong> not an “all or nothing”</strong> mentality, this can be done gradually in order to see and test results.</li><li>Production builds only the applications that have been changed , so build times will go down if only a domain specific application has been changed.</li><li>The transition to using an actual remoteEntry is simple</li><li><strong>each application can be run as an independent application and be consumed by other applications.</strong></li></ol><h3>So why go through the trouble?</h3><p>Moving parts in large companies move slowly, there are many areas not accounted for, and implications that we may be departmentalized from.<br>But we want to grow as developers and as a team, to keep pushing ourselves forward.<br>Having a huge monolith that no one wants to touch is not something that is going away soon, but we can start breaking our applications into domains and widgets to make development cycle easier and less prone to breaking production on a Friday/Thursday…</p><h3>Domain Driven Applications</h3><p>Each Applications has a domain its in charge of, logic/services/interfaces are all included in that domain’s application and is exported outside for others to use.</p><p><strong>Example:</strong><br>Our application has 3pages:<br>1. Lists of all users .<br>2. Single user view.<br>3. Settings page.</p><p>In this very simple webApp we have 3 domain applications. <br>1. The shell (the entry point to our application, the main routing, the high level layout is done here)<br>2. Users — lists and single view<br>3. Settings</p><p>There is no connections between Users and Settings pages, the fact the they are both in the same application is a coincidence. So they can be absolutely independent from one another. they don’t know about each other.<br>one team can work on the User application, and another team can work on Settings application, without conflicts between them. <br>Team 1 can not care about the work that team 2 does (in a perfect world).<br>When team 2 is done and wants to push their work. testing can be done on the domain-driven application level, seeing as just one application has been effected by the changes, we increase our confidence in our updates.</p><h3>Conclusion</h3><p>Breaking our monolith into domain focused applications will gives a lot of the benefits that a micro-front end gives us. It’s not the same but I would say its 90% similar. <br>And more importantly, with out going through hoops and DevOps we can create the same easier development experience that we want from MFEs and justify the need for it when the teams are happy to go fix/add/remove stuff from the domain application with out fear about what might be effected (or at least less fear).<br>Code delivery confidence is something that is being talked about a lot over the years. and the smaller your domain is the better confidence you have in them.</p><h3>Inspiration</h3><p>I highly suggest reading <a href="http://The Micro-Frontend Chaos (and how to solve it)">The Micro-Frontend Chaos (and how to solve it)</a> by <br><em>Orel Balilti.</em><br>The article talks about how the Micro-frontend can be not as helpful as the basic demo makes it seems, and how to fix that issue to make production ready projects that can scale.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae1587dc103c" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/moving-a-company-to-microfront-end-environment-kind-of-ae1587dc103c">Moving a company to microfront-end environment (kind of)</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Webpack hooks and NG watch]]></title>
            <link>https://itnext.io/webpack-hooks-and-ng-watch-2822ffb35538?source=rss-4a80812e7382------2</link>
            <guid isPermaLink="false">https://medium.com/p/2822ffb35538</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[webpack]]></category>
            <dc:creator><![CDATA[Ryan Hoffnan]]></dc:creator>
            <pubDate>Sun, 17 Oct 2021 17:02:53 GMT</pubDate>
            <atom:updated>2021-10-17T18:58:14.875Z</atom:updated>
            <content:encoded><![CDATA[<h3>Webpack hooks and ng watch</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QygWUpk5O2XkWKvP0F23JQ.jpeg" /></figure><p>“watch” is something we take for granted in our development cycle. <br>with each file change or save our app rebuilds/re-renders it self and we see the latest version. But there is a catch. the build command never ends…. and thats annoying.</p><p>if you ever tried to this before:</p><pre>ng build --watch &amp;&amp; node test.js</pre><p>And got angry that your test.js never actually got to run, its because of that small <em>watch</em> flag we gave to the ng build. It tell angular to keep the process and listen to all file changes ( or the types of files we told it to listen to).</p><p>In my use case I needed to add a config file to the dist folder after the build and any solution I tried (run-all, concurrently, postbuild ) failed because of timing mismatches between the commands. and forced me to run it manually after each save. ( not the best practice)<br>And than… , when all hope was gone I found this:</p><h3>Webpack hooks.</h3><p>We have this file we don’t like to touch, <strong><em>webpack.config.js</em></strong> , it is scary and most of us don’t know how it works, it’s a given from the whatever cli command we used to create our application. A true “black box”. So how does Angular uses the webpack.config.js file.</p><p>In our Angular.json file in the root of our project we have the option to pass a custom webpack config to each application/library in our project folder.</p><pre>&quot;build&quot;: {<br>  &quot;builder&quot;: &quot;@angular-builders/custom-webpack:browser&quot;,<br>  &quot;options&quot;: {<br>    &quot;customWebpackConfig&quot;: {<br>      &quot;path&quot;: &quot;./custom-webpack.config.js&quot;<br>    },</pre><p>Angular compiler in build time will run the config file we give it with the original webpack config passed into it . <br>This allows us to extend or/and override the config as we want (unless we break webpack). See example below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R_VPNrirZptb6bhO2-P8pA.png" /></figure><p>In this example I add a functionality to the “done” hook of webpack which runs each time it finished its cycle (in our case a ng build cycle), a list of all the webpack hooks available can be found <a href="https://webpack.js.org/api/compiler-hooks/#hooks">here</a>.</p><p>The behavior in the example above will run “<em>npm run add:file” </em>each time webpack is done rebuilding my angular project.</p><p>This is just a small example of what can be done with webpack config. I was happy to find this tweak which solved a real problem for my team, and gave us a much smoother development experience.<br>Unfortunately and fortunately, Webpack does a lot of black-magic and its time that we try and learn to understand more about it, so we can use this powerful tool how we want and need.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2822ffb35538" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/webpack-hooks-and-ng-watch-2822ffb35538">Webpack hooks and NG watch</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>