Fix some flow errors

This commit is contained in:
uwap 2017-11-14 13:13:31 +01:00
parent 9e45e7f398
commit 48e9572925
4 changed files with 24 additions and 22 deletions

View file

@ -9,6 +9,8 @@ types/types.js
[options]
esproposal.export_star_as=enable
unsafe.enable_getters_and_setters=true
module.system.node.resolve_dirname=node_modules
module.system.node.resolve_dirname=src
[lints]
all=warn

View file

@ -7,7 +7,7 @@ import parseIconName, { controlGetIcon } from "utils/parseIconName";
export type Point = [number, number];
const convertPoint = (p: Point) => [-p[1], p[0]];
const convertPoint = ([y,x]: Point): Point => [-x, y];
export type ControlMapProps = {
width: number,
@ -20,7 +20,7 @@ export type ControlMapProps = {
};
export default class ControlMap extends React.Component<ControlMapProps> {
constructor(props: SpaceMapProps) {
constructor(props: ControlMapProps) {
super(props);
}
@ -57,16 +57,16 @@ export default class ControlMap extends React.Component<ControlMapProps> {
});
}
iconColor(control: Control) {
if (control.iconColor == null) {
return "#000";
}
iconColor(control: Control): string {
if (control.iconColor != null) {
return control.iconColor(
_.mapValues(this.props.state, (x) => x.internal || x.actual),
_.mapValues(this.props.state, (x) => x.actual),
this.props.state
);
}
return "#000";
}
renderMarker(control: Control, key: string) {
return (
@ -97,7 +97,7 @@ export default class ControlMap extends React.Component<ControlMapProps> {
checked={layer.defaultVisibility === "visible"}>
<ImageOverlay url={layer.image}
bounds={Object.values(layer.bounds).map(convertPoint)}
opacity={layer.opacity} />
opacity={layer.opacity || 1} />
</LayersControlType>
);
}

View file

@ -11,7 +11,7 @@ export const renderIcon = (name: string, extraClass?: string) => {
};
export const controlGetIcon = (control: Control, state: State): string => {
return !_.isFunction(control.icon) ? control.icon
return typeof control.icon !== "function" ? control.icon
: control.icon(
_.mapValues(state, (x) => x.internal || x.actual),
_.mapValues(state, (x) => x.actual),

View file

@ -14,7 +14,7 @@ declare type Topic = {
declare type Topics = Map<string,Topic>;
declare type ControlUI = {
type: "toggle" | "dropDown" | "slider" | "section",
type: "toggle" | "dropDown" | "slider" | "section" | "link",
text: string,
topic?: string,
icon?: string,
@ -66,10 +66,15 @@ declare type Config = {
declare type Space = {
name: string,
color: "red"|"pink"|"purple"|"deepPurple"|"indigo"|"blue"|"lightBlue"|"cyan"|"teal"|
"green"|"lightgreen"|"lime"|"yellow"|"amber"|"orange"|"deepOrange"|"brown"|"grey"|"blueGrey"
"green"|"lightGreen"|"lime"|"yellow"|"amber"|"orange"|"deepOrange"|"brown"|"grey"|"blueGrey",
mqtt: string
};
declare type State = Map<string,any>;
declare type StateValue = {
internal: string,
actual: any
};
declare type State = Map<string,StateValue>;
//declare type State = {
// mqtt: ?any,
@ -89,16 +94,11 @@ declare type Point = [number, number];
declare type Layer = {
image: string,
name: string,
baseLayer: boolean,
baseLayer?: boolean,
defaultVisibility: "visible" | "hidden",
opacity: number,
opacity?: number,
bounds: {
topLeft: Point,
bottomRight: Point
}
};
declare type StateAction = {
type: "DISCONNECT" | "CONNECT" | "MESSAGE" | "UI_POPUP",
payload?: any
};