Skip to content

Commit 1b11620

Browse files
committed
Try to make CC happy
1 parent 7acebeb commit 1b11620

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

src/elements/element.line.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import {_computeSegments, _boundSegments} from '../helpers/helpers.segment';
44
import {_steppedLineTo, _bezierCurveTo} from '../helpers/helpers.canvas';
55
import {_updateBezierControlPoints} from '../helpers/helpers.curve';
66

7-
const usePath2D = typeof Path2D === 'function';
8-
97
/**
108
* @typedef { import("./element.point").default } PointElement
119
*/
@@ -200,6 +198,27 @@ function _getInterpolationMethod(options) {
200198
return _pointInLine;
201199
}
202200

201+
function strokePathWithCache(ctx, line, start, count) {
202+
let path = line._path;
203+
if (!path) {
204+
path = line._path = new Path2D();
205+
if (line.path(path, start, count)) {
206+
path.closePath();
207+
}
208+
}
209+
ctx.stroke(path);
210+
}
211+
function strokePathDirect(ctx, line, start, count) {
212+
ctx.beginPath();
213+
if (line.path(ctx, start, count)) {
214+
ctx.closePath();
215+
}
216+
ctx.stroke();
217+
}
218+
219+
const usePath2D = typeof Path2D === 'function';
220+
const strokePath = usePath2D ? strokePathWithCache : strokePathDirect;
221+
203222
export default class LineElement extends Element {
204223

205224
constructor(cfg) {
@@ -365,22 +384,7 @@ export default class LineElement extends Element {
365384

366385
setStyle(ctx, options);
367386

368-
if (usePath2D) {
369-
let path = me._path;
370-
if (!path) {
371-
path = me._path = new Path2D();
372-
if (me.path(path, start, count)) {
373-
path.closePath();
374-
}
375-
}
376-
ctx.stroke(path);
377-
} else {
378-
ctx.beginPath();
379-
if (me.path(ctx, start, count)) {
380-
ctx.closePath();
381-
}
382-
ctx.stroke();
383-
}
387+
strokePath(ctx, me, start, count);
384388

385389
ctx.restore();
386390

0 commit comments

Comments
 (0)