Clean code.

This commit is contained in:
Lars Jung 2016-06-25 00:39:57 +02:00
parent 95c473a7c7
commit 9234e3f287
6 changed files with 22 additions and 51 deletions

View file

@ -71,18 +71,9 @@ const encodedHref = href => {
return forceEncoding(location); return forceEncoding(location);
}; };
const getDomain = () => { const getDomain = () => doc.domain;
return doc.domain; const getAbsHref = () => absHref;
}; const getItem = () => require('../model/item').get(absHref);
const getAbsHref = () => {
return absHref;
};
const getItem = () => {
const Item = require('../model/item');
return Item.get(absHref);
};
const load = callback => { const load = callback => {
request({action: 'get', items: {href: absHref, what: 1}}).then(json => { request({action: 'get', items: {href: absHref, what: 1}}).then(json => {

View file

@ -9,9 +9,7 @@ const defaultThemeHref = themesHref + 'default/';
const defaultIcons = ['file', 'folder', 'folder-page', 'folder-parent', 'ar', 'aud', 'bin', 'img', 'txt', 'vid', 'x']; const defaultIcons = ['file', 'folder', 'folder-page', 'folder-parent', 'ar', 'aud', 'bin', 'img', 'txt', 'vid', 'x'];
const image = id => { const image = id => uiHref + id + '.svg';
return uiHref + id + '.svg';
};
const icon = id => { const icon = id => {
const baseId = (id || '').split('-')[0]; const baseId = (id || '').split('-')[0];

View file

@ -21,9 +21,7 @@ const put = (key, value) => {
save(obj); save(obj);
}; };
const get = key => { const get = key => load()[key];
return load()[key];
};
module.exports = { module.exports = {

View file

@ -1,12 +1,4 @@
const regularCmpFn = (val1, val2) => { const regularCmpFn = (x, y) => x < y ? -1 : x > y ? 1 : 0;
if (val1 < val2) {
return -1;
}
if (val1 > val2) {
return 1;
}
return 0;
};
// Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license // Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license
// Author: Jim Palmer (based on chunking idea from Dave Koelle) // Author: Jim Palmer (based on chunking idea from Dave Koelle)

View file

@ -25,13 +25,10 @@ const intersection = (obj1, obj2) => {
obj2 = values(obj2); obj2 = values(obj2);
return filter(obj1, x => obj2.indexOf(x) >= 0); return filter(obj1, x => obj2.indexOf(x) >= 0);
}; };
const cmp = (x, y) => x < y ? -1 : x > y ? 1 : 0;
const sortBy = (obj, sel) => { const sortBy = (obj, sel) => {
const selFn = isFn(sel) ? sel : x => x[sel]; const selFn = isFn(sel) ? sel : x => x[sel];
const cmpFn = (x, y) => { const cmpFn = (x, y) => cmp(selFn(x), selFn(y));
x = selFn(x);
y = selFn(y);
return x < y ? -1 : x > y ? 1 : 0;
};
return values(obj).sort(cmpFn); return values(obj).sort(cmpFn);
}; };
const debounce = (fn, delay) => { const debounce = (fn, delay) => {

View file

@ -4,19 +4,12 @@ const location = require('../core/location');
const settings = require('../core/settings'); const settings = require('../core/settings');
const types = require('../core/types'); const types = require('../core/types');
const reEndsWithSlash = /\/$/; const reEndsWithSlash = /\/$/;
const reSplitPath = /^(.*\/)([^\/]+\/?)$/; const reSplitPath = /^(.*\/)([^\/]+\/?)$/;
const cache = {}; const cache = {};
const startsWith = (sequence, part) => { const startsWith = (sequence, part) => isStr(sequence) && sequence.startsWith(part);
if (!sequence || !sequence.indexOf) {
return false;
}
return sequence.indexOf(part) === 0;
};
const createLabel = sequence => { const createLabel = sequence => {
sequence = sequence.replace(reEndsWithSlash, ''); sequence = sequence.replace(reEndsWithSlash, '');
@ -26,7 +19,7 @@ const createLabel = sequence => {
return sequence; return sequence;
}; };
const splitPath = sequence => { // eslint-disable-line consistent-return const splitPath = sequence => {
if (sequence === '/') { if (sequence === '/') {
return { return {
parent: null, parent: null,
@ -35,17 +28,19 @@ const splitPath = sequence => { // eslint-disable-line consistent-return
} }
const match = reSplitPath.exec(sequence); const match = reSplitPath.exec(sequence);
if (match) { if (!match) {
const split = { return null;
parent: match[1],
name: match[2]
};
if (split.parent && !startsWith(split.parent, settings.rootHref)) {
split.parent = null;
}
return split;
} }
const split = {
parent: match[1],
name: match[2]
};
if (split.parent && !startsWith(split.parent, settings.rootHref)) {
split.parent = null;
}
return split;
}; };
const getItem = options => { const getItem = options => {