// Vendor modules import * as actions from "@nteract/actions"; import { makeTransformsRecord } from "@nteract/types"; import { List, Map } from "immutable"; import { Action, Reducer } from "redux"; import { combineReducers } from "redux-immutable"; import * as React from "react"; export const byId = ( state = Map(), action: Action ): Map => { let typedAction; switch (action.type) { case actions.ADD_TRANSFORM: typedAction = action as actions.AddTransform; return state.set( typedAction.payload.mediaType, typedAction.payload.component ); case actions.REMOVE_TRANSFORM: typedAction = action as actions.RemoveTransform; return state.delete(typedAction.payload.mediaType); default: return state; } }; export const displayOrder = ( state = List() as List, action: Action ): List => { let typedAction; switch (action.type) { case actions.ADD_TRANSFORM: typedAction = action as actions.AddTransform; return state.insert(0, typedAction.payload.mediaType); case actions.REMOVE_TRANSFORM: typedAction = action as actions.RemoveTransform; return state.delete(state.indexOf(typedAction.payload.mediaType)); default: return state; } }; export const transforms: Reducer< { byId: Map; displayOrder: List; }, Action > = combineReducers({ byId, displayOrder }, makeTransformsRecord as any);