|
1 | 1 | 'use strict';
|
2 | 2 |
|
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'); |
41 | 4 |
|
42 | 5 |
|
43 | 6 | // -----------------------------------------------------
|
@@ -197,11 +160,8 @@ queue.redo = function redo (gd) {
|
197 | 160 | queue.plotDo = function (gd, func, args) {
|
198 | 161 | gd.autoplay = true;
|
199 | 162 |
|
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)); |
205 | 165 | };
|
206 | 166 |
|
207 | 167 | module.exports = queue;
|
0 commit comments