<?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>DEV Community: Alex Dovzhanyn</title>
    <description>The latest articles on DEV Community by Alex Dovzhanyn (@alexdovzhanyn).</description>
    <link>https://dev.to/alexdovzhanyn</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%2F80766%2Fe7bdf3d1-91f1-4b50-979d-ab8aa010a0da.jpg</url>
      <title>DEV Community: Alex Dovzhanyn</title>
      <link>https://dev.to/alexdovzhanyn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alexdovzhanyn"/>
    <language>en</language>
    <item>
      <title>Elixium: A Decentralized App Network Built for Developers</title>
      <dc:creator>Alex Dovzhanyn</dc:creator>
      <pubDate>Sun, 04 Nov 2018 01:51:09 +0000</pubDate>
      <link>https://dev.to/alexdovzhanyn/a-decentralized-application-network-built-for-developers-34o7</link>
      <guid>https://dev.to/alexdovzhanyn/a-decentralized-application-network-built-for-developers-34o7</guid>
      <description>&lt;p&gt;I just wanted to bring some attention to a project I've been working hard on for the past few months, and hopefully bring on board some new contributors who want to get their hands dirty. It's called Elixium. Elixium is a decentralized application network built for developers; its a Proof of Work blockchain that allows engineers to write programs that run on the chain.&lt;/p&gt;

&lt;p&gt;Decentralized applications aren't a new idea -- other networks such as Ethereum or EOS offer smart contracting functionality that doubles as a platform for decentralized applications, but they have their own limitations which we'll talk about in a second. The way Elixium differs from Ethereum/EOS/Lisk is that we're aiming to be akin to AWS, except decentralized, along with offering privacy out of the box.&lt;/p&gt;

&lt;h3&gt;
  
  
  What we're aiming to solve
&lt;/h3&gt;

&lt;p&gt;One of the biggest issues in the blockchain ecosystem right now is the high barrier to entry for engineers who want to use the technology, whether its to create a decentralized application or just to interface with the blockchain. This can be attributed to many different things, but the most pressing reason is that language support in the ecosystem is very poor. In order for an engineer to create a decentralized application or smart contract, they need to either learn a language that is specifically created for smart contracting or use a predetermined language that they might not already know. The fact of the matter is that learning a new language can take days or even weeks, and engineers that I've spoken to are very excited about blockchain but don't want to invest weeks of their time learning a new toolset for a system that might not exist in a few years (e.g. learning Solidity to create Ethereum dApps), since the ecosystem is so rapidly evolving.&lt;/p&gt;

&lt;p&gt;Elixium mitigates this barrier to entry by employing language agnostic smart contracts -- decentralized applications that can be written in potentially any language. Engineers will no longer be tied down to learning a new language like Solidity or migrating to a language like Javascript, they'll be able to use their existing toolset and create decentralized applications with any language that compiles to WebAssembly. They'll be able to use their C, C++, Python, Go, and any other language they're already farmiliar with -- all they have to do is learn a new API to interact with the chain.&lt;/p&gt;

&lt;p&gt;Elixium is built with a technology that focuses on fault tolerance and scalability. This technology is a programming language called Elixir, which is built using a language called Erlang.&lt;/p&gt;

&lt;h3&gt;
  
  
  But why does this matter?
&lt;/h3&gt;

&lt;p&gt;Erlang powers the entire telecom industry. This is the language that supports the infrastructure of our mobile phone networks. It was built by a company called Ericcson in 1986 for the purposes of being distributed, fault tolerant, and to have support for uninterruptable applications. Erlang was reported to have been used in production systems with an uptime of 9 nines, which is a maximum downtime of &lt;em&gt;32 milliseconds per year&lt;/em&gt;. This is a great fit for blockchain, as it is a system that needs to be extremely fault tolerant and available.&lt;/p&gt;

