title: Subscription in Redux Weird behaviour of subscription in Redux
body: <p>I am learning redux at the moment. Code shared below is independent of React, so React integration is out of consideration.</p>
  
  <p>Below is redux-basics.js which has <strong>Reducer, Store , Action and Subscription</strong> Section</p>
  
  <pre><code>const redux = require('redux');
  const createStore =  redux.createStore;
  // Note : Store Creation is actually dependent on Reducer Thats why reducer must be created first.
  // Reducer
  const initialState = {  counter : 0}
  
  const rootReducer = (state = initialState,action) =&gt; {
  
       if(action.type === 'INCR_COUNTER'){
           return  {  ...state, 
              counter : state.counter + 1 }
       }
  
       if(action.type === 'ADD_COUNTER'){
          return  {  ...state, 
             counter : state.counter + action.value }
      }
  
  
      return state;
  }
  // Store 
  const store = createStore(rootReducer);
  console.log(store.getState())
  
  
  // Subscription
  store.subscribe(() =&gt; {
      console.log(" SUbscription " , store.getState()  );
  })
  
  
  
  // Despatching an Action 
  store.dispatch({type : "INCR_COUNTER"});
  store.dispatch({type: "ADD_COUNTER",
   value : 10
  });
  
  
  
  console.log(store.getState());
  </code></pre>
  
  <p>Then I get output like below ( <strong>And which is correct!</strong> ):</p>
  
  <pre><code>Ps-MBP:redux--01-start pramod$ node redux-basics.js 
  { counter: 0 }
   SUbscription  { counter: 1 }
   SUbscription  { counter: 11 }
  { counter: 11 }
  </code></pre>
  
  <p>But when I move listeners below dispatch method then subscriptions wont work? I am trying what I am missing or why is so? Code I am doing is like below: ( <strong>I thought it will print subscription method output, but it isn't</strong>)</p>
  
  <pre><code>// Despatching an Action 
  store.dispatch({type : "INCR_COUNTER"});
  store.dispatch({type: "ADD_COUNTER",
   value : 10
  });
  
  // Subscription
  store.subscribe(() =&gt; {
      console.log(" SUbscription " , store.getState()  );
  })
  
  
  
  console.log(store.getState())
  </code></pre>
  
  <p>After making above code shifting code output is as below:</p>
  
  <pre><code>Pramod:redux--01-start pramod$ node redux-basics.js 
  { counter: 0 }
  { counter: 11 }
  </code></pre>
  
  <p>Any hint/idea why is so?</p>