Skip to content

Commit

Permalink
Merge pull request #1227 from FormidableLabs/bug/parent-events-use-in…
Browse files Browse the repository at this point in the history
…correct-key

alter reduceChildren to fix parent events regression
  • Loading branch information
boygirl authored Jan 9, 2019
2 parents 5ebe716 + 5db0c8f commit 8955aef
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion demo/components/events-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class App extends React.Component {
childName: ["area-3", "area-4"],
target: "data",
mutation: (props) => {
const fill = props.style.fill;
const fill = props.style && props.style.fill;
return fill === "gold" ? null : { style: { fill: "gold" } };
}
}
Expand Down
4 changes: 1 addition & 3 deletions packages/victory-core/src/victory-util/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,7 @@ function reduceChildren(
memo = combine(memo, nestedResults);
} else {
const result = iteratee(child, childName, parent);
if (Array.isArray(result)) {
memo = result.reduce(combine, memo);
} else if (result) {
if (result) {
memo = combine(memo, result);
}
}
Expand Down
13 changes: 8 additions & 5 deletions packages/victory-core/src/victory-util/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,14 @@ export default {
};

const initialMemo = { x: [], y: [] };
const combine = (memo, datum) => ({
x: datum.x !== undefined ? memo.x.concat(datum.x) : memo.x,
y: datum.y !== undefined ? memo.y.concat(datum.y) : memo.y
});

const combine = (memo, datum) => {
const x = Array.isArray(datum) ? datum.map((d) => d.x).filter(Boolean) : datum.x;
const y = Array.isArray(datum) ? datum.map((d) => d.y).filter(Boolean) : datum.y;
return {
x: x !== undefined ? memo.x.concat(x) : memo.x,
y: y !== undefined ? memo.y.concat(y) : memo.y
};
};
return Helpers.reduceChildren(childComponents.slice(0), iteratee, {}, initialMemo, combine);
},

Expand Down

0 comments on commit 8955aef

Please sign in to comment.