Skip to content

Immediately invoked functions are not a good™ API #413

@ChristianUlbrich

Description

@ChristianUlbrich

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions