import cloneObj from '../clone' ; type Actions = { type : string ; name ? : string ; } ; type InitialState = { [ key ] : any ; } ; const initialState = { } ; export default ( state = cloneObj ( initialState ) , action ) => { switch ( action . type ) { case 'SAVE_SCROLL_POSITION' : if ( action . name ) { state [ action . name ] = window . pageYOffset || document . documentElement . scrollTop || document . body . scrollTop || 0 ; } break ; case 'SET_SCROLL_POSITION' : window . scrollTo ( 0 , action . name && state [ action . name ] ? state [ action . name ] : 0 ) ; break ; case 'CLEAN' : state = { } ; break ; } return cloneObj ( state ) ; } ;