refactor(cloudcmd) forEach -> for-of

This commit is contained in:
coderaiser 2019-05-20 18:54:26 +03:00
parent f7e47d2167
commit ee59fbf8d2
4 changed files with 22 additions and 30 deletions

View file

@ -29,16 +29,14 @@ module.exports.convert = (config) => {
const result = {
...config,
};
const array = Object.keys(config);
const array = Object.keys(result);
const filtered = array.filter(isBool(config));
array
.filter(isBool(result))
.forEach((name) => {
const item = result[name];
result[name] = setState(item);
});
for (const name of filtered) {
const item = config[name];
result[name] = setState(item);
}
return result;
};

View file

@ -44,9 +44,8 @@ const unselect = (event) => {
};
const execAll = currify((funcs, event) => {
funcs.forEach((fn) => {
for (const fn of funcs)
fn(event);
});
});
const Info = DOM.CurrentInfo;
@ -260,7 +259,7 @@ function toggleSelect(key, files) {
return DOM.toggleSelectedFile(file);
if (key.shift)
return files.forEach(DOM.selectFile);
return files.map(DOM.selectFile);
}
function changePanel(element) {
@ -404,16 +403,12 @@ function contextMenu() {
function dragndrop() {
const panels = DOM.getByClassAll('panel');
const select = () => {
[...panels].forEach((panel) => {
panel.classList.add('selected-panel');
});
const select = ({target}) => {
target.classList.add('selected-panel');
};
const unselect = () => {
[...panels].forEach((panel) => {
panel.classList.remove('selected-panel');
});
const unselect = ({target}) => {
target.classList.remove('selected-panel');
};
const onDrop = (event) => {
@ -458,13 +453,12 @@ function dragndrop() {
event.preventDefault();
};
Events.add('dragenter', select);
Events.add(['dragleave', 'drop'], unselect);
[...panels].forEach((panel) => {
Events.add('dragover', panel, onDragOver)
.add('drop', panel, onDrop);
});
for (const panel of panels)
Events
.add('dragover', panel, onDragOver)
.add('drop', panel, onDrop)
.add('dragenter', select)
.add(['dragleave', 'drop'], unselect);
}
function unload() {

View file

@ -16,7 +16,6 @@ module.exports = {
'C - Create User Menu File': async ({DOM, CloudCmd, tryToCatch}) => {
const {
Dialog,
RESTful,
CurrentInfo,
} = DOM;

View file

@ -168,21 +168,22 @@ function initConfig(Config, options) {
if (!options)
return config;
Object.keys(options).forEach((name) => {
const names = Object.keys(options);
for (const name of names) {
const isConfig = !!config[name];
const item = options[name];
const isFunc = itype.function(item);
if (!isFunc || !isConfig) {
config[name] = options[name];
return;
continue;
}
const func = config[name];
config[name] = () => {
exec.series([func, item]);
};
});
}
return config;
}