Refactor preprocessors module

This commit is contained in:
Surma
2018-08-01 12:32:29 +01:00
parent dce4fc70ac
commit c550fe9283
7 changed files with 63 additions and 70 deletions

View File

@@ -1,18 +1,10 @@
import { h, Component } from 'preact';
import { bind } from '../../lib/util';
// import * as styles from './styles.scss';
import { bind, inputFieldValueAsNumber } from '../../lib/util';
import { QuantizeOptions } from './quantizer';
type Props = {
options: QuantizeOptions,
onChange(newOptions: QuantizeOptions): void,
};
/**
* @param field An HTMLInputElement, but the casting is done here to tidy up onChange.
*/
function fieldValueAsNumber(field: any): number {
return Number((field as HTMLInputElement).value);
interface Props {
options: QuantizeOptions;
onChange(newOptions: QuantizeOptions): void;
}
export default class QuantizerOptions extends Component<Props, {}> {
@@ -21,8 +13,8 @@ export default class QuantizerOptions extends Component<Props, {}> {
const form = (event.currentTarget as HTMLInputElement).closest('form') as HTMLFormElement;
const options: QuantizeOptions = {
maxNumColors: fieldValueAsNumber(form.maxNumColors),
dither: fieldValueAsNumber(form.dither),
maxNumColors: inputFieldValueAsNumber(form.maxNumColors),
dither: inputFieldValueAsNumber(form.dither),
};
this.props.onChange(options);
}