import { register, waitFor } from '../dispatcher/Dispatcher';
import { createStore, mergeIntoBag, isInBag } from '../utils/StoreUtils';
import UserStore from '../stores/UserStore';
import ActionTypes from '../constants/ActionTypes';
import selectn from 'selectn';

let _like = {};

const LikeStore = createStore({
    contains(userId1, userId2) {

        return (userId1 in _like && (userId2 in _like[userId1])) ||
            (userId2 in _like && (userId1 in _like[userId2]));
    },

    get(userId1, userId2) {

        if (userId1 in _like && (userId2 in _like[userId1])){
            return _like[userId1][userId2];
        } else if (userId2 in _like && (userId1 in _like[userId2])) {
            return _like[userId2][userId1];
        } else {
            return null;
        }
    },

    merge(userId1, userId2, value){
        _like[userId1] = (userId1 in _like) ? _like[userId1] : [];
        _like[userId1][userId2] = value;
    }
});

LikeStore.dispatchToken = register(action => {

    waitFor([UserStore.dispatchToken]);
    if (action.type == ActionTypes.LIKE_USER_SUCCESS
        || action.type == ActionTypes.UNLIKE_USER_SUCCESS)
    {
        const {from, to} = action;

        LikeStore.merge(from, to, action.type == ActionTypes.LIKE_USER_SUCCESS);
        LikeStore.emitChange();

    }
    else if (action.type == ActionTypes.REQUEST_LIKE_USER_SUCCESS)
    {
        const {from, to} = action;
        const like = selectn('response.result', action)? 1 : 0 ;

        LikeStore.merge(from, to, like);
        LikeStore.emitChange();
    }

    if (action.type == ActionTypes.LOGOUT_USER){
        _like = {};
    }
});

export default LikeStore;
@@ -569,16 +569,17 @@
 erId1%5D))
+ 
 %7B%0A      
@@ -1136,36 +1136,32 @@
 KE_USER_SUCCESS)
-%0A   
  %7B%0A        const
@@ -1369,20 +1369,16 @@
 SUCCESS)
-%0A   
  %7B%0A     
@@ -1466,16 +1466,23 @@
 ion)
+ 
 ? 
-1 : 0 
+true : false
 ;%0A%0A 
@@ -1607,16 +1607,17 @@
 UT_USER)
+ 
 %7B%0A      

Fix boolean value in like