title: Redux.js - It is possible to create manually a function listening an another function in Javascript?
body: <p>Hi all I'm working on async programming in Redux currently. </p>
  
  <p>I seek for information to create refined Redux Actions, it is all about side effect in Redux and this kind of topics.</p>
  
  <p>I  have seen a snippet in <a href="https://goshakkk.name/redux-side-effect-approaches/" rel="nofollow noreferrer">this article</a> which propose to create listener in order to refined the code.</p>
  
  <p>Here the snippet : </p>
  
  <pre><code>// Redux Action
  function fetchUser(id) {
    return { type: 'FETCH_USER' };
  }
  
  // in some other place, a function listening the Redux Action
  // (pseudo-code)
  when('FETCH_USER').do((dispatch) =&gt; {
    fetch('...').then(user =&gt; {
      dispatch({ type: 'FETCHED_USER' });
    }, error =&gt; {
      dispatch({ type: 'ERRORED_USER' });
    });
  })
  </code></pre>
  
  <p>great but how create manually a function listener in Javascript ? I can't figure out how to do that without writing some callback, </p>
  
  <p>Thanks you</p>