From e120f59ed4e0a666c4c220b1f74f0e070f54cdbf Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Mon, 14 Jan 2019 19:24:51 -0500 Subject: [PATCH] Simplify defaultPlugins module --- src/defaultPlugins.js | 113 ++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 54 deletions(-) diff --git a/src/defaultPlugins.js b/src/defaultPlugins.js index 20b7720f7..3d648d8a0 100644 --- a/src/defaultPlugins.js +++ b/src/defaultPlugins.js @@ -49,58 +49,63 @@ import whitespace from './plugins/whitespace' import width from './plugins/width' import zIndex from './plugins/zIndex' -// eslint-disable-next-line complexity -export default function(config) { - return [ - config.modules.lists === false ? () => {} : lists(), - config.modules.appearance === false ? () => {} : appearance(), - config.modules.backgroundAttachment === false ? () => {} : backgroundAttachment(), - config.modules.backgroundColors === false ? () => {} : backgroundColors(), - config.modules.backgroundPosition === false ? () => {} : backgroundPosition(), - config.modules.backgroundRepeat === false ? () => {} : backgroundRepeat(), - config.modules.backgroundSize === false ? () => {} : backgroundSize(), - config.modules.borderCollapse === false ? () => {} : borderCollapse(), - config.modules.borderColors === false ? () => {} : borderColors(), - config.modules.borderRadius === false ? () => {} : borderRadius(), - config.modules.borderStyle === false ? () => {} : borderStyle(), - config.modules.borderWidths === false ? () => {} : borderWidths(), - config.modules.cursor === false ? () => {} : cursor(), - config.modules.display === false ? () => {} : display(), - config.modules.flexbox === false ? () => {} : flexbox(), - config.modules.float === false ? () => {} : float(), - config.modules.fonts === false ? () => {} : fonts(), - config.modules.fontWeights === false ? () => {} : fontWeights(), - config.modules.height === false ? () => {} : height(), - config.modules.leading === false ? () => {} : leading(), - config.modules.margin === false ? () => {} : margin(), - config.modules.maxHeight === false ? () => {} : maxHeight(), - config.modules.maxWidth === false ? () => {} : maxWidth(), - config.modules.minHeight === false ? () => {} : minHeight(), - config.modules.minWidth === false ? () => {} : minWidth(), - config.modules.negativeMargin === false ? () => {} : negativeMargin(), - config.modules.objectFit === false ? () => {} : objectFit(), - config.modules.objectPosition === false ? () => {} : objectPosition(), - config.modules.opacity === false ? () => {} : opacity(), - config.modules.outline === false ? () => {} : outline(), - config.modules.overflow === false ? () => {} : overflow(), - config.modules.padding === false ? () => {} : padding(), - config.modules.pointerEvents === false ? () => {} : pointerEvents(), - config.modules.position === false ? () => {} : position(), - config.modules.resize === false ? () => {} : resize(), - config.modules.shadows === false ? () => {} : shadows(), - config.modules.svgFill === false ? () => {} : svgFill(), - config.modules.svgStroke === false ? () => {} : svgStroke(), - config.modules.tableLayout === false ? () => {} : tableLayout(), - config.modules.textAlign === false ? () => {} : textAlign(), - config.modules.textColors === false ? () => {} : textColors(), - config.modules.textSizes === false ? () => {} : textSizes(), - config.modules.textStyle === false ? () => {} : textStyle(), - config.modules.tracking === false ? () => {} : tracking(), - config.modules.userSelect === false ? () => {} : userSelect(), - config.modules.verticalAlign === false ? () => {} : verticalAlign(), - config.modules.visibility === false ? () => {} : visibility(), - config.modules.whitespace === false ? () => {} : whitespace(), - config.modules.width === false ? () => {} : width(), - config.modules.zIndex === false ? () => {} : zIndex(), - ] +function loadPlugins(modules, plugins) { + return Object.keys(plugins) + .filter(plugin => modules[plugin] !== false) + .map(plugin => plugins[plugin]()) +} + +export default function(config) { + return loadPlugins(config.modules, { + lists, + appearance, + backgroundAttachment, + backgroundColors, + backgroundPosition, + backgroundRepeat, + backgroundSize, + borderCollapse, + borderColors, + borderRadius, + borderStyle, + borderWidths, + cursor, + display, + flexbox, + float, + fonts, + fontWeights, + height, + leading, + margin, + maxHeight, + maxWidth, + minHeight, + minWidth, + negativeMargin, + objectFit, + objectPosition, + opacity, + outline, + overflow, + padding, + pointerEvents, + position, + resize, + shadows, + svgFill, + svgStroke, + tableLayout, + textAlign, + textColors, + textSizes, + textStyle, + tracking, + userSelect, + verticalAlign, + visibility, + whitespace, + width, + zIndex, + }) }