Skip to content

Commit

Permalink
Revert "Improved resolution of circularly dependent components (#316)" (
Browse files Browse the repository at this point in the history
#318)

This reverts commit aef60c9.
  • Loading branch information
diegohaz authored Sep 19, 2017
1 parent aef60c9 commit 2c87238
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions src/components/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
const merge = require('lodash/merge')

// https://github.com/diegohaz/arc/wiki/Atomic-Design#do-not-worry
const req = require.context('.', true, /\.\/[^/]+\/[^/]+\/index\.js$/)


// This exports all components, resolving circular dependencies in two steps:
// 1. export empty objects in place of each component
// 2. require each component and merge it into the existing export for that module

const componentPaths = []

// export an empty module for each component
req.keys().forEach((key) => {
const componentName = key.replace(/^.+\/([^/]+)\/index\.js/, '$1')
componentPaths.push({ componentName, key })
module.exports[componentName] = {}
})

// merge each component into its designated module
componentPaths.forEach(({ componentName, key }) => {
merge(module.exports[componentName], req(key).default)
module.exports[componentName] = req(key).default
})

0 comments on commit 2c87238

Please sign in to comment.