mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
34 lines
949 B
JavaScript
34 lines
949 B
JavaScript
import * as types from "../constants/actionTypes";
|
|
|
|
const initialState = {
|
|
all: [],
|
|
active: null
|
|
};
|
|
|
|
function requestsReducer (state = [], action) {
|
|
switch (action.type) {
|
|
case types.REQUEST_ADD:
|
|
return [...state, action.request];
|
|
case types.REQUEST_UPDATE:
|
|
return state.map(request => request.id === action.request.id ? action.request : request);
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
export default function (state = initialState, action) {
|
|
let all, active;
|
|
switch (action.type) {
|
|
case types.REQUEST_ADD:
|
|
all = requestsReducer(state.all, action);
|
|
active = state.active || action.request;
|
|
return Object.assign({}, state, {all, active});
|
|
case types.REQUEST_UPDATE:
|
|
all = requestsReducer(state.all, action);
|
|
active = state.active.id === action.request.id ? action.request : state.active;
|
|
return Object.assign({}, state, {all, active});
|
|
default:
|
|
return state
|
|
}
|
|
}
|