import { createReducer } from "typesafe-actions";
import ISerialConnectionState from "../../interfaces/ISerialConnectionState";
import { SerialConnectionActionTypes } from "../actions/serialConnectionActions";
const initialState: ISerialConnectionState = {
port: null,
portController: null,
status: {
connecting: false,
connected: false,
error: null,
},
};
const SerialConnectionReducer = createReducer(initialState)
.handleType(SerialConnectionActionTypes.SET_SERIAL_PORT, (state, action) => ({
...state,
port: action.payload,
}))
.handleType(SerialConnectionActionTypes.CONNECTION_START, (state) => ({
connecting: true,
.handleType(SerialConnectionActionTypes.CONNECTION_FAILURE, (state, action) => ({
error: action.payload.message,
.handleType(SerialConnectionActionTypes.CONNECTION_SUCCESS, (state) => ({
connected: true,
.handleType(SerialConnectionActionTypes.CONNECTION_END, (state) => ({
...state.status,
.handleType(SerialConnectionActionTypes.SET_PORT_CONTROLLER, (state, action) => ({
portController: action.payload,
}));
export default SerialConnectionReducer;