diff --git a/.eslintrc.js b/.eslintrc.js index 522ce82..e03c58d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -137,6 +137,6 @@ module.exports = { // flow "flowtype/no-dupe-keys": "error", "flowtype/no-weak-types": "warn", - "flowtype/require-variable-type": "warn" + "flowtype/require-variable-type": "off" // wait for https://github.com/gajus/eslint-plugin-flowtype/issues/198 to be resolved } }; diff --git a/src/components/App.js b/src/components/App.js index 671fb62..45508f5 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -25,7 +25,7 @@ export type AppState = { selectedControl: ?Control, drawerOpened: boolean, mqttState: State, - mqttSend: (topic: string, value: any) => void, + mqttSend: (topic: string, value: Actual) => void, mqttConnected: boolean, }; @@ -91,7 +91,7 @@ class App extends React.Component { this.setState({drawerOpened: false}); } - changeState(topic: string, value: any) { + changeState(topic: string, value: Actual) { const rawTopic = this.props.config.topics[topic].command; if (rawTopic == null) { return; diff --git a/src/components/UiItemList/UiItem.js b/src/components/UiItemList/UiItem.js index 983495d..182017c 100644 --- a/src/components/UiItemList/UiItem.js +++ b/src/components/UiItemList/UiItem.js @@ -18,9 +18,10 @@ import keyOf from "utils/keyOf"; type UiItemProps = { item: I, state: State, - onChangeState: (topic: string, nextState: any) => void + onChangeState: (topic: string, nextState: Actual) => void }; +// eslint-disable-next-line flowtype/no-weak-types export default class UiItem extends React.Component> { constructor(props: UiItemProps) { super(props); @@ -58,7 +59,7 @@ export class UiControl extends UiItem { super(props); } - changeState(next: any) { + changeState(next: Actual) { if (this.props.item.topic == null) { throw new Error( `Missing topic in ${this.props.item.type} "${this.props.item.text}"` @@ -131,7 +132,7 @@ export class Toggle extends UiControl { } export class DropDown extends UiControl { - runPrimaryAction = (next?: any) => { + runPrimaryAction = (next?: Actual) => { if (this.isEnabled()) { const control = this.props.item; const keys = _.keys(control.options); diff --git a/src/components/UiItemList/index.js b/src/components/UiItemList/index.js index f089113..d393ba3 100644 --- a/src/components/UiItemList/index.js +++ b/src/components/UiItemList/index.js @@ -18,7 +18,7 @@ import { Toggle, DropDown, Link, Section, Text } from "./UiItem"; export type UiItemListProps = { controls: Array, state: State, - onChangeState: (topic: string, nextState: any) => void + onChangeState: (topic: string, nextState: Actual) => void }; export default class UiItemList extends React.Component { diff --git a/src/utils/parseIconName.js b/src/utils/parseIconName.js index 98e82ac..5b3e249 100644 --- a/src/utils/parseIconName.js +++ b/src/utils/parseIconName.js @@ -1,23 +1,24 @@ // @flow -import React from "react"; +import * as React from "react"; import _ from "lodash"; +import { getInternals, getActuals } from "utils/state"; export default function parseIconName(name: string): string { return `mdi ${name.split(" ").map((icon) => "mdi-".concat(icon)).join(" ")}`; } -export const renderIcon = (name: string, extraClass?: string) => { +export const renderIcon = (name: string, extraClass?: string): React.Node => { return ; }; export const controlGetIcon = (control: Control, state: State): string => { - const internals = _.mapValues(state, (x) => x.internal || x.actual); - const actuals = _.mapValues(state, (x) => x.actual); + const internals: Map = getInternals(state); + const actuals: Map = getActuals(state); return typeof control.icon !== "function" ? control.icon : control.icon(internals, actuals, state); }; export const renderControlIcon = (control: Control, - state: State, extraClass?: string) => { + state: State, extraClass?: string): React.Node => { return renderIcon(controlGetIcon(control, state), extraClass); }; diff --git a/types/types.js b/types/types.js index d9b7785..8dba59b 100644 --- a/types/types.js +++ b/types/types.js @@ -123,6 +123,8 @@ declare type Space = { mqtt: string }; +declare type Internal = string; +declare type Actual = any; declare type StateValue = { internal: string, actual: any