import cloneObj from '../clone' ; type Actions = { type : string ; data ? : any ; id ? : string ; name ? : string ; state ? : any ; update ? : any ; status ? : boolean ; selfId ? : string ; followStatus ? : boolean ; } ; type InitialState = { [ key ] : any ; } ; const initialState = { } ; export default ( state = cloneObj ( initialState ) , action ) => { switch ( action . type ) { case 'SET_FOLLOW' : state = action . state ; case 'SET_FOLLOW_LIST_BY_ID' : var { name , data } = action ; if ( name && data ) state [ name ] = data ; break ; case 'UPDATE_FOLLOW' : var { id , selfId , followStatus } = action ; for ( let i in state ) { let data = state [ i ] . data ; if ( data . length > 0 ) { data . map ( ( item ) => { if ( item . people_id && item . people_id . _id == id ) { item . people_id . follow = followStatus ; } if ( item . people_id && item . people_id . _id == selfId ) { item . people_id . follow_people_count += followStatus ? 1 : - 1 ; } if ( item . user_id && item . user_id . _id == id ) { item . user_id . follow = followStatus ; } if ( item . user_id && item . user_id . _id == selfId ) { item . user_id . fans_count += followStatus ? 1 : - 1 ; } if ( item . topic_id && item . topic_id . _id == id ) { item . topic_id . follow = followStatus ; } if ( item . posts_id && item . posts_id . _id == id ) { item . posts_id . follow = followStatus ; } } ) ; } } break ; case 'CLEAN' : state = { } ; break ; default : return state ; } return cloneObj ( state ) ; } ; export const getFollowListById = ( state , id ) => state . follow [ id ] ;