Repository: plotly/dash
File: dash-renderer/src/persistence.js (JavaScript)

Code before:
        }
        store.removeItem(testKey);
        dispatch(err(`${backEnd} init set/get succeeded after clearing!`));
        return store;
    } catch (e) {
        dispatch(err(`${backEnd} init still failed, falling back to memory`));
        return fallbackStore;
    }
}

function getStore(type, dispatch) {
    if (!stores[type]) {
        stores[type] = tryGetWebStore(backEnds[type], dispatch);
    }
    return stores[type];
}

const noopTransform = {
    extract: propValue => propValue,
    apply: (storedValue, _propValue) => storedValue,
};

const getTransform = (element, propName, propPart) => {
    if (typeof element.persistenceTransforms !== 'undefined') {
        if (
            Object.getOwnPropertyNames(element.persistenceTransforms).includes(
                propName
            )
        ) {
            if (propPart) {
                return element.persistenceTransforms[propName][propPart];
            }
            return element.persistenceTransforms[propName];
        }
        return noopTransform;
    }
    return noopTransform;
};

const getValsKey = (id, persistedProp, persistence) =>
    `${stringifyId(id)}.${persistedProp}.${JSON.stringify(persistence)}`;

const getProps = layout => {
    const {props, type, namespace} = layout;
    if (!type || !namespace) {
        // not a real component - just need the props for recursion
        return {props};
    }
    const {id, persistence} = props;

    const element = Registry.resolve(layout);

Review comment (suggestion):
Old logic checks for just `propPart` for `persistenceTransforms`, but here we add logic to check if either `propName` or `propPart` is the persisted prop.

Code after:
        }
        store.removeItem(testKey);
        dispatch(err(`${backEnd} init set/get succeeded after clearing!`));
        return store;
    } catch (e) {
        dispatch(err(`${backEnd} init still failed, falling back to memory`));
        return fallbackStore;
    }
}

function getStore(type, dispatch) {
    if (!stores[type]) {
        stores[type] = tryGetWebStore(backEnds[type], dispatch);
    }
    return stores[type];
}

const noopTransform = {
    extract: propValue => propValue,
    apply: (storedValue, _propValue) => storedValue
};

const getTransform = (element, propName, propPart) => {
    if (
        element.persistenceTransforms &&
        element.persistenceTransforms[propName]
    ) {
        if (propPart) {
            return element.persistenceTransforms[propName][propPart];
        }
        return element.persistenceTransforms[propName];
    }
    return noopTransform;
};

const getValsKey = (id, persistedProp, persistence) =>
    `${stringifyId(id)}.${persistedProp}.${JSON.stringify(persistence)}`;

const getProps = layout => {
    const {props, type, namespace} = layout;
    if (!type || !namespace) {
        // not a real component - just need the props for recursion
        return {props};
    }
    const {id, persistence} = props;

    const element = Registry.resolve(layout);
    const getVal = prop => props[prop] || (element.defaultProps || {})[prop];
    const persisted_props = getVal('persisted_props');
    const persistence_type = getVal('persistence_type');
    const canPersist = id && persisted_props && persistence_type;