Fix most eslint warnings

This commit is contained in:
uwap 2018-01-19 21:52:53 +01:00
parent 196aa44895
commit 8d2d39cb0e
6 changed files with 16 additions and 12 deletions

View file

@ -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
}
};

View file

@ -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<AppProps & Classes, AppState> {
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;

View file

@ -18,9 +18,10 @@ import keyOf from "utils/keyOf";
type UiItemProps<I> = {
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<I:Object> extends React.Component<UiItemProps<I>> {
constructor(props: UiItemProps<I>) {
super(props);
@ -58,7 +59,7 @@ export class UiControl<I: UIControl> extends UiItem<I> {
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<UIToggle> {
}
export class DropDown extends UiControl<UIDropDown> {
runPrimaryAction = (next?: any) => {
runPrimaryAction = (next?: Actual) => {
if (this.isEnabled()) {
const control = this.props.item;
const keys = _.keys(control.options);

View file

@ -18,7 +18,7 @@ import { Toggle, DropDown, Link, Section, Text } from "./UiItem";
export type UiItemListProps = {
controls: Array<ControlUI>,
state: State,
onChangeState: (topic: string, nextState: any) => void
onChangeState: (topic: string, nextState: Actual) => void
};
export default class UiItemList extends React.Component<UiItemListProps> {

View file

@ -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 <i className={`${extraClass || ""} ${parseIconName(name)}`}></i>;
};
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<string, Internal> = getInternals(state);
const actuals: Map<string, Actual> = 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);
};

View file

@ -123,6 +123,8 @@ declare type Space = {
mqtt: string
};
declare type Internal = string;
declare type Actual = any;
declare type StateValue = {
internal: string,
actual: any