Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Stop using jquery extend #1342

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions src/annotation/annotation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var $ = require('jquery');
var geo_event = require('../event');
var geo_action = require('../action');
var transform = require('../transform');
Expand Down Expand Up @@ -101,7 +100,7 @@ var annotation = function (type, args) {
}

var m_this = this,
m_options = $.extend(true, {}, this.constructor.defaults, args || {}),
m_options = util.deepMerge({}, this.constructor.defaults, args || {}),
m_id = m_options.annotationId;
delete m_options.annotationId;
if (m_id === undefined || (m_options.layer && m_options.layer.annotationById(m_id))) {
Expand Down Expand Up @@ -526,14 +525,14 @@ var annotation = function (type, args) {
var coordinatesSet;
if (arg2 === undefined) {
coordinatesSet = arg1[m_this._coordinateOption] !== undefined;
m_options = $.extend(true, m_options, arg1);
m_options = util.deepMerge(m_options, arg1);
/* For style objects, re-extend them without recursion. This allows
* setting colors without an opacity field, for instance. */
['style', 'createStyle', 'editStyle', 'editHandleStyle', 'labelStyle',
'highlightStyle', 'cursorStyle'
].forEach(function (key) {
if (arg1[key] !== undefined) {
$.extend(m_options[key], arg1[key]);
Object.assign(m_options[key], arg1[key]);
}
});
} else {
Expand Down Expand Up @@ -596,7 +595,7 @@ var annotation = function (type, args) {
m_options[styleType] = {};
}
if (arg2 === undefined) {
m_options[styleType] = $.extend(true, m_options[styleType], arg1);
m_options[styleType] = util.deepMerge(m_options[styleType], arg1);
} else {
m_options[styleType][arg1] = arg2;
}
Expand Down Expand Up @@ -659,15 +658,15 @@ var annotation = function (type, args) {
/* for some states, fall back to the general style if they don't specify a
* value explicitly. */
if (state === annotationState.edit || state === annotationState.highlight) {
return $.extend({}, m_options.style, m_options[state + 'Style']);
return Object.assign({}, m_options.style, m_options[state + 'Style']);
}
if (state === annotationState.create) {
return $.extend({}, m_options.style, m_options.editStyle,
m_options[state + 'Style']);
return Object.assign({}, m_options.style, m_options.editStyle,
m_options[state + 'Style']);
}
if (state === annotationState.cursor) {
return $.extend({}, m_options.style, m_options.editStyle,
m_options.createStyle, m_options[state + 'Style']);
return Object.assign({}, m_options.style, m_options.editStyle,
m_options.createStyle, m_options[state + 'Style']);
}
return m_options[state + 'Style'] || m_options.style || {};
};
Expand Down Expand Up @@ -925,15 +924,15 @@ var annotation = function (type, args) {
*/
this._addEditHandles = function (features, vertices, opts, isOpen) {
var editPoints,
style = $.extend({}, defaultEditHandleStyle, m_this.editHandleStyle()),
style = Object.assign({}, defaultEditHandleStyle, m_this.editHandleStyle()),
handles = util.ensureFunction(style.handles)() || {},
selected = (
m_this._editHandle && m_this._editHandle.handle &&
m_this._editHandle.handle.selected ?
m_this._editHandle.handle : undefined);
/* opts specify which handles are allowed. They must be allowed by the
* original opts object and by the editHandleStyle.handle object. */
opts = $.extend({}, opts);
opts = Object.assign({}, opts);
Object.keys(handles).forEach(function (key) {
if (handles[key] === false) {
opts[key] = false;
Expand All @@ -947,27 +946,27 @@ var annotation = function (type, args) {
vertexList.forEach((vert, vidx) => {
vert.forEach(function (pt, idx) {
if (opts.vertex !== false) {
editPoints.push($.extend({}, pt, {type: 'vertex', index: idx, vindex: vidx, style: style, editHandle: true}));
editPoints.push(Object.assign({}, pt, {type: 'vertex', index: idx, vindex: vidx, style: style, editHandle: true}));
}
if (opts.edge !== false && idx !== vert.length - 1 && (pt.x !== vert[idx + 1].x || pt.y !== vert[idx + 1].y)) {
editPoints.push($.extend({
editPoints.push(Object.assign({
x: (pt.x + vert[idx + 1].x) / 2,
y: (pt.y + vert[idx + 1].y) / 2
}, {type: 'edge', index: idx, vindex: vidx, style: style, editHandle: true}));
}
if (opts.edge !== false && !isOpen && idx === vert.length - 1 && (pt.x !== vert[0].x || pt.y !== vert[0].y)) {
editPoints.push($.extend({
editPoints.push(Object.assign({
x: (pt.x + vert[0].x) / 2,
y: (pt.y + vert[0].y) / 2
}, {type: 'edge', index: idx, vindex: vidx, style: style, editHandle: true}));
}
});
});
if (opts.center !== false) {
editPoints.push($.extend({}, util.centerFromPerimeter(m_this._coordinates()), {type: 'center', style: style, editHandle: true}));
editPoints.push(Object.assign({}, util.centerFromPerimeter(m_this._coordinates()), {type: 'center', style: style, editHandle: true}));
}
if (opts.rotate !== false) {
editPoints.push($.extend(m_this._rotateHandlePosition(
editPoints.push(Object.assign(m_this._rotateHandlePosition(
style.rotateHandleOffset,
style.rotateHandleRotation + (selected && selected.type === 'rotate' ? m_this._editHandle.amountRotated : 0)
), {type: 'rotate', style: style, editHandle: true}));
Expand All @@ -976,7 +975,7 @@ var annotation = function (type, args) {
}
}
if (opts.resize !== false) {
editPoints.push($.extend(m_this._rotateHandlePosition(
editPoints.push(Object.assign(m_this._rotateHandlePosition(
style.resizeHandleOffset,
style.resizeHandleRotation
), {type: 'resize', style: style, editHandle: true}));
Expand Down
6 changes: 3 additions & 3 deletions src/annotation/circleAnnotation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const $ = require('jquery');
const inherit = require('../inherit');
const registerAnnotation = require('../registry').registerAnnotation;
const markerFeature = require('../markerFeature');
const util = require('../util');

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

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

/**
* This object contains the default options to initialize the class.
*/
circleAnnotation.defaults = $.extend({}, ellipseAnnotation.defaults, {
circleAnnotation.defaults = Object.assign({}, ellipseAnnotation.defaults, {
});

var circleRequiredFeatures = {};
Expand Down
8 changes: 4 additions & 4 deletions src/annotation/ellipseAnnotation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const $ = require('jquery');
const inherit = require('../inherit');
const registerAnnotation = require('../registry').registerAnnotation;
const markerFeature = require('../markerFeature');
const util = require('../util');

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

var m_this = this;
Expand All @@ -49,7 +49,7 @@ var ellipseAnnotation = function (args, annotationName) {
marker: {
x: (opt.corners[0].x + opt.corners[1].x + opt.corners[2].x + opt.corners[3].x) / 4,
y: (opt.corners[0].y + opt.corners[1].y + opt.corners[2].y + opt.corners[3].y) / 4,
style: $.extend(
style: Object.assign(
{}, style,
{
radius: radius,
Expand Down Expand Up @@ -120,7 +120,7 @@ inherit(ellipseAnnotation, rectangleAnnotation);
/**
* This object contains the default options to initialize the class.
*/
ellipseAnnotation.defaults = $.extend({}, rectangleAnnotation.defaults, {
ellipseAnnotation.defaults = Object.assign({}, rectangleAnnotation.defaults, {
});

var ellipseRequiredFeatures = {};
Expand Down
6 changes: 3 additions & 3 deletions src/annotation/lineAnnotation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const $ = require('jquery');
const inherit = require('../inherit');
const registerAnnotation = require('../registry').registerAnnotation;
const lineFeature = require('../lineFeature');
const util = require('../util');

const annotation = require('./annotation').annotation;
const annotationState = require('./annotation').state;
Expand Down Expand Up @@ -37,7 +37,7 @@ var lineAnnotation = function (args) {
if (!(this instanceof lineAnnotation)) {
return new lineAnnotation(args);
}
args = $.extend(true, {}, this.constructor.defaults, {
args = util.deepMerge({}, this.constructor.defaults, {
style: {
line: function (d) {
/* Return an array that has the same number of items as we have
Expand Down Expand Up @@ -324,7 +324,7 @@ inherit(lineAnnotation, annotation);
/**
* This object contains the default options to initialize the class.
*/
lineAnnotation.defaults = $.extend({}, annotation.defaults, {
lineAnnotation.defaults = Object.assign({}, annotation.defaults, {
style: {
strokeColor: {r: 0, g: 0, b: 0},
strokeOpacity: 1,
Expand Down
7 changes: 3 additions & 4 deletions src/annotation/pointAnnotation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const $ = require('jquery');
const inherit = require('../inherit');
const util = require('../util');
const registerAnnotation = require('../registry').registerAnnotation;
Expand Down Expand Up @@ -40,7 +39,7 @@ var pointAnnotation = function (args) {
return new pointAnnotation(args);
}

args = $.extend(true, {}, this.constructor.defaults, args);
args = util.deepMerge({}, this.constructor.defaults, args);
args.position = args.position || (args.coordinates ? args.coordinates[0] : undefined);
delete args.coordinates;
annotation.call(this, 'point', args);
Expand All @@ -66,7 +65,7 @@ var pointAnnotation = function (args) {
if (opt.style.scaled === true) {
opt.style.scaled = m_this.layer().map().zoom();
}
style = $.extend({}, style, {
style = Object.assign({}, style, {
radius: function () {
var radius = opt.style.radius,
zoom = m_this.layer().map().zoom();
Expand Down Expand Up @@ -182,7 +181,7 @@ inherit(pointAnnotation, annotation);
/**
* This object contains the default options to initialize the class.
*/
pointAnnotation.defaults = $.extend({}, annotation.defaults, {
pointAnnotation.defaults = Object.assign({}, annotation.defaults, {
style: {
fill: true,
fillColor: {r: 0, g: 1, b: 0},
Expand Down
5 changes: 2 additions & 3 deletions src/annotation/polygonAnnotation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const $ = require('jquery');
const inherit = require('../inherit');
const registerAnnotation = require('../registry').registerAnnotation;
const lineFeature = require('../lineFeature');
Expand Down Expand Up @@ -44,7 +43,7 @@ var polygonAnnotation = function (args) {
return new polygonAnnotation(args);
}

args = $.extend(true, {}, this.constructor.defaults, {
args = util.deepMerge({}, this.constructor.defaults, {
style: {
polygon: function (d) { return d.polygon; }
},
Expand Down Expand Up @@ -354,7 +353,7 @@ inherit(polygonAnnotation, annotation);
/**
* This object contains the default options to initialize the class.
*/
polygonAnnotation.defaults = $.extend({}, annotation.defaults, {
polygonAnnotation.defaults = Object.assign({}, annotation.defaults, {
style: {
fill: true,
fillColor: {r: 0, g: 1, b: 0},
Expand Down
16 changes: 8 additions & 8 deletions src/annotation/rectangleAnnotation.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const $ = require('jquery');
const inherit = require('../inherit');
const geo_event = require('../event');
const geo_action = require('../action');
const registerAnnotation = require('../registry').registerAnnotation;
const polygonFeature = require('../polygonFeature');
const util = require('../util');

const annotation = require('./annotation').annotation;
const annotationState = require('./annotation').state;
Expand Down Expand Up @@ -48,7 +48,7 @@ var rectangleAnnotation = function (args, annotationName) {
return new rectangleAnnotation(args, annotationName);
}

args = $.extend(true, {}, this.constructor.defaults, args);
args = util.deepMerge({}, this.constructor.defaults, args);
args.corners = args.corners || args.coordinates || [];
delete args.coordinates;
annotation.call(this, annotationName || 'rectangle', args);
Expand Down Expand Up @@ -230,7 +230,7 @@ var rectangleAnnotation = function (args, annotationName) {
c2 = map.gcsToDisplay(evt.mapgcs, null),
c1 = {x: c2.x, y: c0.y},
c3 = {x: c0.x, y: c2.y};
corners[2] = $.extend({}, evt.mapgcs);
corners[2] = Object.assign({}, evt.mapgcs);
corners[1] = map.displayToGcs(c1, null);
corners[3] = map.displayToGcs(c3, null);
if (this._selectionConstraint) {
Expand Down Expand Up @@ -290,10 +290,10 @@ var rectangleAnnotation = function (args, annotationName) {
return 'done';
}
if (evt.buttonsDown.left) {
corners.push($.extend({}, evt.mapgcs));
corners.push($.extend({}, evt.mapgcs));
corners.push($.extend({}, evt.mapgcs));
corners.push($.extend({}, evt.mapgcs));
corners.push(Object.assign({}, evt.mapgcs));
corners.push(Object.assign({}, evt.mapgcs));
corners.push(Object.assign({}, evt.mapgcs));
corners.push(Object.assign({}, evt.mapgcs));
return true;
}
};
Expand Down Expand Up @@ -388,7 +388,7 @@ inherit(rectangleAnnotation, annotation);
/**
* This object contains the default options to initialize the class.
*/
rectangleAnnotation.defaults = $.extend({}, annotation.defaults, {
rectangleAnnotation.defaults = Object.assign({}, annotation.defaults, {
style: {
fill: true,
fillColor: {r: 0, g: 1, b: 0},
Expand Down
6 changes: 3 additions & 3 deletions src/annotation/squareAnnotation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const $ = require('jquery');
const inherit = require('../inherit');
const registerAnnotation = require('../registry').registerAnnotation;
const polygonFeature = require('../polygonFeature');
const util = require('../util');

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

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

/**
* This object contains the default options to initialize the class.
*/
squareAnnotation.defaults = $.extend({}, rectangleAnnotation.defaults, {
squareAnnotation.defaults = Object.assign({}, rectangleAnnotation.defaults, {
});

var squareRequiredFeatures = {};
Expand Down
8 changes: 4 additions & 4 deletions src/annotationLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ var annotationLayer = function (arg) {
};
});

m_options = $.extend(true, {}, {
m_options = util.deepMerge({}, {
dblClickTime: 300,
adjacentPointProximity: 5, // in pixels, 0 is exact
// in pixels; set to continuousPointProximity to false to disable
Expand Down Expand Up @@ -445,7 +445,7 @@ var annotationLayer = function (arg) {
return m_options[arg1];
}
if (arg2 === undefined) {
m_options = $.extend(true, m_options, arg1);
m_options = util.deepMerge(m_options, arg1);
} else {
m_options[arg1] = arg2;
}
Expand Down Expand Up @@ -696,7 +696,7 @@ var annotationLayer = function (arg) {
m_this.map().interactor().removeAction(
undefined, undefined, geo_annotation.actionOwner);
if (createAnnotation) {
options = $.extend({}, options || {}, {
options = Object.assign({}, options || {}, {
state: geo_annotation.state.create,
layer: m_this
});
Expand Down Expand Up @@ -812,7 +812,7 @@ var annotationLayer = function (arg) {
gcs === undefined ? map.ingcs() : gcs));
$.each(dataList, function (data_idx, data) {
var type = (data.properties || {}).annotationType || feature.featureType,
options = $.extend({}, data.properties || {}),
options = Object.assign({}, data.properties || {}),
position, datagcs, i, existing;
if ($.inArray(type, annotationList) < 0) {
return;
Expand Down
Loading