redux reducer vs action
<p>Newbie question regarding reducer vs action. <a href="http://redux.js.org/docs/basics/Reducers.html" rel="nofollow">From redux documentation</a>:</p>

<blockquote>
  <p>Actions describe the fact that something happened, but don’t specify
  how the application’s state changes in response.</p>
</blockquote>

<p>and </p>

<blockquote>
  <p>Given the same arguments, reducer should calculate the next state and
  return it. No surprises. No side effects. No API calls. No mutations.
  Just a calculation.</p>
</blockquote>

<p>So if we consider the following scenario:</p>

<ol>
<li>User can place points on a map and get route between those points.</li>
<li>When user first clicks on a map this is his starting point. When he clicks for the second time - this is his ending point. Consequent clicks add points between the previous point and end location.</li>
<li>After each point is added (except for the first one) route must be calculated between new point and previous point. So if i have S -> A -> F and add point B (S -> A -> B -> F) two routes must be calculated A -> B and B -> F</li>
</ol>

<p>So we kind of have two side effects upon adding any 3+ point:</p>

<ul>
<li>New point is placed not at the end of the list</li>
<li>New route must be calculated to the Finish point.</li>
</ul>

<p>If i model my Point structure as this:</p>

<pre><code> // typescript
interface Point {
  coordinates;
  routeTo?;
}
</code></pre>

<p>Am I correct to perform item position calculation and route retrieval in Actions, eg:</p>

<pre><code>  // pseudo code
    export function addMapPoint(newPoint) {
      return (dispatch, getState) =&gt; {
        const {points} = getState();
        const position = getInsertPosition(points, newPoint)
        dispatch(addPoint(newPoint, position));
        if (points.length &gt;= 2) {
          const previousPoint = getPreviousPoint(points, position);
          calculateRoute(newPoint, previousPoint).then(route =&gt; {
            dispatch(updateRoute(newPoint, route))
          })
        }
      }
    }
</code></pre>

<p>To me this somehow contradicts to the "but don’t specify how the application’s state changes" - because from action i'm specifying where to insert my new point.<br>
I could calculate the insert position in reducer, but then how do i fetch route data for the Finish point?<br>
What is the correct approach here?</p>