Skip to content

Commit

Permalink
Extract returnCompose method (#1178)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Feb 24, 2020
1 parent 0672d99 commit d971c03
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -790,11 +790,13 @@ class Generator extends EventEmitter {
options = {};
}

const returnCompose = ret => (returnNewGenerator ? ret : this);

let instantiatedGenerator;

if (Array.isArray(generator)) {
const generators = generator.map(gen => this.composeWith(gen, options));
return returnNewGenerator ? generators : this;
return returnCompose(generators);
}

const instantiate = (Generator, path) => {
Expand Down Expand Up @@ -877,7 +879,7 @@ class Generator extends EventEmitter {
}

if (!instantiatedGenerator) {
return returnNewGenerator ? instantiatedGenerator : this;
return returnCompose(instantiatedGenerator);
}

if (this._running) {
Expand All @@ -886,7 +888,7 @@ class Generator extends EventEmitter {
this._composedWith.push(instantiatedGenerator);
}

return returnNewGenerator ? instantiatedGenerator : this;
return returnCompose(instantiatedGenerator);
}

/**
Expand Down

0 comments on commit d971c03

Please sign in to comment.