import Reflux from 'reflux';
import UserActions from '../actions/UserActions';

var user = JSON.parse(localStorage.user);

var UserStore = Reflux.createStore({
  listenables: UserActions,

  user() {
    return user;
  },

  onLoggedIn(jsonUser) {
    user = jsonUser;
    localStorage.user = JSON.stringify(jsonUser);
  },

  onLoggedOut() {
    user = null;
    delete localStorage.user;
  },
});

export default UserStore;

import Reflux from 'reflux';
import UserActions from '../actions/UserActions';

var user = JSON.parse(localStorage.user || null);

var UserStore = Reflux.createStore({
  listenables: UserActions,

  user() {
    return user;
  },

  onLoggedIn(jsonUser) {
    user = jsonUser;
    localStorage.user = JSON.stringify(jsonUser);
  },

  onLoggedOut() {
    user = null;
    delete localStorage.user;
  },
});

export default UserStore;

Fix calling JSON.parse on undefined
Fix calling JSON.parse on undefined

This throws an exception in Chrome. So feed `null` to `JSON.parse` which
returns `null`.
