Farmbot-Web-App/frontend/config/reducer.ts

22 lines
734 B
TypeScript
Raw Normal View History

2017-06-29 12:54:02 -06:00
import { generateReducer } from "../redux/generate_reducer";
import { ChangeApiHost, ChangeApiPort, ConfigState } from "./interfaces";
import { API } from "../api";
import { Actions } from "../constants";
2017-08-28 05:49:13 -06:00
const initialState: ConfigState = {
2017-06-29 12:54:02 -06:00
host: location.hostname,
// It gets annoying to manually change the port # in dev mode.
// I automatically point to port 3000 on local.
port: API.inferPort()
};
export const configReducer = generateReducer<ConfigState>(initialState)
2017-06-29 12:54:02 -06:00
.add<ChangeApiPort>(Actions.CHANGE_API_PORT, (s, { payload }) => {
s.port = payload.port.replace(/\D/g, "");
return s;
})
.add<ChangeApiHost>(Actions.CHANGE_API_HOST, (s, { payload }) => {
s.host = payload.host;
return s;
});