{"version":3,"file":"static/chunks/37059.7a9078730527c49d.js","sources":["webpack://_N_E/./src/modules/sports/store/sportsEventsData/sportsEventsData.reducer.ts"],"sourceRoot":"","sourcesContent":["import Redux, { combineReducers } from 'redux';\nimport { IdDictionary } from '@legacyApp/types/default/IdDictionary';\nimport { setReducer } from '@legacyApp/methods/store/setReducer';\nimport { removeIndexArray } from '@legacyApp/client/modules/app/appService';\nimport {\n\tSPORTS_EVENTS_DATA_ADD_ID,\n\tSPORTS_EVENTS_DATA_LOADING,\n\tSPORTS_EVENTS_DATA_REMOVE_DATA,\n\tSPORTS_EVENTS_DATA_REMOVE_ID,\n\tSPORTS_EVENTS_DATA_UPDATE_DATA,\n} from './sportsEventsData.constants';\nimport { EventsDataElementId } from './sportsEventsData.actions';\n\nexport type SportEventsDataReducer = IdDictionary<IdDictionary<object>>;\n\nexport const dataReducer = (\n\tstate: SportEventsDataReducer = {},\n\taction: Redux.AnyAction,\n): SportEventsDataReducer => {\n\tif (action.type === SPORTS_EVENTS_DATA_UPDATE_DATA) {\n\t\treturn {\n\t\t\t...state,\n\t\t\t[action.dataType]: {\n\t\t\t\t...(state[action.dataType] || {}),\n\t\t\t\t...(action.data || {}),\n\t\t\t},\n\t\t};\n\t}\n\tif (action.type === SPORTS_EVENTS_DATA_REMOVE_DATA) {\n\t\tconst newState = { ...state };\n\t\tif (newState[action.dataType]?.[action.eventId]) {\n\t\t\tdelete newState[action.dataType][action.eventId];\n\t\t}\n\t\treturn newState;\n\t}\n\treturn state;\n};\n\nexport type SportEventsIdsReducer = IdDictionary<\n\tIdDictionary<EventsDataElementId[]>\n>;\n\nexport const idsReducer = (\n\tstate: SportEventsIdsReducer = {},\n\taction: Redux.AnyAction,\n): SportEventsIdsReducer => {\n\tif (action.type === SPORTS_EVENTS_DATA_ADD_ID) {\n\t\tconst newState = { ...state };\n\t\tif (!newState[action.dataType]) {\n\t\t\tnewState[action.dataType] = {};\n\t\t}\n\t\tif (!newState[action.dataType][action.eventId]) {\n\t\t\tnewState[action.dataType][action.eventId] = [];\n\t\t}\n\t\tnewState[action.dataType][action.eventId].push(action.elementId);\n\t\treturn newState;\n\t}\n\tif (action.type === SPORTS_EVENTS_DATA_REMOVE_ID) {\n\t\tconst newState = { ...state };\n\t\tif (newState[action.dataType]?.[action.eventId]?.length) {\n\t\t\tconst index = newState[action.dataType][action.eventId].indexOf(\n\t\t\t\taction.elementId,\n\t\t\t);\n\t\t\tif (index > -1) {\n\t\t\t\tnewState[action.dataType][action.eventId] = removeIndexArray(\n\t\t\t\t\tnewState[action.dataType][action.eventId],\n\t\t\t\t\tindex,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tif (\n\t\t\tnewState[action.dataType]?.[action.eventId] &&\n\t\t\t!newState[action.dataType]?.[action.eventId].length\n\t\t) {\n\t\t\tdelete newState[action.dataType][action.eventId];\n\t\t}\n\t\treturn newState;\n\t}\n\treturn state;\n};\n\nexport interface SportsEventsDataReducerType {\n\tids: SportEventsIdsReducer;\n\tdata: SportEventsDataReducer;\n\tloading: boolean;\n}\n\nconst loadingReducer = setReducer(false, SPORTS_EVENTS_DATA_LOADING);\n\nconst sportsEventsDataReducer = combineReducers({\n\tids: idsReducer,\n\tdata: dataReducer,\n\tloading: loadingReducer,\n});\n\nexport default sportsEventsDataReducer;\n"],"names":["dataReducer","state","action","type","SPORTS_EVENTS_DATA_UPDATE_DATA","dataType","data","SPORTS_EVENTS_DATA_REMOVE_DATA","newState","eventId","idsReducer","SPORTS_EVENTS_DATA_ADD_ID","push","elementId","SPORTS_EVENTS_DATA_REMOVE_ID","length","index","indexOf","removeIndexArray","loadingReducer","setReducer","SPORTS_EVENTS_DATA_LOADING","sportsEventsDataReducer","combineReducers","ids","loading"],"mappings":";;uyBAeO,IAAMA,EAAc,WAGE,IAF5BC,EAE4B,uDAFI,GAChCC,EAC4B,uCAC5B,GAAIA,EAAOC,OAASC,EAAAA,GACnB,OAAO,EAAP,KACIH,GADJ,cAEEC,EAAOG,SAFT,OAGM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