Skip to content

Commit

Permalink
🐛 Fixing a bug.
Browse files Browse the repository at this point in the history
Line constructor second argument is correctly treated as position definition if possible.
  • Loading branch information
Guillaume Martigny committed Dec 19, 2018
1 parent 600648c commit 9c33451
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
12 changes: 4 additions & 8 deletions modules/line/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@ export default class Line extends Component {
constructor (positionDefinition, points, options) {
super(positionDefinition, options);

let positions;
try {
// Try to treat it as one position definition
positions = [Position.from(points)];
}
catch (e) {
positions = points.map(point => Position.from(point));
}
// Try to treat it as one position definition
const positions = points.slice(0, 2).every(n => n === undefined || typeof n === "number") ?
[Position.from(points)] :
points.map(point => Position.from(point));

/**
* @type {Array<Position>}
Expand Down
7 changes: 2 additions & 5 deletions modules/line/line.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,8 @@ test("ishover", (t) => {
test("toJSON", (t) => {
const json = t.context.toJSON();

t.deepEqual(json.position, [100, 50]);
t.deepEqual(json.points, [
[150, 150],
[200, 200],
]);
t.deepEqual(json.position, t.context.position);
t.deepEqual(json.points, t.context.points);
t.is(json.constructor, "Line");
});

Expand Down

0 comments on commit 9c33451

Please sign in to comment.