|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 |
| -var clone = require('clone'); |
| 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 | +} |
4 | 41 |
|
5 | 42 |
|
6 | 43 | // -----------------------------------------------------
|
@@ -162,8 +199,11 @@ queue.redo = function redo (gd) {
|
162 | 199 | queue.plotDo = function (gd, func, args) {
|
163 | 200 | gd.autoplay = true;
|
164 | 201 |
|
165 |
| - // call the supplied function with a cloned args |
166 |
| - func.apply(null, clone(args)); |
| 202 | + // this *won't* copy gd and it preserves `undefined` properties! |
| 203 | + args = copyArgArray(gd, args); |
| 204 | + |
| 205 | + // call the supplied function |
| 206 | + func.apply(null, args); |
167 | 207 | };
|
168 | 208 |
|
169 | 209 | module.exports = queue;
|
0 commit comments