Skip to content

Commit 9b9521b

Browse files
committed
perf: Stop using jquery extend
Pure javascript is faster
1 parent 1fd3450 commit 9b9521b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+197
-193
lines changed

src/annotation/annotation.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
var $ = require('jquery');
21
var geo_event = require('../event');
32
var geo_action = require('../action');
43
var transform = require('../transform');
@@ -101,7 +100,7 @@ var annotation = function (type, args) {
101100
}
102101

103102
var m_this = this,
104-
m_options = $.extend(true, {}, this.constructor.defaults, args || {}),
103+
m_options = util.deepMerge({}, this.constructor.defaults, args || {}),
105104
m_id = m_options.annotationId;
106105
delete m_options.annotationId;
107106
if (m_id === undefined || (m_options.layer && m_options.layer.annotationById(m_id))) {
@@ -526,14 +525,14 @@ var annotation = function (type, args) {
526525
var coordinatesSet;
527526
if (arg2 === undefined) {
528527
coordinatesSet = arg1[m_this._coordinateOption] !== undefined;
529-
m_options = $.extend(true, m_options, arg1);
528+
m_options = util.deepMerge(m_options, arg1);
530529
/* For style objects, re-extend them without recursion. This allows
531530
* setting colors without an opacity field, for instance. */
532531
['style', 'createStyle', 'editStyle', 'editHandleStyle', 'labelStyle',
533532
'highlightStyle', 'cursorStyle'
534533
].forEach(function (key) {
535534
if (arg1[key] !== undefined) {
536-
$.extend(m_options[key], arg1[key]);
535+
Object.assign(m_options[key], arg1[key]);
537536
}
538537
});
539538
} else {
@@ -596,7 +595,7 @@ var annotation = function (type, args) {
596595
m_options[styleType] = {};
597596
}
598597
if (arg2 === undefined) {
599-
m_options[styleType] = $.extend(true, m_options[styleType], arg1);
598+
m_options[styleType] = util.deepMerge(m_options[styleType], arg1);
600599
} else {
601600
m_options[styleType][arg1] = arg2;
602601
}
@@ -659,15 +658,15 @@ var annotation = function (type, args) {
659658
/* for some states, fall back to the general style if they don't specify a
660659
* value explicitly. */
661660
if (state === annotationState.edit || state === annotationState.highlight) {
662-
return $.extend({}, m_options.style, m_options[state + 'Style']);
661+
return Object.assign({}, m_options.style, m_options[state + 'Style']);
663662
}
664663
if (state === annotationState.create) {
665-
return $.extend({}, m_options.style, m_options.editStyle,
666-
m_options[state + 'Style']);
664+
return Object.assign({}, m_options.style, m_options.editStyle,
665+
m_options[state + 'Style']);
667666
}
668667
if (state === annotationState.cursor) {
669-
return $.extend({}, m_options.style, m_options.editStyle,
670-
m_options.createStyle, m_options[state + 'Style']);
668+
return Object.assign({}, m_options.style, m_options.editStyle,
669+
m_options.createStyle, m_options[state + 'Style']);
671670
}
672671
return m_options[state + 'Style'] || m_options.style || {};
673672
};
@@ -925,15 +924,15 @@ var annotation = function (type, args) {
925924
*/
926925
this._addEditHandles = function (features, vertices, opts, isOpen) {
927926
var editPoints,
928-
style = $.extend({}, defaultEditHandleStyle, m_this.editHandleStyle()),
927+
style = Object.assign({}, defaultEditHandleStyle, m_this.editHandleStyle()),
929928
handles = util.ensureFunction(style.handles)() || {},
930929
selected = (
931930
m_this._editHandle && m_this._editHandle.handle &&
932931
m_this._editHandle.handle.selected ?
933932
m_this._editHandle.handle : undefined);
934933
/* opts specify which handles are allowed. They must be allowed by the
935934
* original opts object and by the editHandleStyle.handle object. */
936-
opts = $.extend({}, opts);
935+
opts = Object.assign({}, opts);
937936
Object.keys(handles).forEach(function (key) {
938937
if (handles[key] === false) {
939938
opts[key] = false;
@@ -947,27 +946,27 @@ var annotation = function (type, args) {
947946
vertexList.forEach((vert, vidx) => {
948947
vert.forEach(function (pt, idx) {
949948
if (opts.vertex !== false) {
950-
editPoints.push($.extend({}, pt, {type: 'vertex', index: idx, vindex: vidx, style: style, editHandle: true}));
949+
editPoints.push(Object.assign({}, pt, {type: 'vertex', index: idx, vindex: vidx, style: style, editHandle: true}));
951950
}
952951
if (opts.edge !== false && idx !== vert.length - 1 && (pt.x !== vert[idx + 1].x || pt.y !== vert[idx + 1].y)) {
953-
editPoints.push($.extend({
952+
editPoints.push(Object.assign({
954953
x: (pt.x + vert[idx + 1].x) / 2,
955954
y: (pt.y + vert[idx + 1].y) / 2
956955
}, {type: 'edge', index: idx, vindex: vidx, style: style, editHandle: true}));
957956
}
958957
if (opts.edge !== false && !isOpen && idx === vert.length - 1 && (pt.x !== vert[0].x || pt.y !== vert[0].y)) {
959-
editPoints.push($.extend({
958+
editPoints.push(Object.assign({
960959
x: (pt.x + vert[0].x) / 2,
961960
y: (pt.y + vert[0].y) / 2
962961
}, {type: 'edge', index: idx, vindex: vidx, style: style, editHandle: true}));
963962
}
964963
});
965964
});
966965
if (opts.center !== false) {
967-
editPoints.push($.extend({}, util.centerFromPerimeter(m_this._coordinates()), {type: 'center', style: style, editHandle: true}));
966+
editPoints.push(Object.assign({}, util.centerFromPerimeter(m_this._coordinates()), {type: 'center', style: style, editHandle: true}));
968967
}
969968
if (opts.rotate !== false) {
970-
editPoints.push($.extend(m_this._rotateHandlePosition(
969+
editPoints.push(Object.assign(m_this._rotateHandlePosition(
971970
style.rotateHandleOffset,
972971
style.rotateHandleRotation + (selected && selected.type === 'rotate' ? m_this._editHandle.amountRotated : 0)
973972
), {type: 'rotate', style: style, editHandle: true}));
@@ -976,7 +975,7 @@ var annotation = function (type, args) {
976975
}
977976
}
978977
if (opts.resize !== false) {
979-
editPoints.push($.extend(m_this._rotateHandlePosition(
978+
editPoints.push(Object.assign(m_this._rotateHandlePosition(
980979
style.resizeHandleOffset,
981980
style.resizeHandleRotation
982981
), {type: 'resize', style: style, editHandle: true}));

src/annotation/circleAnnotation.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const $ = require('jquery');
21
const inherit = require('../inherit');
32
const registerAnnotation = require('../registry').registerAnnotation;
43
const markerFeature = require('../markerFeature');
4+
const util = require('../util');
55

66
const ellipseAnnotation = require('./ellipseAnnotation');
77

@@ -22,15 +22,15 @@ var circleAnnotation = function (args, annotationName) {
2222
if (!(this instanceof circleAnnotation)) {
2323
return new circleAnnotation(args, annotationName);
2424
}
25-
args = $.extend(true, {}, this.constructor.defaults, args, {constraint: 1});
25+
args = util.deepMerge({}, this.constructor.defaults, args, {constraint: 1});
2626
ellipseAnnotation.call(this, args, annotationName || 'circle');
2727
};
2828
inherit(circleAnnotation, ellipseAnnotation);
2929

3030
/**
3131
* This object contains the default options to initialize the class.
3232
*/
33-
circleAnnotation.defaults = $.extend({}, ellipseAnnotation.defaults, {
33+
circleAnnotation.defaults = Object.assign({}, ellipseAnnotation.defaults, {
3434
});
3535

3636
var circleRequiredFeatures = {};

src/annotation/ellipseAnnotation.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const $ = require('jquery');
21
const inherit = require('../inherit');
32
const registerAnnotation = require('../registry').registerAnnotation;
43
const markerFeature = require('../markerFeature');
4+
const util = require('../util');
55

66
const annotationState = require('./annotation').state;
77
const rectangleAnnotation = require('./rectangleAnnotation');
@@ -23,7 +23,7 @@ var ellipseAnnotation = function (args, annotationName) {
2323
if (!(this instanceof ellipseAnnotation)) {
2424
return new ellipseAnnotation(args, annotationName);
2525
}
26-
args = $.extend(true, {}, this.constructor.defaults, args);
26+
args = util.deepMerge({}, this.constructor.defaults, args);
2727
rectangleAnnotation.call(this, args, annotationName || 'ellipse');
2828

2929
var m_this = this;
@@ -49,7 +49,7 @@ var ellipseAnnotation = function (args, annotationName) {
4949
marker: {
5050
x: (opt.corners[0].x + opt.corners[1].x + opt.corners[2].x + opt.corners[3].x) / 4,
5151
y: (opt.corners[0].y + opt.corners[1].y + opt.corners[2].y + opt.corners[3].y) / 4,
52-
style: $.extend(
52+
style: Object.assign(
5353
{}, style,
5454
{
5555
radius: radius,
@@ -120,7 +120,7 @@ inherit(ellipseAnnotation, rectangleAnnotation);
120120
/**
121121
* This object contains the default options to initialize the class.
122122
*/
123-
ellipseAnnotation.defaults = $.extend({}, rectangleAnnotation.defaults, {
123+
ellipseAnnotation.defaults = Object.assign({}, rectangleAnnotation.defaults, {
124124
});
125125

126126
var ellipseRequiredFeatures = {};

src/annotation/lineAnnotation.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const $ = require('jquery');
21
const inherit = require('../inherit');
32
const registerAnnotation = require('../registry').registerAnnotation;
43
const lineFeature = require('../lineFeature');
4+
const util = require('../util');
55

66
const annotation = require('./annotation').annotation;
77
const annotationState = require('./annotation').state;
@@ -37,7 +37,7 @@ var lineAnnotation = function (args) {
3737
if (!(this instanceof lineAnnotation)) {
3838
return new lineAnnotation(args);
3939
}
40-
args = $.extend(true, {}, this.constructor.defaults, {
40+
args = util.deepMerge({}, this.constructor.defaults, {
4141
style: {
4242
line: function (d) {
4343
/* Return an array that has the same number of items as we have
@@ -324,7 +324,7 @@ inherit(lineAnnotation, annotation);
324324
/**
325325
* This object contains the default options to initialize the class.
326326
*/
327-
lineAnnotation.defaults = $.extend({}, annotation.defaults, {
327+
lineAnnotation.defaults = Object.assign({}, annotation.defaults, {
328328
style: {
329329
strokeColor: {r: 0, g: 0, b: 0},
330330
strokeOpacity: 1,

src/annotation/pointAnnotation.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const $ = require('jquery');
21
const inherit = require('../inherit');
32
const util = require('../util');
43
const registerAnnotation = require('../registry').registerAnnotation;
@@ -40,7 +39,7 @@ var pointAnnotation = function (args) {
4039
return new pointAnnotation(args);
4140
}
4241

43-
args = $.extend(true, {}, this.constructor.defaults, args);
42+
args = util.deepMerge({}, this.constructor.defaults, args);
4443
args.position = args.position || (args.coordinates ? args.coordinates[0] : undefined);
4544
delete args.coordinates;
4645
annotation.call(this, 'point', args);
@@ -66,7 +65,7 @@ var pointAnnotation = function (args) {
6665
if (opt.style.scaled === true) {
6766
opt.style.scaled = m_this.layer().map().zoom();
6867
}
69-
style = $.extend({}, style, {
68+
style = Object.assign({}, style, {
7069
radius: function () {
7170
var radius = opt.style.radius,
7271
zoom = m_this.layer().map().zoom();
@@ -182,7 +181,7 @@ inherit(pointAnnotation, annotation);
182181
/**
183182
* This object contains the default options to initialize the class.
184183
*/
185-
pointAnnotation.defaults = $.extend({}, annotation.defaults, {
184+
pointAnnotation.defaults = Object.assign({}, annotation.defaults, {
186185
style: {
187186
fill: true,
188187
fillColor: {r: 0, g: 1, b: 0},

src/annotation/polygonAnnotation.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const $ = require('jquery');
21
const inherit = require('../inherit');
32
const registerAnnotation = require('../registry').registerAnnotation;
43
const lineFeature = require('../lineFeature');
@@ -44,7 +43,7 @@ var polygonAnnotation = function (args) {
4443
return new polygonAnnotation(args);
4544
}
4645

47-
args = $.extend(true, {}, this.constructor.defaults, {
46+
args = util.deepMerge({}, this.constructor.defaults, {
4847
style: {
4948
polygon: function (d) { return d.polygon; }
5049
},
@@ -354,7 +353,7 @@ inherit(polygonAnnotation, annotation);
354353
/**
355354
* This object contains the default options to initialize the class.
356355
*/
357-
polygonAnnotation.defaults = $.extend({}, annotation.defaults, {
356+
polygonAnnotation.defaults = Object.assign({}, annotation.defaults, {
358357
style: {
359358
fill: true,
360359
fillColor: {r: 0, g: 1, b: 0},

src/annotation/rectangleAnnotation.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const $ = require('jquery');
21
const inherit = require('../inherit');
32
const geo_event = require('../event');
43
const geo_action = require('../action');
54
const registerAnnotation = require('../registry').registerAnnotation;
65
const polygonFeature = require('../polygonFeature');
6+
const util = require('../util');
77

88
const annotation = require('./annotation').annotation;
99
const annotationState = require('./annotation').state;
@@ -48,7 +48,7 @@ var rectangleAnnotation = function (args, annotationName) {
4848
return new rectangleAnnotation(args, annotationName);
4949
}
5050

51-
args = $.extend(true, {}, this.constructor.defaults, args);
51+
args = util.deepMerge({}, this.constructor.defaults, args);
5252
args.corners = args.corners || args.coordinates || [];
5353
delete args.coordinates;
5454
annotation.call(this, annotationName || 'rectangle', args);
@@ -230,7 +230,7 @@ var rectangleAnnotation = function (args, annotationName) {
230230
c2 = map.gcsToDisplay(evt.mapgcs, null),
231231
c1 = {x: c2.x, y: c0.y},
232232
c3 = {x: c0.x, y: c2.y};
233-
corners[2] = $.extend({}, evt.mapgcs);
233+
corners[2] = Object.assign({}, evt.mapgcs);
234234
corners[1] = map.displayToGcs(c1, null);
235235
corners[3] = map.displayToGcs(c3, null);
236236
if (this._selectionConstraint) {
@@ -290,10 +290,10 @@ var rectangleAnnotation = function (args, annotationName) {
290290
return 'done';
291291
}
292292
if (evt.buttonsDown.left) {
293-
corners.push($.extend({}, evt.mapgcs));
294-
corners.push($.extend({}, evt.mapgcs));
295-
corners.push($.extend({}, evt.mapgcs));
296-
corners.push($.extend({}, evt.mapgcs));
293+
corners.push(Object.assign({}, evt.mapgcs));
294+
corners.push(Object.assign({}, evt.mapgcs));
295+
corners.push(Object.assign({}, evt.mapgcs));
296+
corners.push(Object.assign({}, evt.mapgcs));
297297
return true;
298298
}
299299
};
@@ -388,7 +388,7 @@ inherit(rectangleAnnotation, annotation);
388388
/**
389389
* This object contains the default options to initialize the class.
390390
*/
391-
rectangleAnnotation.defaults = $.extend({}, annotation.defaults, {
391+
rectangleAnnotation.defaults = Object.assign({}, annotation.defaults, {
392392
style: {
393393
fill: true,
394394
fillColor: {r: 0, g: 1, b: 0},

src/annotation/squareAnnotation.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const $ = require('jquery');
21
const inherit = require('../inherit');
32
const registerAnnotation = require('../registry').registerAnnotation;
43
const polygonFeature = require('../polygonFeature');
4+
const util = require('../util');
55

66
const rectangleAnnotation = require('./rectangleAnnotation');
77

@@ -22,15 +22,15 @@ var squareAnnotation = function (args, annotationName) {
2222
if (!(this instanceof squareAnnotation)) {
2323
return new squareAnnotation(args, annotationName);
2424
}
25-
args = $.extend(true, {}, this.constructor.defaults, args, {constraint: 1});
25+
args = util.deepMerge({}, this.constructor.defaults, args, {constraint: 1});
2626
rectangleAnnotation.call(this, args, annotationName || 'square');
2727
};
2828
inherit(squareAnnotation, rectangleAnnotation);
2929

3030
/**
3131
* This object contains the default options to initialize the class.
3232
*/
33-
squareAnnotation.defaults = $.extend({}, rectangleAnnotation.defaults, {
33+
squareAnnotation.defaults = Object.assign({}, rectangleAnnotation.defaults, {
3434
});
3535

3636
var squareRequiredFeatures = {};

src/annotationLayer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ var annotationLayer = function (arg) {
140140
};
141141
});
142142

143-
m_options = $.extend(true, {}, {
143+
m_options = util.deepMerge({}, {
144144
dblClickTime: 300,
145145
adjacentPointProximity: 5, // in pixels, 0 is exact
146146
// in pixels; set to continuousPointProximity to false to disable
@@ -445,7 +445,7 @@ var annotationLayer = function (arg) {
445445
return m_options[arg1];
446446
}
447447
if (arg2 === undefined) {
448-
m_options = $.extend(true, m_options, arg1);
448+
m_options = util.deepMerge(m_options, arg1);
449449
} else {
450450
m_options[arg1] = arg2;
451451
}
@@ -696,7 +696,7 @@ var annotationLayer = function (arg) {
696696
m_this.map().interactor().removeAction(
697697
undefined, undefined, geo_annotation.actionOwner);
698698
if (createAnnotation) {
699-
options = $.extend({}, options || {}, {
699+
options = Object.assign({}, options || {}, {
700700
state: geo_annotation.state.create,
701701
layer: m_this
702702
});
@@ -812,7 +812,7 @@ var annotationLayer = function (arg) {
812812
gcs === undefined ? map.ingcs() : gcs));
813813
$.each(dataList, function (data_idx, data) {
814814
var type = (data.properties || {}).annotationType || feature.featureType,
815-
options = $.extend({}, data.properties || {}),
815+
options = Object.assign({}, data.properties || {}),
816816
position, datagcs, i, existing;
817817
if ($.inArray(type, annotationList) < 0) {
818818
return;

0 commit comments

Comments
 (0)