<?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 Sebastián Ibañez on Medium]]></title>
        <description><![CDATA[Stories by Sebastián Ibañez on Medium]]></description>
        <link>https://medium.com/@thram?source=rss-88a0d6ecca2e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*SzWZ55MSEEQ0LaaU.</url>
            <title>Stories by Sebastián Ibañez on Medium</title>
            <link>https://medium.com/@thram?source=rss-88a0d6ecca2e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 22:12:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thram/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[Thrux: Making state management a piece of cake]]></title>
            <link>https://thram.medium.com/thrux-making-state-management-a-piece-of-cake-5251062134dc?source=rss-88a0d6ecca2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/5251062134dc</guid>
            <category><![CDATA[thrux]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[state-management]]></category>
            <dc:creator><![CDATA[Sebastián Ibañez]]></dc:creator>
            <pubDate>Sun, 29 Jan 2017 00:16:15 GMT</pubDate>
            <atom:updated>2017-03-12T22:35:50.061Z</atom:updated>
            <content:encoded><![CDATA[<p>This is my first ever article so first I want to give you an introduction about myself.</p><p>I’m a software developer with more than 10 years experience. I’ve worked for large companies, start ups, and also as a freelancer, where I’ve coded in more languages than I can count (some of them that are already lost from technology). Currently I work with Javascript because I like the freedom the language gives you, and I can write anything (WebApps, Servers, Desktop apps, Mobile apps, etc)</p><p>One thing in particular that I’m passionate about is simplifying and optimising workflows. Lately I’ve found that Redux is very useful for that, but at some point if my app scales, my Redux files (actions/reducers/stores/types) start to get messy. Your code is broken into so many files that it can be pretty annoying to handle, jumping around from one file to another just to fix one little thing. Also I’ve found myself repeating the same steps every time on my projects, pretty much copy/pasting a bunch of code just to setup my Redux store, and writing a lot of repetitive code to define actions and reducers. So I decided to create this library where I’ve simplified that workflow and aim to have a better and easier file structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*rtvevRIVzmTpRpIHjuB5pA.png" /></figure><h3>Making state management simple again</h3><p>To solve these problems, Thrux introduces the concept of <strong><em>Dictionaries. </em></strong>A <strong><em>Dictionary</em></strong> has 3 basic components: a Dispatcher function, a Map function <em>(optional)</em> and an Error function<em> (optional)</em>. You can create dictionaries using the <strong><em>createDict</em></strong> method. These Dictionaries are going to be assigned to an Action Key.</p><p>Let me show you an example:</p><p><em>counter.js</em></p><pre>import {createDict} from &quot;thrux&quot;;</pre><pre>const increaseDispatcher = (payload, state) =&gt; (state || 0) + 1;</pre><pre>const decreaseDispatcher = (payload, state) =&gt; (state &gt; 0) ? state - 1 : 0;</pre><pre>const resetDispatcher = (payload, state) =&gt; 0;</pre><pre>const setDispatcher = (payload, state) =&gt; payload;</pre><pre>const setMap = (data)=&gt; data.value;</pre><pre>export default {    <br>    INCREASE: createDict(increaseDispatcher),<br>    DECREASE: createDict(decreaseDispatcher),    <br>    SET     : createDict(setDispatcher, setMap),<br>    RESET   : createDict(resetDispatcher)  <br>}});</pre><p>Now that we have our dictionaries defined, we can register our state.</p><p><em>registers.js</em></p><pre>import {register} from &quot;thrux&quot;;<br>import counter from &quot;./counter&quot;;</pre><pre>register({counter});</pre><p>The only thing left is to dispatch the actions defined and observe the state for changes.</p><p><em>app.js</em></p><pre>import &quot;./registers.js&quot;<br>import {observe, dispatch} from &quot;thrux&quot;;</pre><pre>observe(&#39;counter&#39;, (state, actionKey) =&gt; console.log(state, actionKey));</pre><pre>dispatch(&#39;counter:SET&#39;, {value: 10});<br>dispatch(&#39;counter:INCREASE&#39;);<br>dispatch(&#39;counter:DECREASE&#39;);<br>dispatch(&#39;counter:RESET&#39;);</pre><p>And that’s it. The observer will trigger every time the state changes, and you can attach as many observers as you want.</p><p><strong><em>TIP: Reuse</em></strong></p><p>You could also easily register different states using the same actions. For example, keeping track of different counters:</p><p><em>registers.js</em></p><pre>import {register} from &quot;thrux&quot;;<br>import counter from &quot;./counter&quot;;</pre><pre>register({counter1: counter, counter2: counter });</pre><p><em>app.js</em></p><pre>import &quot;./registers.js&quot;<br>import {observe, dispatch} from &quot;thrux&quot;;</pre><pre>observe(&#39;counter1&#39;, (state, actionKey) =&gt; console.log(state, actionKey));<br>observe(&#39;counter2&#39;, (state, actionKey) =&gt; console.log(state, actionKey));</pre><pre>dispatch(&#39;counter1:INCREASE&#39;);<br>dispatch(&#39;counter1:INCREASE&#39;);<br>dispatch(&#39;counter1:INCREASE&#39;);</pre><pre>dispatch(&#39;counter2:INCREASE&#39;);<br>dispatch(&#39;counter2:INCREASE&#39;);<br>dispatch(&#39;counter2:DECREASE&#39;);</pre><p>I hope you find this library as useful as I do. For more details check the Library on Github: <a href="https://github.com/Thram/thrux">https://github.com/Thram/thrux</a></p><p>I’m also working on some tools and implementation for the library, here is what I have for now:</p><ul><li><a href="https://github.com/Thram/thrux-logger"><strong><em>Thrux Logger</em></strong></a>: A logger middleware for Thrux</li><li><a href="https://github.com/Thram/react-thrux"><strong><em>React Thrux</em></strong></a>: React implementation of Thrux</li><li><a href="https://github.com/Thram/react-native-thrux-router"><strong><em>React Native — Thrux Router</em></strong></a><em>: </em>Router for ReactNative using <a href="https://github.com/Thram/thrux">Thrux</a> state manager.</li></ul><p>I hope people will join me and contribute to make the library more robust.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5251062134dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>