Skip to content

Commit 9f966b1

Browse files
committed
replace copyArgArray in queue.js with clone
1 parent 600b7fb commit 9f966b1

File tree

1 file changed

+3
-43
lines changed
  • shelly/plotlyjs/static/plotlyjs/src

1 file changed

+3
-43
lines changed

shelly/plotlyjs/static/plotlyjs/src/queue.js

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,6 @@
11
'use strict';
22

3-
/**
4-
* Copy arg array *without* removing `undefined` values from objects.
5-
*
6-
* `$.extend(true, *, *)` ignores `undefined` object properties, which we
7-
* depend on in relayout and restyle. This function exists *purely* to
8-
* conserve these undefined properties.
9-
*
10-
* Note, it doesn't bother with undefined properties inside an object in
11-
* an array. We don't have a use-case for this, so it doesn't matter.
12-
*
13-
* @param gd
14-
* @param args
15-
* @returns {Array}
16-
*/
17-
function copyArgArray (gd, args) {
18-
var copy = [],
19-
i,
20-
arg,
21-
ai;
22-
for (i = 0; i < args.length; i++) {
23-
arg = args[i];
24-
if (arg === gd) {
25-
copy[i] = arg;
26-
} else if (typeof arg === 'object') {
27-
if (Array.isArray(arg)) {
28-
copy[i] = $.extend(true, [], arg);
29-
} else {
30-
copy[i] = {};
31-
32-
// this is the important line! `undefined` things are kept!
33-
for(ai in arg) copy[i][ai] = arg[ai];
34-
}
35-
} else {
36-
copy[i] = arg;
37-
}
38-
}
39-
return copy;
40-
}
3+
var clone = require('clone');
414

425

436
// -----------------------------------------------------
@@ -197,11 +160,8 @@ queue.redo = function redo (gd) {
197160
queue.plotDo = function (gd, func, args) {
198161
gd.autoplay = true;
199162

200-
// this *won't* copy gd and it preserves `undefined` properties!
201-
args = copyArgArray(gd, args);
202-
203-
// call the supplied function
204-
func.apply(null, args);
163+
// call the supplied function with a cloned args
164+
func.apply(null, clone(args));
205165
};
206166

207167
module.exports = queue;

0 commit comments

Comments
 (0)