Skip to content

Commit ff21077

Browse files
authored
Merge pull request #1347 from OpenGeoscience/minor-refactor
refactor: Make some code simpler
2 parents af985cb + ce38d21 commit ff21077

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

src/annotation/lineAnnotation.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ var lineAnnotation = function (args) {
4242
line: function (d) {
4343
/* Return an array that has the same number of items as we have
4444
* vertices. */
45-
return Array.apply(null, Array(m_this.options('vertices').length)).map(
46-
function () { return d; });
45+
return Array(m_this.options('vertices').length).fill(d);
4746
},
4847
position: function (d, i) {
4948
return m_this.options('vertices')[i];
@@ -53,8 +52,7 @@ var lineAnnotation = function (args) {
5352
line: function (d) {
5453
/* Return an array that has the same number of items as we have
5554
* vertices. */
56-
return Array.apply(null, Array(m_this.options('vertices').length)).map(
57-
function () { return d; });
55+
return Array(m_this.options('vertices').length).fill(d);
5856
},
5957
position: function (d, i) {
6058
return m_this.options('vertices')[i];

src/annotation/polygonAnnotation.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ var polygonAnnotation = function (args) {
4343
return new polygonAnnotation(args);
4444
}
4545

46-
args = util.deepMerge({}, this.constructor.defaults, {
46+
var m_this = this;
47+
48+
args = util.deepMerge({
4749
style: {
4850
polygon: function (d) { return d.polygon; }
4951
},
@@ -52,26 +54,24 @@ var polygonAnnotation = function (args) {
5254
const coord = m_this._coordinates();
5355
/* Return an array that has the same number of items as we have
5456
* vertices. */
55-
return Array.apply(null, Array((coord.outer || coord).length)).map(
56-
function () { return d; });
57+
return Array((coord.outer || coord).length).fill(d);
5758
},
5859
position: function (d, i) {
5960
if (d.x !== undefined) {
60-
return d.x;
61+
return d;
6162
}
6263
return m_this.options('vertices')[i];
6364
}
6465
},
6566
cursorStyle: {
6667
position: util.identityFunction
6768
}
68-
}, args);
69+
}, this.constructor.defaults, args);
6970
args.vertices = args.vertices || args.coordinates || [];
7071
delete args.coordinates;
7172
annotation.call(this, 'polygon', args);
7273

73-
var m_this = this,
74-
s_actions = this.actions,
74+
var s_actions = this.actions,
7575
s_state = this.state;
7676

7777
/**

src/util/common.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,15 +1011,15 @@ var util = {
10111011
}
10121012
const copy = source[key];
10131013
if (copy && typeof copy === 'object' && (copy.constructor === Object || Array.isArray(copy))) {
1014-
let src = target[key];
1014+
let value = target[key];
10151015
if (!Array.isArray(copy)) {
1016-
if (typeof src !== 'object' || Array.isArray(src)) {
1017-
src = {};
1016+
if (typeof value !== 'object' || Array.isArray(value)) {
1017+
value = {};
10181018
}
1019-
} else if (!Array.isArray(src)) {
1020-
src = [];
1019+
} else if (!Array.isArray(value)) {
1020+
value = [];
10211021
}
1022-
target[key] = util.deepMerge(src, copy);
1022+
target[key] = util.deepMerge(value, copy);
10231023
} else if (copy !== undefined) {
10241024
target[key] = copy;
10251025
}

0 commit comments

Comments
 (0)