network-resurrector-frontend/src/state/reducer.js

35 lines
803 B
JavaScript
Raw Normal View History

2020-12-19 03:38:04 +02:00
export function reducer(state, action) {
switch (action.type) {
2020-12-19 04:22:38 +02:00
case "onCredentialsChange": {
const { prop, value } = action.payload;
2020-12-19 03:38:04 +02:00
return {
...state,
2020-12-19 04:22:38 +02:00
credentials: {
...state.credentials,
[prop]: value
2020-12-19 03:38:04 +02:00
}
};
}
2020-12-23 01:51:23 +02:00
case "onNetworkChange": {
const { prop, value } = action.payload;
return {
...state,
network: {
...state.network,
[prop]: value
}
};
}
2020-12-19 03:38:04 +02:00
default: {
return state;
}
}
}
export const dispatchActions = dispatch => ({
2020-12-19 04:22:38 +02:00
onCredentialsChange: (prop, value) =>
2020-12-23 01:51:23 +02:00
dispatch({ type: "onCredentialsChange", payload: { prop, value } }),
onNetworkChange: (prop, value) =>
2020-12-23 10:42:20 +02:00
dispatch({ type: "onNetworkChange", payload: { prop, value } })
2020-12-19 03:38:04 +02:00
});