Skip to content

Commit

Permalink
Use the context to pass the last value in the suffle generator
Browse files Browse the repository at this point in the history
  • Loading branch information
sunesimonsen committed Nov 29, 2018
1 parent 06c6592 commit 00e7801
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/ShuffleGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ class ShuffleGenerator extends Generator {
}

shrink(items, context) {
const shrinkable = (this.lastValue || []).some(g => g && g.shrink);
const lastValue = context.childContext(this).get("lastValue");
const shrinkable = (lastValue || []).some(g => g && g.shrink);

if (shrinkable) {
return new ShuffleGenerator(
this.lastValue.map(
lastValue.map(
(g, i) => (g && g.shrink ? g.shrink(items[i], context) : items[i])
)
);
Expand All @@ -37,9 +38,11 @@ class ShuffleGenerator extends Generator {
generate(chance, context) {
const { items } = this.options;

this.lastValue = chance.shuffle(items);
const value = chance.shuffle(items);

return this.lastValue.map(
context.childContext(this).set("lastValue", value);

return value.map(
item => (item && item.isGenerator ? item.generate(chance, context) : item)
);
}
Expand Down

0 comments on commit 00e7801

Please sign in to comment.