title: Using reselect-selectors in a reducer
body: <p>Let's say there is a <code>tree</code> in the state of my react-redux app and <code>tree</code> belongs to <code>myReducer</code>. In many cases I need this tree flattened, so I've got a selector:</p>
  
  <pre><code>const getTree = state =&gt; state.myReducer.tree;
  
  export const getFlatNodes = createSelector(
      [getTree],
      (tree) =&gt; flattenTree(tree)
  );
  </code></pre>
  
  <p>And now I need to access the flattened tree in an action</p>
  
  <pre><code>import { getFlatNodes } from 'path/to/selectors';
  
  function myReducer(state = defaultState, action) {
      switch (action.type) {
         case SOME_ACTION:
             const flattenedTree = getFlatNodes(state);
             return {
                 ...state,
                 smth: getSmthFromFlattenedTree(flattenedTree)
             };
      }
  }
  </code></pre>
  
  <p>This code will not work as expected since <code>state</code> in the reducer is just a slice of the app state. A simple workaround I came up with is to wrap <code>state</code> to make the passed parameter compatible:</p>
  
  <pre><code>import { getFlatNodes as _getFlatNodes } from 'path/to/selectors';
  const getFlatNodes = myReducer =&gt; _getFlatNodes({ myReducer });
  </code></pre>
  
  <p>The code works, although it looks quite hacky and I'm not sure if it won't cause any issues.</p>
  
  <p>Does anybody have any idea why and how it can be done better or my approach is good enough already?</p>