Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removing the "a" from "ARc" #343

Closed
EricWVGG opened this issue May 20, 2018 · 3 comments
Closed

removing the "a" from "ARc" #343

EricWVGG opened this issue May 20, 2018 · 3 comments

Comments

@EricWVGG
Copy link

EricWVGG commented May 20, 2018

I'm about 15 months into a ARc front end, and the experience has been great. Thank you so much for putting together such a good toolkit.

That said, we feel like we have “outgrown” the atomic component organization methodology. We have roughly 100 components, and would rather be organizing these in folders like "menu" and "account". I'm also starting another project on ARc, and my designer flatly refuses to even break ground with atomic.

Unfortunately, the webpack (is this right?) seems to be very finicky about the order of components. Off the bat, renaming "atoms" to "widgets" causes the higher-level components to fail. Renaming it to "_widgets" fixes the problem, but that won't be sustainable down the road.

I've tried to get some assistance through a Stack Overflow question (https://stackoverflow.com/questions/50335247/organizing-project-components-does-this-need-to-be-alphabetic) , but everyone seems to think I'm possibly crazy. Could you tell me a little about how this works?

(I apologize if github issues is the wrong place for an inquiry like this, but I've hit a wall.)

@diegohaz
Copy link
Owner

diegohaz commented May 20, 2018

Hi, @EricWVGG. It's good to know that you've reached this far with this approach. That's a great feedback.

I've implemented ARc without "A" in some cases, usually smaller projects with a few components, when I wanted to have a flat components folder.

In those cases, I've just removed the components/index.js file and started importing components directly (import Component from "../components/Component").

If you want to keep importing components dynamically, I'd recommend you to update [components/index.js]. You'll probably find a solution by reordering req keys.

const req = require.context('.', true, /\.\/[^/]+\/[^/]+\/index\.js$/)
req.keys().forEach((key) => {
const componentName = key.replace(/^.+\/([^/]+)\/index\.js/, '$1')
module.exports[componentName] = req(key).default
})

Another possible solution is to never use the component directly on the top level of your module (component file). JavaScript will be able to resolve the circular dependency at runtime (#131 (comment)).

@EricWVGG
Copy link
Author

I'll give that a crack.

https://strongwater.net, if you're interested in taking a look. Thank you again, this framework is absolutely top notch.

@EricWVGG
Copy link
Author

… if anyone in the future digs up this discussion, here's how I resolved the issue. Using renaming "atoms" to "widgets" as an example:

const load_components = (req) => req.keys().forEach((key) => {
  const componentName = key.replace(/^.+\/([^/]+)\/index\.js/, '$1')
  module.exports[componentName] = req(key).default
})

load_components( require.context('.', true, /\.\/widgets\/[^/]+\/index\.js$/) )
load_components( require.context('.', true, /\.\/_molecules\/[^/]+\/index\.js$/) )
load_components( require.context('.', true, /\.\/_organisms\/[^/]+\/index\.js$/) )
load_components( require.context('.', true, /\.\/pages\/[^/]+\/index\.js$/) )
load_components( require.context('.', true, /\.\/templates\/[^/]+\/index\.js$/) )
load_components( require.context('.', true, /\.\/themes\/[^/]+\/index\.js$/) )

Clunky, but this isn't as straightforward as dynamically running regexes with variables, as require_context() requires a statically defined regex, I'm sure as some sort of safety mechanism.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants