dropdown_menu.js 656 B

123456789101112131415161718
  1. import Immutable from 'immutable';
  2. import {
  3. DROPDOWN_MENU_OPEN,
  4. DROPDOWN_MENU_CLOSE,
  5. } from '../actions/dropdown_menu';
  6. const initialState = Immutable.Map({ openId: null, placement: null, keyboard: false, scroll_key: null });
  7. export default function dropdownMenu(state = initialState, action) {
  8. switch (action.type) {
  9. case DROPDOWN_MENU_OPEN:
  10. return state.merge({ openId: action.id, placement: action.placement, keyboard: action.keyboard, scroll_key: action.scroll_key });
  11. case DROPDOWN_MENU_CLOSE:
  12. return state.get('openId') === action.id ? state.set('openId', null).set('scroll_key', null) : state;
  13. default:
  14. return state;
  15. }
  16. }