Skip to content

Commit

Permalink
remove extra loop
Browse files Browse the repository at this point in the history
  • Loading branch information
giuseppeg committed May 13, 2017
1 parent 4ea091e commit 48e84f9
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,18 +237,19 @@ export const combinePlugins = plugins => {
throw new Error('`plugins` must be an array of plugins names')
}

const loadedPlugins = plugins.map(plugin => {
// eslint-disable-next-line import/no-dynamic-require
const p = require(plugin)
return (p && p.default) || p
})

loadedPlugins.forEach((plugin, i) => {
const type = typeof plugin
if (type !== 'function') {
throw new Error(`Expected plugin ${plugins[i]} to be a function but instead got ${type}`)
}
})
return plugins
.map((plugin, i) => {
// eslint-disable-next-line import/no-dynamic-require
let p = require(plugin)
if (p.default) {
p = p.default
}

return loadedPlugins.reduce((plugin, nextPlugin) => css => nextPlugin(plugin(css)))
const type = typeof p
if (type !== 'function') {
throw new Error(`Expected plugin ${plugins[i]} to be a function but instead got ${type}`)
}
return p
})
.reduce((plugin, nextPlugin) => css => nextPlugin(plugin(css)))
}

0 comments on commit 48e84f9

Please sign in to comment.