function changeOptionRecursive()

in src/store.js [110:168]


    function changeOptionRecursive(obj, pathParts, objKey, nodePath) {
        const itemStr = pathParts.shift();
        nodePath = (nodePath ? (nodePath + '.') : '') + itemStr;

        if (objKey === 'data' && (typeof obj !== 'object' || Array.isArray(obj))) {
            // Convert number to object
            obj = {
                value: obj
            };
        }

        // Clone a new object because the original one is freezed and cant be changed.
        obj = Object.assign({}, obj);
        if (!pathParts.length) {
            if (value === undefined) {
                delete obj[itemStr];
                return obj;
            }
            else {
                obj[itemStr] = value;
                return obj;
            }
        }

        const subtypeItems = itemStr.split('-');
        const key = subtypeItems[0];
        const subtype = subtypeItems[1];
        // TODO: If prop not exists and it should be an array.
        if (obj[key] == null) {
            const outlineNode = getOutlineNode(nodePath);
            obj[key] = makeDefaultOption(key) ||
                ((outlineNode && outlineNode.isArray) ? [] : {});
        }
        const prop = obj[key];
        if (Array.isArray(prop)) {
            if (key === 'series') { // Only set all on series.
                obj[key] = prop.map(function (childObj, idx) {
                    if (subtype && childObj.type !== subtype) {
                        return childObj;
                    }
                    return changeOptionRecursive(childObj, pathParts.slice(), key, nodePath);
                });
            }
            else {
                // Only change the first one.
                // TODO: Should be able to choose the index.
                obj[key] = prop.slice();
                obj[key][0] = changeOptionRecursive(obj[key][0] || {}, pathParts.slice(), key, nodePath);
            }
        }
        else {
            if (subtype && prop.type !== subtype) {
                obj[key] = prop;
            }
            obj[key] = changeOptionRecursive(prop, pathParts.slice(), key, nodePath);
        }

        return obj;
    }