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

Immediately invoked functions are not a good™ API #413

Open
ChristianUlbrich opened this issue Jun 23, 2020 · 0 comments
Open

Immediately invoked functions are not a good™ API #413

ChristianUlbrich opened this issue Jun 23, 2020 · 0 comments

Comments

@ChristianUlbrich
Copy link

The current (iter) API is built upon immediately invoked functions, i.e. lerna-script-magicz() returns a function that then can be called immediately.

What is the motivation for this pattern? I've never seen it in the wild (apart from IIFEs which serve a totally different use case), the closest you would get to is Reacts Hook Pattern and there they are almost exclusively never immediately invoke the function but assign to a variable and call it.

Looking at the code, I can see that it might simplify development but at the sacrifice of a bad API.

The iter stuff is sync, so it should either be possible to call it in a sync way iter.parallel(packages, packageFn) or use a fluent API such as iter.parallel(packages).with(packageFn).

Another possibility would be returning proxied arrays, which would also be feasible with lerna running on node.

Using the pattern

function parallel() {
  const retFun = taskFn => { /*..*/ };
  retFun.with = retFun;
  return retFun;
}

you could support this syntax without breaking the existing API too much at the benefit of a more natural API.

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

No branches or pull requests

1 participant