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

Code before:
        if (store.getItem(testKey) !== storeTest) {
            throw new Error('nope');
        }
        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;

Review comment (refactor):
Here you can simplify the top level check to:
```suggestion
    if (element.persistenceTransforms) {
```
any truth-y value will pass the test (https://dorey.github.io/JavaScript-Equality-Table/)

Code after:
        if (store.getItem(testKey) !== storeTest) {
            throw new Error('nope');
        }
        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');