More ESLint options

This commit is contained in:
uwap 2017-11-07 01:32:22 +01:00
parent a60e800cee
commit 19b91cfd0a
8 changed files with 200 additions and 59 deletions

View file

@ -15,22 +15,29 @@ const initState : State = {
mqtt: null,
uiOpened: null,
values: R.map(
topic => { return {
internal: keyOf(topic.values, topic.defaultValue),
actual: topic.defaultValue
};}, Config.topics),
topic => {
return {
internal: keyOf(topic.values, topic.defaultValue),
actual: topic.defaultValue
};
}, Config.topics),
visibleLayers: []
};
const onMessage = (state: State, action: StateAction) => {
if (action.payload == undefined) return state;
// action.payload.topic is the mqtt topic
// topics is the list of all internal topic references
// that have their state topic set to action.payload.topic
const payload = action.payload == undefined ? { topic: "", message: {} }
if (action.payload == null) {
return state;
}
/*
* action.payload.topic is the mqtt topic
* topics is the list of all internal topic references
* that have their state topic set to action.payload.topic
*/
const payload = action.payload == null ? { topic: "", message: {} }
: action.payload; // thx flow </3
const topics = R.keys(R.pickBy(
val => val.state == payload.topic, Config.topics));
val => val.state === payload.topic, Config.topics));
const message = payload.message;
const parsedMessage = (topic: string) => {
let parseFunction = Config.topics[topic].parseState;
@ -43,7 +50,7 @@ const onMessage = (state: State, action: StateAction) => {
const newValue = (topic: string) => {
return {
actual: parsedMessage(topic),
internal: keyOf(Config.topics[topic].values,parsedMessage(topic))
internal: keyOf(Config.topics[topic].values, parsedMessage(topic))
};
};
return R.mergeDeepRight(state, R.objOf("values", R.mergeAll(
@ -51,14 +58,15 @@ const onMessage = (state: State, action: StateAction) => {
)));
};
const match = (value: any, array: Map<any,any>) => array[value];
const match = (value: any, array: Map<any, any>) => array[value];
const handleEvent = (state: State = initState, action: StateAction) => {
return match(action.type, {
[Actions.MQTT_CONNECT ]: R.merge(state, { mqtt: action.payload }),
[Actions.MQTT_MESSAGE ]: onMessage(state, action),
[Actions.CHANGE_UI ]: (() => {
[Actions.MQTT_CONNECT]: R.merge(state, { mqtt: action.payload }),
[Actions.MQTT_MESSAGE]: onMessage(state, action),
[Actions.CHANGE_UI]: (() => {
const control = Config.controls[action.payload];
if (action.toggle && control.ui.length > 0 && control.ui[0].type == "toggle") {
if (action.toggle && control.ui.length > 0
&& control.ui[0].type === "toggle") {
const props = control.ui[0];
onSwitch(props.topic, props, state)(null, !isToggled(state, props));
return state;