From a69bdba63f94ef78d6919b119b6f6536a4826777 Mon Sep 17 00:00:00 2001 From: rr- Date: Thu, 29 Sep 2016 11:16:55 +0200 Subject: [PATCH] client/build: ditch arrayToObject UglifyJS seems to have troubles using it, I didn't want to investigate it too much as it's just a syntactic sugar used in about 4 places so I just removed it altogether --- client/js/tags.js | 22 ++++----- client/js/util/misc.js | 52 ++++++++-------------- client/js/util/search.js | 6 +-- client/js/util/views.js | 96 ++++++++++++++++++++-------------------- 4 files changed, 81 insertions(+), 95 deletions(-) diff --git a/client/js/tags.js b/client/js/tags.js index 18b9b62..c0c301b 100644 --- a/client/js/tags.js +++ b/client/js/tags.js @@ -112,14 +112,14 @@ function getSuggestions(tagName) { return actualTag.suggestions || []; } -module.exports = misc.arrayToObject([ - getAllCategories, - getAllTags, - getTagByName, - getCategoryByName, - getNameToTagMap, - getOriginalTagName, - refreshExport, - getAllImplications, - getSuggestions, -], func => func.name); +module.exports = { + getAllCategories: getAllCategories, + getAllTags: getAllTags, + getTagByName: getTagByName, + getCategoryByName: getCategoryByName, + getNameToTagMap: getNameToTagMap, + getOriginalTagName: getOriginalTagName, + refreshExport: refreshExport, + getAllImplications: getAllImplications, + getSuggestions: getSuggestions, +}; diff --git a/client/js/util/misc.js b/client/js/util/misc.js index 72fc7db..3258030 100644 --- a/client/js/util/misc.js +++ b/client/js/util/misc.js @@ -213,36 +213,22 @@ function arraysDiffer(source1, source2, orderImportant) { source2.filter(value => !source1.includes(value)).length > 0); } -function arrayToObject(array, keySelector, valueSelector) { - if (keySelector === undefined) { - keySelector = item => item; - } - if (valueSelector === undefined) { - valueSelector = item => item; - } - return array.reduce((obj, item) => { - obj[keySelector(item)] = valueSelector(item); - return obj; - }, {}); -} - -module.exports = arrayToObject([ - range, - formatUrlParameters, - parseUrlParameters, - parseUrlParametersRoute, - formatRelativeTime, - formatFileSize, - formatMarkdown, - formatInlineMarkdown, - unindent, - enableExitConfirmation, - disableExitConfirmation, - confirmPageExit, - escapeHtml, - makeCssName, - splitByWhitespace, - arraysDiffer, - decamelize, - arrayToObject, -], func => func.name); +module.exports = { + range: range, + formatUrlParameters: formatUrlParameters, + parseUrlParameters: parseUrlParameters, + parseUrlParametersRoute: parseUrlParametersRoute, + formatRelativeTime: formatRelativeTime, + formatFileSize: formatFileSize, + formatMarkdown: formatMarkdown, + formatInlineMarkdown: formatInlineMarkdown, + unindent: unindent, + enableExitConfirmation: enableExitConfirmation, + disableExitConfirmation: disableExitConfirmation, + confirmPageExit: confirmPageExit, + escapeHtml: escapeHtml, + makeCssName: makeCssName, + splitByWhitespace: splitByWhitespace, + arraysDiffer: arraysDiffer, + decamelize: decamelize, +}; diff --git a/client/js/util/search.js b/client/js/util/search.js index ba5c2f7..8d5fca4 100644 --- a/client/js/util/search.js +++ b/client/js/util/search.js @@ -12,6 +12,6 @@ function searchInputNodeFocusHelper(inputNode) { }); } -module.exports = misc.arrayToObject([ - searchInputNodeFocusHelper, -], func => func.name); +module.exports = { + searchInputNodeFocusHelper: searchInputNodeFocusHelper, +}; diff --git a/client/js/util/views.js b/client/js/util/views.js index 31c19dd..7b5eca3 100644 --- a/client/js/util/views.js +++ b/client/js/util/views.js @@ -359,31 +359,31 @@ function getTemplate(templatePath) { if (!ctx) { ctx = {}; } - Object.assign(ctx, misc.arrayToObject([ - getPostUrl, - getPostEditUrl, - makeRelativeTime, - makeFileSize, - makeMarkdown, - makeThumbnail, - makeRadio, - makeCheckbox, - makeSelect, - makeInput, - makeButton, - makeTextarea, - makeTextInput, - makePasswordInput, - makeEmailInput, - makeColorInput, - makePostLink, - makeTagLink, - makeUserLink, - makeFlexboxAlign, - makeAccessKey, - misc.makeCssName, - makeNumericInput, - ], func => func.name)); + Object.assign(ctx, { + getPostUrl: getPostUrl, + getPostEditUrl: getPostEditUrl, + makeRelativeTime: makeRelativeTime, + makeFileSize: makeFileSize, + makeMarkdown: makeMarkdown, + makeThumbnail: makeThumbnail, + makeRadio: makeRadio, + makeCheckbox: makeCheckbox, + makeSelect: makeSelect, + makeInput: makeInput, + makeButton: makeButton, + makeTextarea: makeTextarea, + makeTextInput: makeTextInput, + makePasswordInput: makePasswordInput, + makeEmailInput: makeEmailInput, + makeColorInput: makeColorInput, + makePostLink: makePostLink, + makeTagLink: makeTagLink, + makeUserLink: makeUserLink, + makeFlexboxAlign: makeFlexboxAlign, + makeAccessKey: makeAccessKey, + makeCssName: misc.makeCssName, + makeNumericInput: makeNumericInput, + }); return htmlToDom(templateFactory(ctx)); }; } @@ -493,26 +493,26 @@ document.addEventListener('click', e => { } }); -module.exports = misc.arrayToObject([ - htmlToDom, - getTemplate, - emptyContent, - replaceContent, - enableForm, - disableForm, - decorateValidator, - makeVoidElement, - makeNonVoidElement, - makeTagLink, - makePostLink, - makeCheckbox, - makeRadio, - syncScrollPosition, - slideDown, - slideUp, - monitorNodeRemoval, - clearMessages, - showError, - showSuccess, - showInfo, -], func => func.name); +module.exports = { + htmlToDom: htmlToDom, + getTemplate: getTemplate, + emptyContent: emptyContent, + replaceContent: replaceContent, + enableForm: enableForm, + disableForm: disableForm, + decorateValidator: decorateValidator, + makeVoidElement: makeVoidElement, + makeNonVoidElement: makeNonVoidElement, + makeTagLink: makeTagLink, + makePostLink: makePostLink, + makeCheckbox: makeCheckbox, + makeRadio: makeRadio, + syncScrollPosition: syncScrollPosition, + slideDown: slideDown, + slideUp: slideUp, + monitorNodeRemoval: monitorNodeRemoval, + clearMessages: clearMessages, + showError: showError, + showSuccess: showSuccess, + showInfo: showInfo, +};