@shopgate/engage
Version:
Shopgate's ENGAGE library.
6 lines • 917 B
JavaScript
import{produce}from'immer';import{isDev,logger}from'@shopgate/engage/core/helpers';import{A11Y_INCREASE_MODAL_COUNT,A11Y_DECREASE_MODAL_COUNT}from"../constants";var defaultState={modalCount:0};/**
* Stores a11y state
* @param {Object} [state={}] The current state.
* @param {Object} action The action object.
* @returns {Object} The new state.
*/export default function a11y(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:defaultState;var action=arguments.length>1?arguments[1]:undefined;/* eslint-disable no-param-reassign */var producer=produce(function(draft){switch(action.type){case A11Y_INCREASE_MODAL_COUNT:{draft.modalCount+=1;break;}case A11Y_DECREASE_MODAL_COUNT:{draft.modalCount-=1;if(draft.modalCount<0){if(isDev){logger.warn('Modal count is negative, resetting to 0');}draft.modalCount=0;}break;}default:break;}});/* eslint-enable no-param-reassign */return producer(state);}