refactor(config) fillTemplate: forEach -> squad, map

This commit is contained in:
coderaiser 2017-10-13 16:44:36 +03:00
parent 09059a0fe8
commit 74e351475e

View file

@ -7,6 +7,7 @@ require('../../css/config.css');
const rendy = require('rendy');
const exec = require('execon');
const currify = require('currify/legacy');
const squad = require('squad');
const input = require('../input');
const Images = require('../dom/images');
@ -26,6 +27,16 @@ const showLoad = () => {
Images.show.load('top');
};
const addKey = currify((fn, input) => {
Events.addKey(input, fn);
return input;
});
const addChange = currify((fn, input) => {
Events.add('change', input, fn);
return input;
});
CloudCmd.Config = ConfigProto;
let Loading = true;
@ -166,23 +177,20 @@ function fillTemplate(error, template) {
});
const inputs = document.querySelectorAll('input, select', Element);
const inputFirst = inputs[0];
const [inputFirst] = inputs;
let afterShow;
if (inputFirst) {
onAuthChange(inputFirst.checked);
afterShow = () => {
inputFirst.focus();
};
afterShow = inputFirst.focus.bind(inputFirst);
}
[...inputs].forEach((input) => {
Events.addKey(input, onKey)
.add('change', input, ({target}) => {
onChange(target);
});
});
const getTarget = ({target}) => target;
const handleChange = squad(onChange, getTarget);
[...inputs]
.map(addKey(onKey))
.map(addChange(handleChange));
const autoSize = true;
CloudCmd.View.show(Element, {