Rev 1146 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import { TOPIC_ACTIONS } from './topics.types'const initialState = {topicsAllIds: [],topicById: {},capsulesAllIds: [],capsuleById: {},slidesAllIds: [],slideById: {}}const topicsReducer = (state = initialState, { type, payload }) => {switch (type) {case TOPIC_ACTIONS.ADD_TOPIC: {const topic = payloadconst topicsIds = new Set([...state.topicsAllIds, topic.uuid])return {...state,topicById: {...state.topicById,[topic.uuid]: topic},topicsAllIds: Array.from(topicsIds)}}case TOPIC_ACTIONS.ADD_CAPSULE: {const capsule = payloadconst capsulesIds = new Set([...state.capsulesAllIds, capsule.uuid])return {...state,capsuleById: {...state.capsuleById,[capsule.uuid]: capsule},capsulesAllIds: Array.from(capsulesIds)}}case TOPIC_ACTIONS.ADD_SLIDE: {const slide = payloadconst slidesIds = new Set([...state.slidesAllIds, slide.uuid])return {...state,slideById: {...state.slideById,[slide.uuid]: slide},slidesAllIds: Array.from(slidesIds)}}default:return state}}export default topicsReducer