"use strict";

import Dispatcher     from "../dispatcher";
import Constants      from "../constants";
import StoreCommon    from "./store_common";
import assign         from "object-assign";

let _user = {};

// log the user in
function login(email, password){
  return true;
}

// Register
function register(user){
  return true; 
}

// Extend User Store with EventEmitter to add eventing capabilities
let UserStore = assign({}, StoreCommon, {

  // Return current user
  current(){
    return _user;
  },

  loggedIn(){
    return _user.email !== undefined;
  },

  token(){
    return _user.token;
  }

});

// Register callback with Dispatcher
Dispatcher.register(function(payload) {
  let action = payload.action;
  
  switch(action){

    // Respond to LOGIN action
    case Constants.LOGIN:
      login(payload.email, payload.password);
      break;

    // Respond to REGISTER action
    case Constants.REGISTER:
      register(payload.user);
      break;

    default:
      return true;
  }

  // If action was responded to, emit change event
  UserStore.emitChange();

  return true;

});

export default UserStore;


@@ -185,19 +185,19 @@
 sign%22;%0A%0A
-let
+var
  _user =
@@ -396,19 +396,19 @@
 ilities%0A
-let
+var
  UserSto
@@ -687,11 +687,11 @@
 %7B%0A  
-let
+var
  act

Change let to var