redux how to get or store computed values
<p>How should I implement in redux computed values based on it's current state?</p>

<p>I have this for an example a sessionState</p>

<pre><code>const defaultState = {
  ui: {
    loading: false
  }, metadata: { },
  data: {
    id: null
  }
}

export default function sessionReducer(state = defaultState, action) {
  switch(action.type) {
  case STORE_DATA:
    return _.merge({}, state, action.data);
  case PURGE_DATA:
    return defaultState;
  default:
    return state;
  }
}
</code></pre>

<p>Say for example I want to get if the session is logged in, I usually do right now is <code>sessionState.data.id</code> to check it, but I want to know how I can do <code>sessionState.loggedIn</code> or something?</p>

<p>Can this do?</p>

<pre><code>const defaultState = {
  ui: {
    loading: false
  }, metadata: { },
  data: {
    id: null
  },
  loggedIn: () =&gt; {
    this.data.id
  }
}
</code></pre>

<p>or something (that's not tested, just threw that in). In this example it looks simple to just write <code>.data.id</code> but maybe when it comes to computations already, it's not good to write the same computations on different files.</p>