<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>State-Management on D34dBlog</title>
    <link>https://www.d34dman.com/tags/state-management/</link>
    <description>Recent content in State-Management on D34dBlog</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Tue, 26 May 2026 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://www.d34dman.com/tags/state-management/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Why I Don&#39;t Trust the Submit Button Toggle</title>
      <link>https://www.d34dman.com/posts/engineering/submit-toggle-is-a-cache/</link>
      <pubDate>Tue, 26 May 2026 00:00:00 +0000</pubDate>
      <guid>https://www.d34dman.com/posts/engineering/submit-toggle-is-a-cache/</guid>
      <description>&lt;p&gt;Here&amp;rsquo;s a pattern I&amp;rsquo;ve written more times than I care to admit:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;button&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;classList&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;add&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;enabled&amp;#39;&lt;/span&gt;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;button&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;addEventListener&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;click&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#66d9ef&#34;&gt;async&lt;/span&gt; () =&amp;gt; {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#a6e22e&#34;&gt;button&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;classList&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;toggle&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;enabled&amp;#39;&lt;/span&gt;);   &lt;span style=&#34;color:#75715e&#34;&gt;// intent: disable while submitting&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#66d9ef&#34;&gt;await&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;sendRequest&lt;/span&gt;();&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#a6e22e&#34;&gt;button&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;classList&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;toggle&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;enabled&amp;#39;&lt;/span&gt;);   &lt;span style=&#34;color:#75715e&#34;&gt;// intent: re-enable after&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;});&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Two &lt;code&gt;toggle&lt;/code&gt;s. Symmetric. Looks self-explanatory.&lt;/p&gt;&#xA;&lt;p&gt;Wrong in a way that takes a paragraph to explain and ten minutes to debug the first time you ship it.&lt;/p&gt;&#xA;&lt;p&gt;The problem isn&amp;rsquo;t the function name. It&amp;rsquo;s the &lt;em&gt;operation&lt;/em&gt;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;toggle()&lt;/code&gt; says &amp;ldquo;flip whatever&amp;rsquo;s there.&amp;rdquo; &lt;code&gt;add()&lt;/code&gt; and &lt;code&gt;remove()&lt;/code&gt; say &amp;ldquo;make it on&amp;rdquo; or &amp;ldquo;make it off.&amp;rdquo; Those look interchangeable when you&amp;rsquo;re typing them. They aren&amp;rsquo;t &amp;mdash; not when something else writes to the class between your two calls.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
