import cloneObj from '../clone' ; type Actions = { type : string ; state ? : any ; postsId ? : string ; commentId ? : string ; total ? : number ; } ; type InitialState = { posts ? : object ; comments ? : object ; } ; const initialState = { posts : { } , comments : { } } ; export default ( state = cloneObj ( initialState ) , action ) => { switch ( action . type ) { case 'INIT_HAS_READ_POSTS_STATE' : state = action . state ; break ; case 'ADD_POSTS_HAS_READ' : var { postsId , total = 0 } = action ; if ( postsId ) state . posts [ postsId ] = total ; break ; case 'ADD_COMMENT_HAS_READ' : var { commentId , total = 0 } = action ; if ( commentId ) state . comments [ commentId ] = total ; break ; case 'CLEAN' : state = { posts : { } , comments : { } } ; break ; default : return state ; } return cloneObj ( state ) ; } ; export function getHasReadByPostsId ( state , { postsId , total } ) { if ( typeof state . hasReadPosts . posts [ postsId ] != 'undefined' ) { return total - state . hasReadPosts . posts [ postsId ] ; } return - 1 ; } export function getHasReadByCommentId ( state , { commentId , total } ) { if ( typeof state . hasReadPosts . comments [ commentId ] != 'undefined' && state . hasReadPosts . comments [ commentId ] >= total ) { return true ; } return false ; }