Files
Hydro/packages/ui-default/components/scratchpad/reducers/pretest.js
T
undefined 5faa54c7ca ui-default: init
将ui-default合并至主存储库便于维护
2021-04-03 01:44:22 +08:00

30 lines
646 B
JavaScript

export default function reducer(state = {
input: '',
output: '',
rid: null,
}, action) {
if (action.type === 'SCRATCHPAD_PRETEST_DATA_CHANGE') {
const { type, value } = action.payload;
return {
...state,
[type]: value,
};
}
if (action.type === 'SCRATCHPAD_RECORDS_PUSH') {
const { rdoc } = action.payload;
if (rdoc._id === state.rid && rdoc.testCases[0]) {
return {
...state,
output: rdoc.testCases[0].message,
};
}
}
if (action.type === 'SCRATCHPAD_POST_PRETEST_FULFILLED') {
return {
...state,
rid: action.payload.rid,
};
}
return state;
}