@@ -589,9 +589,25 @@ lib.objectFromPath = function(path, value) {
589589/**
590590 * Iterate through an object in-place, converting dotted properties to objects.
591591 *
592- * @example
593- * lib.expandObjectPaths({'nested.test.path': 'value'});
594- * // returns { nested: { test: {path: 'value'}}}
592+ * Examples:
593+ *
594+ * lib.expandObjectPaths({'nested.test.path': 'value'});
595+ * => { nested: { test: {path: 'value'}}}
596+ *
597+ * It also handles array notation, e.g.:
598+ *
599+ * lib.expandObjectPaths({'foo[1].bar': 'value'});
600+ * => { foo: [null, {bar: value}] }
601+ *
602+ * It handles merges the results when two properties are specified in parallel:
603+ *
604+ * lib.expandObjectPaths({'foo[1].bar': 10, 'foo[0].bar': 20});
605+ * => { foo: [{bar: 10}, {bar: 20}] }
606+ *
607+ * It does NOT, however, merge mulitple mutliply-nested arrays::
608+ *
609+ * lib.expandObjectPaths({'marker[1].range[1]': 5, 'marker[1].range[0]': 4})
610+ * => { marker: [null, {range: 4}] }
595611 */
596612
597613// Store this to avoid recompiling regex on *every* prop since this may happen many
@@ -624,10 +640,27 @@ lib.expandObjectPaths = function(data) {
624640 data [ prop ] = data [ prop ] || [ ] ;
625641
626642 if ( match [ 3 ] === '.' ) {
643+ // This is the case where theere are subsequent properties into which
644+ // we must recurse, e.g. transforms[0].value
627645 trailingPath = match [ 4 ] ;
628646 dest = data [ prop ] [ idx ] = data [ prop ] [ idx ] || { } ;
647+
648+ // NB: Extend deep no arrays prevents this from working on multiple
649+ // nested properties in the same object, e.g.
650+ //
651+ // {
652+ // foo[0].bar[1].range
653+ // foo[0].bar[0].range
654+ // }
655+ //
656+ // In this case, the extendDeepNoArrays will overwrite one array with
657+ // the other, so that both properties *will not* be present in the
658+ // result. Fixing this would require a more intelligent tracking
659+ // of changes and merging than extendDeepNoArrays currently accomplishes.
629660 lib . extendDeepNoArrays ( dest , lib . objectFromPath ( trailingPath , lib . expandObjectPaths ( datum ) ) ) ;
630661 } else {
662+ // This is the case where this property is the end of the line,
663+ // e.g. xaxis.range[0]
631664 data [ prop ] [ idx ] = lib . expandObjectPaths ( datum ) ;
632665 }
633666 } else {
0 commit comments