From 7bb4a6f08fd3a2b3a7c07efc6724eb0187e87fcb Mon Sep 17 00:00:00 2001 From: Niklas von Hertzen Date: Tue, 12 Dec 2017 22:18:15 +0800 Subject: [PATCH] Fix compiled code using symbols --- src/Gradient.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Gradient.js b/src/Gradient.js index e4169a3..a5126ab 100644 --- a/src/Gradient.js +++ b/src/Gradient.js @@ -339,19 +339,21 @@ const findCorner = (bounds: Bounds, x: number, y: number, closest: boolean): Poi {x: bounds.width, y: bounds.height} ]; - let optimumDistance = closest ? Infinity : -Infinity; - let optimumCorner = null; - - for (let corner of corners) { - const d = distance(x - corner.x, y - corner.y); - if (closest ? d < optimumDistance : d > optimumDistance) { - optimumDistance = d; - optimumCorner = corner; - } - } - // $FlowFixMe - return optimumCorner; + return corners.reduce((stat, corner) => { + const d = distance(x - corner.x, y - corner.y); + if (closest ? d < stat.optimumDistance : d > stat.optimumDistance) { + return { + optimumCorner: corner, + optimumDistance: d + }; + } + + return stat; + }, { + optimumDistance: closest ? Infinity : -Infinity, + optimumCorner: null + }).optimumCorner; }; const calculateRadius = (