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

Handle recursivity ? #5

Open
Vincz opened this issue Apr 18, 2018 · 1 comment
Open

Handle recursivity ? #5

Vincz opened this issue Apr 18, 2018 · 1 comment

Comments

@Vincz
Copy link

Vincz commented Apr 18, 2018

Hi!
I think it would be great to handle recursivity.
Given the following structure:

index.js
a/a1.js
b/b1.js
b/b2/js
c/c1.js

We could then do something like this:

const { a: {a1}, b: { b2 } } = require("lib");

And it would avoid to have to create an index.js in each sub directory.

What do you think ? :)

@rjhilgefort
Copy link
Owner

Hello and thanks for the issue!

I haven't had a use case for that structure yet but I could see that being pretty useful if you were trying to really break up your code. I see your motivation to reduce the amount of boilerplate index.js files all over your lib sub folders, but I worry about the implications of making lib/index.js always require sub folders. Again, I don't know your real-world use case and you may be perfectly fine with doing the recursive requires with every file that wants something in lib. I think a more flexible solution being something like:

Have an index.js at the root of every sub folder that describes how to require it's sibling files. This would allow for greater control at any level, but require a bit more boilerplate. The biggest advantage I see is that you would be able to require at any level of your lib depending on the need of the calling file. For example you could just get the sub-package you want, without having to require alllll of lib (and making it do all the other requires), just to grab b2. It would allow for pretty much any usage that a caller might want.

const b2 = require('./lib/b/b2');
const { b2 } = require('./lib/b');
const { b: { b2 } } = require('./lib');

That's just my initial thoughts on implementing a "folder" feature (since this currently just ignores folders). I don't feel especially strong either way, so let me know what you think.

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