&lt;p&gt;Concurrency is at the core of the language - processes are cheap and you can run hundreds of thousands to even millions of processes easily. This allows for huge performance improvements and parallelization. Erlang has built in error containment and fault tolerance. It has a really cool feature called a Supervisor, which automatically restarts failed processes. Erlang also features hot code swapping functionality -- allowing the software to be updated without interrupting the program. This makes writing distributed applications easy.&lt;/p&gt;

&lt;p&gt;Because of Erlang's large support for concurrency, Elixium is able to mitigate pain points in blockchain by massively parallelizing things like transaction processing. Whenever a new transaction comes in, it's cheap and easy to spin up a separate process to validate and relay that transaction.&lt;/p&gt;

&lt;p&gt;Using hot code swapping, Elixium reduces friction from nodes whenever a new version is released. Rather than a maintainer of a node needing to take down that node, download a patch, run the update, and then start the node back up, maintainers can choose to have their nodes updated on the fly. This reduces the chances of forks happening on the chain whenever a new patch is released.&lt;/p&gt;

&lt;p&gt;As a result of the fault tolerance built into Erlang, and by extension Elixir, Elixium is able to have self-healing nodes. If a node encounters an error during runtime, rather than crashing and waiting for the maintainer of the node to notice and restart the node, it is able to restart itself and not lose context of its current operations, which adds to the total uptime and security of the overall network.&lt;/p&gt;

&lt;h3&gt;
  
  
  Anonymous transactions
&lt;/h3&gt;

&lt;p&gt;We're going to be the first (that I'm aware of) blockchain that strictly enforces zkSNARKS technology in it's core. Other networks default to insecure / non-anonymous transactions and some allow nodes to opt into secure transactions. Our approach is to only allow anonymous transactions via zero knowledge proofs -- it's part of our consensus mechanism. We're still researching this, but we're looking at using Hyrax, a zero knowledge protocol that doesn't need a trusted setup.&lt;/p&gt;

&lt;h3&gt;
  
  
  A few other goodies
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Smooth token emission similar to the CryptoNote token emission algorithm&lt;/li&gt;
&lt;li&gt;Memory-hardened PoW algorithm that discourages the usage of FPGA/ASICs&lt;/li&gt;
&lt;li&gt;Journalized sharding (more info &lt;a href="https://research.elixium.app/qKN0VINqS_eo3AjJ0O4LLQ#Sharding" rel="noopener noreferrer"&gt;here&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;TCP-layer zero knowledge peer authentication for secure communication&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Where we are now
&lt;/h3&gt;

&lt;p&gt;Right now, we're very early in our development phase, so it's a great time to get involved if you want to sway the direction of the project. We're completely open source and community driven, and we aim to continue being that way -- decentralized even within the development team. We don't yet have a whitepaper; a lot of project launch with nothing but a whitepaper, we wanted to have an MVP done before writing a whitepaper to allow the technology to speak for itself, and have the whitepaper be supplemental to the actual system, not vice-versa.&lt;/p&gt;

&lt;p&gt;The website isn't fully done, but I'll link it here as it has some useful links.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.github.com/ElixiumNetwork" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://elixiumnetwork.org" rel="noopener noreferrer"&gt;Website&lt;/a&gt; (P.S. as soon as you contribute to the core, your name + photo is added to the team section of the website)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://t.me/elixiumnetwork" rel="noopener noreferrer"&gt;Telegram Group&lt;/a&gt; (This is where pretty much all of the development discussion is)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://twitter.com/elixiumnetwork" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://reddit.com/r/elixium" rel="noopener noreferrer"&gt;Reddit&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>elixium</category>
      <category>blockchain</category>
      <category>crypto</category>
      <category>aws</category>
    </item>
    <item>
      <title>Building a Blockchain - What I've learned over the past few months</title>
      <dc:creator>Alex Dovzhanyn</dc:creator>
      <pubDate>Sun, 12 Aug 2018 19:17:18 +0000</pubDate>
      <link>https://dev.to/alexdovzhanyn/building-a-blockchain---what-ive-learned-over-the-past-few-months-3e61</link>
      <guid>https://dev.to/alexdovzhanyn/building-a-blockchain---what-ive-learned-over-the-past-few-months-3e61</guid>
      <description>&lt;p&gt;7 months ago, when I first embarked on the journey of creating a new blockchain, I was inspired by the thought of changing the internet -- of being on the front lines of innovation, developing bleeding-edge technology, and pushing the boundaries of how we interact. I was deeply intrigued by blockchain technology and it's ability to change the world for the better, to make the internet into the decentralized and uncontrolled networking system that it was meant to be. &lt;/p&gt;

&lt;p&gt;I noticed a few gaps in the blockchain community at the time, for example: all cryptocurrencies/blockchains fit into a maximum of 2 of the following categories:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Fast&lt;/li&gt;
&lt;li&gt;Anonymous&lt;/li&gt;
&lt;li&gt;More than just internet money&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A blockchain that was both fast and anonymous was meant to be a currency, an anonymous blockchain that was more than just internet money was not fast, etc. As an engineer, I thought to myself, "why not combine all three?". If we're going to build a decentralized internet, we can't settle for something that doesn't satisfy all of the things we do on the internet today: shop, use web apps, and manage banking accounts (hopefully securely). This led me to creating &lt;a href="https://github.com/elixiumnetwork/elixium_core"&gt;Elixium&lt;/a&gt; (&lt;a href="https://twitter.com/elixiumnetwork"&gt;@ElixiumNetwork&lt;/a&gt;, &lt;a href="https://reddit.com/r/elixium"&gt;/r/elixium&lt;/a&gt;): a fast, anonymous, and scriptable blockchain network.&lt;/p&gt;

&lt;p&gt;Elixium allows developers to create decentralized applications written in Javascript, removing the barrier of needing to learn a new language in order to write dApps.&lt;/p&gt;

&lt;p&gt;Here are a few thing I learned in the process:&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Distributed Computing is Hard
&lt;/h2&gt;

&lt;p&gt;Finding a way to allow people to write applications in javascript, and making it &lt;em&gt;fair&lt;/em&gt; to the miners is a difficult problem to solve. Javascript is a turing-complete language, which means it is impossible to parse through it's code and determine whether or not it will run forever (e.g. contains an infinite loop). I spent hours trying to figure out a good way to do this, and finally came up with the following solution, based on Ethereum's model: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Parse the javascript into it's abstract syntax tree (AST) representation&lt;/li&gt;
&lt;li&gt;Sanitize the javascript, making sure all variables are namespaced, in order to minimize interference with any other code that would be interacting with the contract&lt;/li&gt;
&lt;li&gt;Calculate costs based on the computational complexity of a line of code.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This allows miners/nodes on the network who are running the code of the contract to charge a small fee to the developer of the contract for running the code (similar to how hosting services charge money to host your website, or how AWS charges for usage of their servers).&lt;/p&gt;

&lt;p&gt;This also solved the issue of infinite loops: eventually the funder of the contract would run out of funds to run it, and the contract execution would stop (even if there was an infinite loop)&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Networking is really cool
&lt;/h2&gt;

&lt;p&gt;I used to take the convenience of HTTP for granted, but after writing a communication protocol on top of TCP that fit the specific needs of the Elixium network, I realized how crucial it is to understand the way that internet communication works. The tentatively-named Ghost protocol is built on top of TCP and uses an SRP protocol layer to establish a handshake between peers, allowing for end-to-end encryption.&lt;/p&gt;

&lt;p&gt;Writing a communication protocol isn't actually too hard - you all should give it a try!&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Nothing is set in stone
&lt;/h2&gt;

&lt;p&gt;Since blockchain is such a new field of technology, there really aren't that many standards set in place, as you might expect there to be if you come from a web development background. In web development, there's usually one or two different ways of accomplishing a goal that have been standardized, and those standards are relatively easy to spot, e.g. using bcrypt for password authentication, or using Ajax to make XHR requests, or manipulating DOM elements.&lt;/p&gt;

&lt;p&gt;In the world of blockchain, it's a lot more open. At first, this felt weird, because I was used to knowing what the "right" way of doing something was, and if I couldn't find the "right" way, it felt weird to me. Slowly I realized that there is no tried and true way of doing many blockchain related things, like which hashing algorithms to use, the proper way to set up a consensus algorithm, or even how to store data! This allows you to be really creative in the way you solve problems, and although it first felt taboo, it's actually really liberating.&lt;/p&gt;

&lt;p&gt;Oh, and by the way, Elixium is open source and looking for contributors, so hop on GitHub and help us make a better internet!&lt;/p&gt;

</description>
      <category>elixir</category>
      <category>blockchain</category>
    </item>
    <item>
      <title>Recursion For Beginners</title>
      <dc:creator>Alex Dovzhanyn</dc:creator>
      <pubDate>Mon, 30 Jul 2018 18:43:46 +0000</pubDate>
      <link>https://dev.to/alexdovzhanyn/recursion-for-beginners-1k7f</link>
      <guid>https://dev.to/alexdovzhanyn/recursion-for-beginners-1k7f</guid>
      <description>&lt;p&gt;One topic that stumped me as a beginner programmer was the concept of recursion. It’s something that seems to never be used outside of programming, and it’s advantages aren’t quite obvious, making it something not-too-easy to understand. This is an attempt to effectively explain recursion to anyone who isn’t sure what it is, how it works, or why it’s useful.&lt;/p&gt;

&lt;p&gt;What is Recursion?&lt;br&gt;
According to Webster Dictionary, recursion is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“a computer programming technique involving the use of a procedure, subroutine, function, or algorithm that calls itself one or more times until a specified condition is met at which time the rest of each repetition is processed from the last one called to the first”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But what does that even mean? We already know it’s a computer programming technique, but under what conditions would you want a function to call itself?&lt;/p&gt;

&lt;p&gt;Basically, recursion is the concept of having a function call itself until it has done whatever it needs to. This is kind of like a loop (and some languages actually use recursion AS their loops under the hood), but the key difference is that loops (iteration) work by explicitly specifying a repetition structure, whereas recursion achieves repetition by continuous method calls. Consider the following task:&lt;/p&gt;

&lt;p&gt;Create a method that takes any two numbers as parameters and runs the fibonacci sequence algorithm on them 100 times, and displays the output for each step.&lt;/p&gt;

&lt;p&gt;Iteratively, you may do so like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fib = (a, b) =&amp;gt; {   // Create the method
  counter = 0              // Instantiate a counter
  while(counter &amp;lt; 100) {     // Loop until the counter reaches 99 
    sum = a + b
    console.log(sum)
    a = b                  // Reassign the variables for the next iteration
    b = sum
    counter++
  }
}

fib(4,5);                   // Call the function
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This gives you the desired results, and works fine. Recursively, though, it would look something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fib = (a, b, counter = 0) =&amp;gt; { // Create the method
  if (counter &amp;gt; 100) return // Check exit condition
  counter++
  console.log(a + b)
  return fib(b, a + b, counter) // Call itself again if exit condition isnt met
}

fib(4,5)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, they both give the same results, but the recursion is slightly shorter and easier to read. Recursion allows for management of exponential growth. While recursion is useful in many cases, there are also cases when it is better to solve the problem iteratively. Recursion is usually more memory intensive, so it may not be the best option for solving problems that require minimal memory usage.&lt;/p&gt;

</description>
      <category>recursion</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Working With Webhooks in Development</title>
      <dc:creator>Alex Dovzhanyn</dc:creator>
      <pubDate>Thu, 26 Jul 2018 21:47:45 +0000</pubDate>
      <link>https://dev.to/alexdovzhanyn/working-with-webhooks-in-development-4jii</link>
      <guid>https://dev.to/alexdovzhanyn/working-with-webhooks-in-development-4jii</guid>
      <description>&lt;p&gt;I often find myself needing to integrate with an API or external service when building apps or new features. Often enough, I need to be able to fetch information in (almost) real time. Services like MailChimp and PayPal offer webhooks, which is basically a fancy way of describing and external POST request to your server (&lt;a href="http://www.w3schools.com/TAGS/ref_httpmethods.asp"&gt;Click here if you aren’t familiar with HTTP verbs&lt;/a&gt;). Anyone who’s worked with webhooks in a development environment knows it’s quite a pain to work with them if you don't have hosting set up, because you can’t just pass in your localhost address to these services. Localhost pretty much just translates to 127.0.0.1, which is (generally) every computers home IP; telling an API to POST to localhost:3000/your_hook_path literally just tells it to post to itself (and usually APIs won’t let you enter localhost as a URL). You can see how this puts you in an awkward position during development and testing.&lt;/p&gt;

&lt;h4&gt;
  
  
  Ngrok: The Best Thing Since Sliced Bread
&lt;/h4&gt;

&lt;p&gt;Ngrok is a really great tool to solve this problem, and I personally love the tool as a whole (it works with more than just webhooks). Basically, ngrok sets up a URL that routes any incoming requests to a port of your choice, which makes it really useful when working with webhooks. Setting up ngrok is super fast, too. Just download it here, cd into the directory where you installed it, and run &lt;code&gt;./ngrok http 3000&lt;/code&gt;, replacing the 3000 with whatever port you want to expose. If all goes well (and it probably will) ngrok will generate a HTTP and HTTPS URL that forwards to your localhost. All you have to do now is provide the API webhook with the generated URL, and voila! You’ve got a working webhook listener in your development environment. It’s important to note that ngrok will generate a new set of URLs every time you restart the client, so you will need to swap out the URL in the APIs webhook. I also love using ngrok for demoing work while I’m developing. That way, anyone can see the current status of the app/website I’m working on without me having to set up hosting, and I can avoid deploying until it’s actually necessary. It’s also great for testing your website across multiple devices/browsers, because you can connect from pretty much anything.&lt;/p&gt;

&lt;h4&gt;
  
  
  Everyone Loves Ngrok!
&lt;/h4&gt;

&lt;p&gt;Don’t just take my word for it, here are some tweets from people who love ngrok:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“so ngrok.com is basically the greatest thing ever.“&lt;br&gt;
— @philadams&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;“#ngrok is a dream for testing localhost with remote APIs!“&lt;br&gt;
— @davejlong&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;“#ngrok has got to be the easiest local tunnel solution I’ve ever used.“&lt;br&gt;
— &lt;a class="mentioned-user" href="https://dev.to/thecodeboss"&gt;@thecodeboss&lt;/a&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;… and there’s actually &lt;a href="https://ngrok.com/love"&gt;quite a bit more love&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>tools</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Rydux - A Redux store for your ruby application</title>
      <dc:creator>Alex Dovzhanyn</dc:creator>
      <pubDate>Wed, 27 Jun 2018 15:04:21 +0000</pubDate>
      <link>https://dev.to/alexdovzhanyn/rydux---a-redux-store-for-your-ruby-application-16cn</link>
      <guid>https://dev.to/alexdovzhanyn/rydux---a-redux-store-for-your-ruby-application-16cn</guid>
      <description>&lt;p&gt;Hey all, just wanted to write this post to let you know about a small ruby gem I've created, Rydux. This gem allows you to decouple the state from your logic in your application, and implements a more functional paradigm to ruby programming. You can check it out &lt;a href="https://www.github.com/alexdovzhanyn/rydux"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To use the gem, require it somewhere in the &lt;em&gt;root&lt;/em&gt; of your application (or somewhere the store will be accessible everywhere you need it). Next, create some reducers in your application, you can place them anywhere, but a &lt;code&gt;reducers/&lt;/code&gt; directory is recommended. A sample reducer looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;  &lt;span class="c1"&gt;# reducers/user_reducer.rb&lt;/span&gt;

  &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserReducer&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;Rydux&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Reducer&lt;/span&gt;

    &lt;span class="c1"&gt;# Your reducer MUST have a map_state function in order to do anything.&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nc"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map_state&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{})&lt;/span&gt;
      &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:type&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="s1"&gt;'SOME_RANDOM_ACTION'&lt;/span&gt; &lt;span class="c1"&gt;# You can add as many actions here as you'd like&lt;/span&gt;
        &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;some_random_data: &lt;/span&gt;&lt;span class="kp"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="s1"&gt;'APPEND_PAYLOAD'&lt;/span&gt;
        &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:payload&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
      &lt;span class="k"&gt;else&lt;/span&gt;
        &lt;span class="n"&gt;state&lt;/span&gt;
      &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;end&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a store somewhere easily accessible in your application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;    &lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'reducers/user_reducer'&lt;/span&gt;

    &lt;span class="c1"&gt;# The key passed into .new here is the key at which this value&lt;/span&gt;
    &lt;span class="c1"&gt;# will be stored in the state. E.g. { user: whatever_user_state }&lt;/span&gt;
    &lt;span class="no"&gt;Store&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Rydux&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;user: &lt;/span&gt;&lt;span class="no"&gt;UserReducer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Have something subscribe to the store:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyClass&lt;/span&gt;
      &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;initialize&lt;/span&gt;
        &lt;span class="no"&gt;Store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="k"&gt;end&lt;/span&gt;

      &lt;span class="c1"&gt;# Every instance that subscribes to the store will&lt;/span&gt;
      &lt;span class="c1"&gt;# get this state_changed method called whenever the state&lt;/span&gt;
      &lt;span class="c1"&gt;# in the store changes. Do whatever you want with your state here.&lt;/span&gt;
      &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;state_changed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="c1"&gt;# ...&lt;/span&gt;
      &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To update the store with new data, you can &lt;code&gt;dispatch&lt;/code&gt; actions, like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;    &lt;span class="no"&gt;Store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;type: &lt;/span&gt;&lt;span class="s1"&gt;'SOME_RANDOM_ACTION'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Putting it all together:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'rydux'&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserReducer&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;Rydux&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Reducer&lt;/span&gt;
  &lt;span class="vc"&gt;@@initial_state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;name: &lt;/span&gt;&lt;span class="s1"&gt;'Alex'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;age: &lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nc"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map_state&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="vc"&gt;@@initial_state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:type&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="s1"&gt;'CHANGE_USER_NAME'&lt;/span&gt;
      &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;name: &lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:payload&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="ss"&gt;:name&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;
      &lt;span class="n"&gt;state&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="no"&gt;Store&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Rydux&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;user: &lt;/span&gt;&lt;span class="no"&gt;UserReducer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Friend&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;initialize&lt;/span&gt;
    &lt;span class="no"&gt;Store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="vi"&gt;@users_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;name&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;state_changed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="vi"&gt;@users_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;name&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;greet_user&lt;/span&gt;
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Hello, &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="vi"&gt;@users_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="c1"&gt;# Create a new friend (this will subscribe it to the store)&lt;/span&gt;
&lt;span class="n"&gt;friend&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Friend&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;
&lt;span class="n"&gt;friend&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;greet_user&lt;/span&gt; &lt;span class="c1"&gt;#=&amp;gt; Hello, Alex&lt;/span&gt;

&lt;span class="c1"&gt;# Change a value in the store&lt;/span&gt;
&lt;span class="no"&gt;Store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;type: &lt;/span&gt;&lt;span class="s1"&gt;'CHANGE_USER_NAME'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;payload: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;name: &lt;/span&gt;&lt;span class="s1"&gt;'Mike'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="n"&gt;friend&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;greet_user&lt;/span&gt; &lt;span class="c1"&gt;#=&amp;gt; Hello, Mike&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>showdev</category>
      <category>ruby</category>
    </item>
  </channel>
</rss>
