<?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 Jam on Medium]]></title>
        <description><![CDATA[Stories by Jam on Medium]]></description>
        <link>https://medium.com/@devUnemployed?source=rss-2bfd737b446------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*e0Y2JZWzTYtPPiPpzpSAZw.png</url>
            <title>Stories by Jam on Medium</title>
            <link>https://medium.com/@devUnemployed?source=rss-2bfd737b446------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 01:08:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@devUnemployed/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[Soft-launching a curl diff viewer as a side hustle]]></title>
            <link>https://medium.com/@devUnemployed/soft-launching-a-curl-diff-viewer-as-a-side-hustle-8314c6c8ced3?source=rss-2bfd737b446------2</link>
            <guid isPermaLink="false">https://medium.com/p/8314c6c8ced3</guid>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[developer-tools]]></category>
            <category><![CDATA[https]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Jam]]></dc:creator>
            <pubDate>Tue, 13 Jan 2026 11:57:47 GMT</pubDate>
            <atom:updated>2026-01-13T11:57:47.333Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why I Built a Curl Diff Tool for API Debugging</h3><p>Presenting: <a href="https://diffycurl.com/">https://diffycurl.com/</a></p><p>Since joining an API team a few years ago, I’ve come across so many issues when trying to replicate issues across teams, partners and servers. I’ve found that you can document your authentication endpoints as much as possible, and clients still stuff it up. They prefer to send us emails with vague screenshots and error messages instead of the most important bit — the request itself! You would not believe how much it takes sometimes to just get that golden request in a curl format, so we can recreate the problem, and then quickly resolve the ‘issue’. In nearly all cases we find that its because of a malformed request, not adhering to documentation.</p><h4>Problem</h4><p>Its pareto-typical that serving these issues manually is a waste of developer time. In our case, I tend to believe that this is mostly a comprehension problem and we need to solve this for two reasons; less interruptions to the dev team and allowing self-service of clients. Additionally, imagine a tool that support teams can also get in for collecting failing requests and reproducing issues before they even reach a dev.</p><p>I found that there’s a few unique angles of how this problem manifests. Firstly, it could be any request made to our API, including authorization endpoints. Luckily, we can represent pretty much all requests in curl so it has naturally become a common language to exchange request related information, and most tools and languages can export a reproducible curl easily. So I have started building a tool to help compare, test and diagnose curl commands.</p><h4>Solution</h4><p>This is the power of <a href="https://diffycurl.com/">diffycurl.com</a>. At present, it serves as <strong>free </strong>web<strong> </strong>tool built for curl diffs will outwit all the lexicographic diff tools available, where order doesn’t necessarily matter. Users are either API developers or API consumers. Anyone who needs to debug two requests and potentially share it off as evidence of a failure mode. They paste in two commands and see immediate differences.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rsyRgNhW1V3qqqlWirKULw.png" /><figcaption>Diffycurl renders using a brand new engine from diffs.com</figcaption></figure><p>Do other tools exist? Sure. Diff tools exist in general, but don’t solve this problem exactly. Curl is a command for developers, and has options and parameters. So an immediate comparison of mine-with-yours is not accurate. My header list might be in a different order to yours. Mine will use <em>my </em>API key, yours will use <em>your</em> key — which is technically <em>different</em> but not <em>relevant</em> to the issue. And if it does happen to be relevant to the issue, then it would likely be <em>the only thing </em>different between a working/failing request, and therefore obvious.</p><p>What do API teams do currently? Its arduous email chains with rubbish formatting, its out-of-hours messaging and there’s PMs in the middle to muddy up all the deeper explanations. The communication complexity is enormous when a client complains first to support, which passes to the PM, which then to the developers. And solving the issue usually involves communicating back in reverse. Next, all the sample curls sent over are already expired by the time you get to them. Dev teams have to spend extra time setting up their own requests to reproduce it.</p><p>There are other side issues we can uncover from a tool like this. Once we see no difference in the requests made, the developer should be able to reproduce the issue on their end. If they cannot, then there is probably a network issue preventing the client from continuing. So by comparing the requests we have also figured out about the client’s environment, a network issue.</p><h4>Automate the process</h4><p>Now, what if this is automated? What if an API developer could upload a working set of commands, like token exchange, and the client could reproduce it against their snippets on their own. There is opportunity for an API team to show ‘here’s our endpoints, in exact order, and it works — click here to run it’</p><blockquote>In the future, API teams can create one side of the diff and say ‘this works for us, check it yourself’ and don’t have to receive failing request details upfront. Solving the problem before we need to know about it.</blockquote><h4>Request security</h4><p>Can we keep requests secure? At present, Diffycurl can only process request secrets on the client side, and allow templating when needing to store requests. So it is stateless by default. For example, we can intelligently know if API keys are different by hash instead of actually storing their values. Both users know what their real values are, and there is no necessity to share those pieces, so its largely irrelevant to remember the exact secret when storing requests. A representation of the secret can be compared at the same fidelity.</p><p>With a persistent template system we should be able to provide plug-and-play variables for curl runners that users can input their secrets on client side runs. On the Diffycurl server side, the API developers can provide a authorization procedure and set up our server with its own API credentials and sample requests.</p><h4>Pricing</h4><p>At present, diffycurl.com is a <strong>free tool to use in browser</strong>. Currently ranking on Google and getting clicks. Try it today and let us know how it goes!</p><p>We plan to offer value on a set of paid feature tiers; consisting of deeper payload inspections and http relevant callouts like character encodings, protocol issues and JWT/JWKS checks. Another monetization mode would be to implement a backing server that API teams can set-up to test inputs on the fly, prepared to show ‘this works’ instantly across the web.</p><h4>Conclusion</h4><p><a href="https://diffycurl.com/">Diffycurl</a> started as a way to remove friction from a problem I kept seeing repeatedly. By making curl diffs explicit and shareable, it helps teams move faster, and front-load the debugging process before it reaches developers. The current tool is intentionally narrow, but it already solves a real pain point. If you work with APIs and spend time diagnosing requests, especially for third party clients, try it and see whether it shortens that loop for you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8314c6c8ced3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git conflicts: merging in the fast lane]]></title>
            <link>https://medium.com/@devUnemployed/git-conflicts-merging-in-the-fast-lane-60255d2f7c9c?source=rss-2bfd737b446------2</link>
            <guid isPermaLink="false">https://medium.com/p/60255d2f7c9c</guid>
            <category><![CDATA[developer-tools]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[pull-request]]></category>
            <category><![CDATA[bitbucket]]></category>
            <dc:creator><![CDATA[Jam]]></dc:creator>
            <pubDate>Mon, 12 May 2025 01:48:57 GMT</pubDate>
            <atom:updated>2025-05-12T01:48:57.570Z</atom:updated>
            <content:encoded><![CDATA[<p>Every time I saw ‘This branch has conflicts that must be resolved,’ I’d sigh and switch to main, pull, switch back, merge. It is the way I was taught, as an intern at a large enterprise software company. Now, years later, I finally had enough. Enough of switching, merging, pulling. Its just too slow in some repos. Its overkill and there is a faster way.</p><p>Introducing, <em>upmerge</em>.</p><p>To fix merge conflicts with origin, just merge origin/main directly. No more main checkout and pulling. You don’t need to keep your local main in sync if you are not going to push it. Its a slight adjustment but I feel like it will actually simplify the upstream sync.</p><p>For example if you are already in a feature branch:</p><pre>git fetch origin<br>git merge origin/main</pre><p>Now there is no need to update local main if you’re not working off it. Your client will offer conflict resolution as normal. After, you can push your branch and be none the wiser.</p><p>You can achieve this with a new git alias, upmerge. It handles the origin fetch for you, so its even faster to pull in latest.</p><pre>git config --global alias.upmerge &#39;!f() { git fetch origin &amp;&amp; git merge origin/$1; }; f&#39;<br><br>git upmerge main</pre><h4>Closing</h4><p>Just fetch and merge origin/main directly into your feature branches. Keep local main in sync when you need to work on the latest code.</p><p>You may notice I don’t offer a rebase approach. This is because I prefer to use squash merging anyway, so rebase doesn’t really matter when fixing conflicts on the feature branch.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60255d2f7c9c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RoboCopy: The way to back up folders on Windows]]></title>
            <link>https://medium.com/@devUnemployed/robocopy-the-way-to-back-up-folders-on-windows-0efe6538a028?source=rss-2bfd737b446------2</link>
            <guid isPermaLink="false">https://medium.com/p/0efe6538a028</guid>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[windows]]></category>
            <category><![CDATA[backup]]></category>
            <dc:creator><![CDATA[Jam]]></dc:creator>
            <pubDate>Sun, 18 Aug 2024 03:35:52 GMT</pubDate>
            <atom:updated>2024-08-18T03:38:21.182Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>RoboCopy </strong>is a command-line tool built into Windows that provides advanced file copy options. Unlike dragging and dropping files using File Explorer, RoboCopy allows you to perform more sophisticated backup tasks with options to control exactly how files are copied.</p><h4>When copying files to a backup location, you often want to ensure that:</h4><ol><li><strong>Only new or changed files are copied</strong> — you don’t want to waste time copying files that are already backed up.</li><li><strong>No files are deleted</strong> — even if they no longer exist in the source folder.</li><li><strong>The process is efficient</strong> — without manually reviewing each file.</li></ol><h4>To back up your files while ensuring no duplicates or deletions, use the following command:</h4><pre>robocopy &quot;C:\path\to\source&quot; &quot;D:\path\to\backup&quot; /E /XC /XN /XO</pre><p>These flags together ensure that only files that need to be copied are transferred, avoiding unnecessary duplication.</p><p>Once you’ve entered the command, press Enter and let RoboCopy do its thing. The process can take some time depending on the size of your folders, but it’s highly efficient.</p><p>Windows Explorer offers basic conflict resolution (like “Skip,” “Replace,” or “Keep Both”), but it’s not as robust as RoboCopy’s command-line options.</p><p>RoboCopy also outputs a nice log trail of all new file operations, so you can always check exactly what was copied over.</p><p>RoboCopy by default does not run any delete operations so its quite safe to run.</p><p>This simple backup command has led me to realize that most backup software are probably just wrappers for my newfound friend, RoboCopy!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0efe6538a028" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tailwind CSS — How I learned in 24-hours]]></title>
            <link>https://medium.com/@devUnemployed/tailwind-css-how-i-learned-in-24-hours-d2dc2617c73a?source=rss-2bfd737b446------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2dc2617c73a</guid>
            <category><![CDATA[tailwind-css]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Jam]]></dc:creator>
            <pubDate>Thu, 15 Feb 2024 00:41:28 GMT</pubDate>
            <atom:updated>2025-08-21T05:22:57.895Z</atom:updated>
            <content:encoded><![CDATA[<h3>How I learned Tailwind CSS in 24-hours</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DJyrD87CzJEMaoUbdAf9GQ.png" /><figcaption>An average component using Tailwind (dramatized)</figcaption></figure><p>Welcome to my Tailwind CSS cheat sheet where I was brought up to speed and got up and running with it within 24 hours. In the past, I put off learning Tailwind CSS because I was skeptical of its use-case, and I didn’t fully understand why we would want utility-first styling. However, as I learned more, I came to appreciate its intention and goals of helping us never manually write CSS again. I’m still not a complete evangelist of it, but this is how I learnt Tailwind CSS in a day:</p><h4>1. Watch: Tailwind in 100 seconds</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fmr15Xzb1Ook%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dmr15Xzb1Ook&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fmr15Xzb1Ook%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/c3ebf9a40d8de908d9ce9767fc9c4ac5/href">https://medium.com/media/c3ebf9a40d8de908d9ce9767fc9c4ac5/href</a></iframe><h4>2. Get the <a href="https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss">Tailwind CSS IntelliSense VSCode Extension</a></h4><p>The VSCode extension is very helpful and offers intellisense for all the class names you’ll be writing. Most importantly, it shows what CSS output is for classes you hover over.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/1*9c4o8uWxuFhI1aGau9D_5A.png" /><figcaption>Hovering over te mx-auto class shows the real CSS output</figcaption></figure><h4>3. Start writing</h4><p>Here’s the bottom-line with Tailwind CSS — <strong>you still need to know CSS</strong>. Tailwind is good for stacking classes together, but the fundamentals of CSS are actually more needed than ever with this. You need to know what the intention of a mx-auto class would be, you must know the nuance of the box model to decide if you use a p- class or a m- class.</p><p>Tailwind CSS just provides the pattern to combine it all. I like this model, because it means I don’t have to learn some new abstraction over CSS. So adoption is much easier. With Tailwind CSS I feel like I’m just writing shorthand for the CSS I already know.</p><h4>4. Where next?</h4><p>I’m enjoying my first day with Tailwind CSS. Of course, my main concern is the duplication and maintainability nightmare of class names all over my component files. The two methods to overcome that are extracting common styles to components and using Tailwind’s @apply directive. The former seems to be the recommended solution, because the latter involves writing CSS which seems very clear from the documentation is least desirable when using this framework.</p><p>So for next steps, I look to start extracting out components mainly just to re-use the styles.</p><h4>Conclusion</h4><p>In conclusion, in 24 hours I learnt about the utility-first value proposition of Tailwind CSS, and how it aims to help me write CSS faster and with optimized css builds. I was able to achieve a responsive login form with dark mode support in a day. I levered the theme overrides so I can easily change my accent color given I’m sure our requirements will change. I say give it a try!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2dc2617c73a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React children props with TypeScript]]></title>
            <link>https://medium.com/@devUnemployed/react-children-props-with-typescript-9d369343e18a?source=rss-2bfd737b446------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d369343e18a</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Jam]]></dc:creator>
            <pubDate>Mon, 01 Jan 2024 00:55:55 GMT</pubDate>
            <atom:updated>2024-01-01T00:56:27.212Z</atom:updated>
            <content:encoded><![CDATA[<p>This will be a short one as I was building today and I finally questioned the interface I define for react children.</p><p>Consider you’re creating a react component that needs children:</p><pre>export const BasicPage = ({ title, children }) =&gt; {<br>    return (<br>        &lt;&gt;<br>            &lt;div className=&quot;container&quot;&gt;<br>                &lt;h1 className=&quot;h2&quot;&gt;{title}&lt;/h1&gt;<br>            &lt;/div&gt;<br>            {children}<br>        &lt;/&gt;<br>    );<br>};</pre><p>In the past, even in enterprise, we have defined the children prop as part of the props interface, usually like so:</p><pre>interface BasicPageProps {<br>    title: string;<br>    children: ReactNode | ReactNode[];<br>}<br><br>export const BasicPage = ({ title, children }: BasicPageProps) =&gt; {<br>...</pre><p>Today I encourage you all to use React.PropsWithChildren like so:</p><pre>interface BasicPageProps extends React.PropsWithChildren {<br>    title: string;<br>}<br><br>export const BasicPage = ({ title, children }: BasicPageProps) =&gt; {<br>...</pre><p>This is great because typescript interfaces can extend many interfaces, so PropsWithChildren is just one of potentailly many. It simplifies your props interface. Overall, I’ll be doing this from now on.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d369343e18a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What makes ‘Haunted’ Code?]]></title>
            <link>https://medium.com/@devUnemployed/what-makes-haunted-code-9a91e58b366a?source=rss-2bfd737b446------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a91e58b366a</guid>
            <category><![CDATA[programming-horror]]></category>
            <category><![CDATA[software-bugs]]></category>
            <category><![CDATA[halloween]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Jam]]></dc:creator>
            <pubDate>Sat, 28 Oct 2023 09:33:25 GMT</pubDate>
            <atom:updated>2023-10-28T09:33:25.562Z</atom:updated>
            <content:encoded><![CDATA[<p>I feel an overwhelming sense of dread as Visual Studio begins to load the next solution. Project reference errors begin to trickle down the Error window like itemized drippings of blood. ‘Loading project 1 of 10…’ it scribes in the notification bar. ‘Its slow today, am I on the VPN?’, I wonder. As my machine begins to allocate more and more resources, I hear a louder and louder whine - stemming from my poor laptop fans. The neighbor’s dogs outside begin to howl as the coil whine amplifies. The projects begin to appear out from the dark-themed Solution explorer. Visual Studio slowly recovers from the list of over 200 errors as it finds the courage to load its project dependencies and restore all NuGet packages. The fog clears. Its quiet now — I’m ready to code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rKHFYPj1klfoHCFsJMUJDA.jpeg" /></figure><h4>Files &amp; Structure: Lost in the Labyrinth</h4><p>Getting lost in a codebase can be like a haunted hedge maze. A poor file structure is often a heuristic for a lack of conventions. When conventions are missing, we tend to reinvent the wheel and create many alternative solutions to many of the same problems.</p><p>Lacking of effective file grouping quickly sprouts a disorganized and illogical mess in the filesystem. Developer productivity suffers as a result of this disorganization. Overall, poor structure of files creates a maintenance nightmare for yourself and others. Proper structure can serve as metadata for self-documentation. For larger projects, you should decide early on your grouping — do you want to create feature-sliced folders, or responsibility-sliced folders?</p><p>Feature-sliced folders promotes isolation, but encourages repetition. Responsibility-sliced folders promotes reusability, but encourages heterogeneous arrangement.</p><p>Create something familiar and stick with it. In the past I have seen folders like:</p><ul><li>‘App’ — for UI, Controllers, Message Handling,</li><li>‘Business’ — for entities, logic and business rules,</li><li>‘Services’ — for DB and API access, and</li><li>‘Utils’ — for helper functions and extension methods.</li></ul><p>You can’t go too wrong starting with that.</p><h4>Multithreading: From Hell</h4><p>The roots of all multithreading evils are race conditions or deadlocks.</p><p>Race conditions occur when two or more threads access shared resources concurrently and the final outcome depends on the timing and order of thread execution. This can lead to unpredictable and incorrect results in your program. Race conditions can usually manifest when values are caluclated incorrectly in CPU bound work. In IO bound work, you might uncover null reference exceptions as resources are required before they are retrieved.</p><p>A deadlock is a situation where two or more threads are unable to proceed because the threads are waiting for the others to release a resource. This can bring your program to a standstill. An apparition of this is when tasks seem to never complete, your program appears to be ‘stuck’ or your UI is frozen.</p><h4>Unit Testing: Dreadful Suspense</h4><p>A spectral avatar hands over a black box to you. ‘Business layer’, it whispers. ‘This is yours now’.</p><p>A black box without much to signal its purpose or function is a suspenseful nightmare. What <em>will </em>it do? What is it <em>supposed</em> to do? How do I use this thing? Its depth is unknown, a deep abyss. The spectral avatar was a metaphor for your ex-colleague who has now left the company — i.e. their display picture is greyed out.</p><p>Untested code is usually unchanged code because we are terrified of opening Pandora’s box.</p><p>A lack of unit testing is dreadful because you become suspicious of production code. Its hazy because we lose sight of what the <em>happy-path </em>was supposed to be and we lose documentation of what is expected to happen. We become paranoid and fear changing it. If code cannot be unit tested, consider falling back to commenting the function and purpose of the code is acceptable. Product requirements change all the time, but we need to know what the requirements were at the time it was written.</p><p>We have to write code and unit tests under the assumption that none of us, with all our business requirements and context, will still be around in 6 months to maintain it. Unit tests done right will allow us to validate every input, every branch, every output. This is for when you cross over, the undeparted will know what to do.</p><p>Code coverage is a good measure of the quality of our code. You don’t need any fancy automated tool suite to determine code coverage. If your tests consider the combinations of inputs, branches and outputs, you’ll be in a better place.</p><h4>Conclusion</h4><p>Code can be scary. This Halloween, sharpen your new projects with a cleaner file system, organising by feature-sliced or responsibility-sliced structures. When programming multi-threaded procedures, ensure that you aren’t introducing new synchronization issues through race conditions or deadlocks. Lastly, an inherited project can be daunted when it does not indicate how it should work. Unit tests act as documentation of the happy-path and what the intention of your app code is.</p><p>Happy Halloween.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a91e58b366a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Easy Inline Editing of Objects in React]]></title>
            <link>https://medium.com/@devUnemployed/easy-inline-editing-of-objects-in-react-11feb3071e31?source=rss-2bfd737b446------2</link>
            <guid isPermaLink="false">https://medium.com/p/11feb3071e31</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Jam]]></dc:creator>
            <pubDate>Sun, 24 Sep 2023 13:22:27 GMT</pubDate>
            <atom:updated>2023-12-28T05:08:55.291Z</atom:updated>
            <content:encoded><![CDATA[<p>Every time I am tasked to ‘support inline editing’ of an object in React, I dread it, particularly when the data source is remote. Should I mutate the existing state? Do I clone the object and sync all changes at the end? What happens if a server update happens in the middle of editing? Gah!</p><p>In the past, I have tried to store the ids if which item we are ‘currently editing’, like so:</p><pre>const [editingIds, setEditingIds] = useState&lt;string[]&gt;();</pre><p>This will help us remember which objects in a list are currently being edited.</p><p>And then you would render the editing UI, like so:</p><pre>return items.map(item =&gt; editingIds.has(item.id) ? &lt;EditUI /&gt; : &lt;DisplayUI /&gt;)</pre><p>This allows the user to see a UI to either edit the item or display the item.</p><p>This idea generally works. However, its not so nice because it creates a dependency where editingIds needs to be synchronized to the source list. What if you’re editing just the Title property of an Item? With this pattern, you would also need a state for [pendingTitle, setPendingTitle]. Suddenly, you will need to synchronize individual fields every time the source changes.</p><p>Its too granular and becomes tedious very quickly.</p><h3>A better way</h3><p>Introducing… the <strong>draft object. </strong>The draft object is a replica of your source object with the ability to track its own editability state. I’ve had success with it recently and would like to explain how it works. Simply, it works like this:</p><ol><li>When entering ‘edit’ mode, clone the source object into a <em>draft</em>. This supports the immutability of the original source, so you can revert back easily.</li></ol><pre>const [draft, setDraft] = useState&lt;myModel&gt;();<br><br>onStartDrafting = () =&gt; { <br>  setDraft(Object.assign({}, selectedModel));<br>};</pre><p>Now you have a clone of your model as `draft` , which you’re free to modify its properties. You can easily render the original/draft values separately. This is really useful to also keep track of the before &amp; after values too.</p><p>2. You can use Typescript’s intersection types to persist editing metadata on your clone. Like so:</p><pre>interface DraftItem {<br>  isDirty: boolean;<br>}<br><br>const [draft, setDraft] = useState&lt;myModel &amp; DraftItem&gt;();</pre><p>Now your item is cloned with isDirty state, you can set this when you first change anything on your clone. Because of typescript’s intersection type &amp; operator, you do not need to pollute your model type e.g. myModel. This makes serialization for your model a dream.</p><p>3. You can also do this for each item in a list like so:</p><pre>type EditableItem = ItemType &amp; {<br>  isEditing: boolean;<br>};<br><br>const setIsEditing = (draftKey: string, isEditing: boolean) =&gt; {<br>  const draftItem = itemsDraft.find((x) =&gt; x.key === draftKey) as EditableItem;<br>  draftItem.isEditing = isEditing;<br> <br>  const newDraft = Object.assign({}, itemsDraft);<br>  setItemsDraft(itemsDraft);<br>};</pre><p>This allows you to attribute each item with ‘isEditing’ flag for your UI. Now you can maintain a list of edited items in one place, without a separate list of Ids to monitor and synchronize.</p><p>From here, you can:</p><ul><li>On save, replace your entire model with the draft object, then reset the draft.</li><li>On save, push your draft object to your remote state to be persisted. Since the draft follows the same schema as your real model, it might be fully compatible with your API anyway.</li><li>When the remote state is refreshed, you can repopulate your draft. If your model is a list of objects, you can utilize the isDirty and isEditing attributes to prevent the update from overwriting items that have dirty or in-progress changes. Instead, you can prompt the user to save or overwrite.</li></ul><p>In conclusion, for react inline editing, avoid using state properties for <em>every attribute </em>of your objects. Instead, simply clone the object as a draft and allow the inline editing UI to operate on the clone.</p><p>Using a draft object, it allows for easy revert and promotes immutability of your original data model. Changes can then flow outwards to remote state and then the UI will receive an update from the remote state. Overall, it encourages a healthy flow of model state around your system instead of circular micromanagement of watching &amp; filtering react states.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11feb3071e31" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[C# Avoiding the Strategy Pattern — Today]]></title>
            <link>https://medium.com/@devUnemployed/c-avoiding-the-strategy-pattern-today-db6a658a151?source=rss-2bfd737b446------2</link>
            <guid isPermaLink="false">https://medium.com/p/db6a658a151</guid>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[objectorientedprogramming]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <dc:creator><![CDATA[Jam]]></dc:creator>
            <pubDate>Fri, 15 Sep 2023 06:45:20 GMT</pubDate>
            <atom:updated>2023-09-17T09:31:32.766Z</atom:updated>
            <content:encoded><![CDATA[<h3>C# Avoiding the Strategy Pattern — Today</h3><p>If you have a class who’s algorithm can have multiple implementations, you may be temped to use a strategy pattern. Today I was faced with this problem:</p><p>A class has the responsibility of sending messages, was originally written like so:</p><pre>class MessageSender<br>{<br>    // &lt;Pretend all the setup is here&gt;<br><br>    public void SendMessage(string accountId)<br>    {<br>        if (featureToggle(&quot;send-over-sns&quot;).enabled(accountId))<br>        {<br>          // Send over SNS<br>        } else<br>        {<br>          // Send over HTTP<br>        }<br>    }<br>}</pre><p>From here, we have two smells already in this algorithm:</p><ol><li>We have application-layer concerns/business rules (feature toggles) in shared, low level code, and</li><li>We are checking cases with completely different concerns within the same control flow — if statements.</li></ol><p>I needed to extract this class out to a new shared project. For this article, imagine we have an API project and a ‘Shared’ project which might be consumed by more than one projects.</p><p>A problem quickly arose which was that I didn’t want to share the SNS setup and implementation in <em>every possible consumer </em>because I know there’s only one project that would need it — API. What happens if we need a 3rd, 4th, 5th way to send messages? I know, I’ll use a strategy.</p><p>However, when in multi-project development, where each project owns its service registrations, how do you use dependency injection to retrieve the right strategy? You would need a wrapper class in each project, that resolves the correct strategy and assigns it to a resolved base instance. At runtime, this presents a few more problems like potentially using a service locator (antipattern) to retrieve the services needed for our new strategies. Overall, I can see its becoming more complicated. Then an easier solution hit me.</p><p>Simple class inheritance over DI.</p><p>I can define the base algorithm in my shared project like so:</p><pre>public class HttpMessageSender : IMessageSender<br>{<br>    // &lt;Pretend all the setup is here&gt;<br><br>    public virtual void SendMessage(string accountId)<br>    {<br>          // Send over HTTP<br>    }<br>}</pre><p>and still register it in DI in my shared project</p><pre>public void Configure(IServiceCollection <br>{<br>   // TryAddSingleton: Other projects are allowed to register ISendMessages first.<br>   services.TryAddSingleton&lt;ISendMessages, HttpMessagingService&gt;();<br>}</pre><p>An important feature of this registration is that its TryAddSingleton — we can override using DI! 👌 Anyone who wants to override the instance can just register that interface first.</p><p>Now in my API project, I can implement just the algorithm this project specifically needs <em>w</em>hile maintaining the structure of the base class:</p><pre>class SNSMessageSender : HttpMessageSender<br>{<br>    // &lt;Pretend all the setup is here&gt;<br>    public override void SendMessage(string accountId)<br>    {<br>        if (featureToggle(&quot;send-over-sns&quot;).enabled(accountId))<br>        {<br>          // Send over SNS<br>        } else<br>        {<br>          // Fallback support!! <br>          // Send over HTTP<br>          base.SendMessage(accountId);<br>        }<br>    }<br>}</pre><p>And its DI:</p><pre>public void Configure(IServiceCollection <br>{<br>   services.AddSingleton&lt;ISendMessages, SNSMessagingService&gt;();<br><br>   services.ConfigureSharedRegistrations();<br>}</pre><p>Here we are saying specifically for this API project the implementation we want. Assume that ConfigureSharedRegistrationswould register whatever is in our shared project’s registration, it would skip registering our base class.</p><p>Now we have set up a maintainable and extensible way to override a base class algorithm without the strategy pattern 👍. We leveraged dotnet DI to ensure that we can optionally override interfaces with child classes. This addresses our two main problems with the first class:</p><ol><li>App-level (feature flag) checking is done in the right project and not shared out to different consumers</li><li>Each concern is now part of its respective project, and anyone can use the base implementation out of the box.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db6a658a151" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>