<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Kjell</title>
    <description>The latest articles on Forem by Kjell (@metafoo).</description>
    <link>https://forem.com/metafoo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1014379%2F0388d515-b699-47e4-8b4e-eba9b20caf40.jpg</url>
      <title>Forem: Kjell</title>
      <link>https://forem.com/metafoo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/metafoo"/>
    <language>en</language>
    <item>
      <title>State management thoughts...</title>
      <dc:creator>Kjell</dc:creator>
      <pubDate>Wed, 25 Jan 2023 09:57:31 +0000</pubDate>
      <link>https://forem.com/metafoo/state-management-thoughts-kbf</link>
      <guid>https://forem.com/metafoo/state-management-thoughts-kbf</guid>
      <description>&lt;p&gt;Every now and then when I'm thinking about managing state in react applications I end up, asking myself the same questions over and over again:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is there missing something or am I just using it wrong?&lt;/li&gt;
&lt;li&gt;How do I reuse reducer-logic?&lt;/li&gt;
&lt;li&gt;Is there a way to apply a reducer on the fly to new objects?&lt;/li&gt;
&lt;li&gt;How do I manage relationships (1:n) between objects without putting all of them into the same bucket/reducer ending up with crazy, unreadable update logic?&lt;/li&gt;
&lt;li&gt;How to deal with objects, associated with more than one object (n:m)?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To be more precise let's assume the following data-model:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;task-lists → tasks → comments → quick-reactions&lt;br&gt;
threads → comments → quick-reactions&lt;br&gt;
activities → (task-list|task|thread|comment)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A naive approach would end up having three deeply nested objects with a different reducer managing updates each.&lt;/p&gt;

&lt;p&gt;The reducers will operate on the data in an immutable way of course, so when I add a task the task-list can properly re-render. With a new comment, a task or thread is able to reflect the changes immediately an so on. So everything is fine here!&lt;/p&gt;

&lt;p&gt;Drawbacks:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Update logic is ugly as hell: Just adding a quick-reaction to a comment would lead to apply updates all the way up to task-lists. &lt;strong&gt;→ breaks readable/maintainable code (to me)&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Due to this "update-issue" it's difficult to extract and reuse reducer logic like the quick-reaction, or even the comments-logic at all. &lt;strong&gt;→ breaks DRY&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Assuming to have a (totally decoupled) list of activities rendered besides the tasks: It's nearly impossible to for example a change on a task made here, being reflected in the "original" task-list (in a nice way without "hacking" it...). &lt;strong&gt;→ breaks single-source-of-truth&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;On the other hand: When thinking about having a reducer for every single entity each and somehow managing their relationships by hand this feels very much like reinventing the wheel and implementing a lightweight client-side RDBMS.&lt;/p&gt;

&lt;p&gt;Always thinking of a way to somehow apply different reducers to several parts of an object. Combined with the option to just subscribe to specific parts. This would solve 1. + 2. at least...&lt;/p&gt;

&lt;p&gt;How do you cope with these problems? Am I missing something? Do I over-complicate things?&lt;/p&gt;

&lt;p&gt;✌🏻&lt;/p&gt;

</description>
      <category>plugin</category>
      <category>woocommerce</category>
      <category>software</category>
      <category>news</category>
    </item>
  </channel>
</rss>
