<commit_before>import deleteValueForProperty from './deleteValueForProperty';
import setValueForProperty from './setValueForProperty';
import setValueForStyles from './setValueForStyles';
import eventManager from '../events/eventManager';
import events from '../events/shared/events';

/**
 * Detecting differences in property values and updating the DOM as necessary.
 * This function is probably the single most critical path for performance optimization.
 *
 * @param {DOMElement} node
 * @param {string} propKey
 * @param {object} lastProps
 * @param {object} nextProps
 */
function updateDOMProperties(element, propKey, lastProps, nextProps) {

    if (propKey === 'style') {

        let styleUpdates;
        let styleName;

        if (lastProps != null) {

            if (nextProps == null) {
                deleteValueForProperty(element, propKey);
            } else {

                // Unset styles on `lastProp` but not on `nextProp`.
                for (styleName in lastProps) {
                    if (lastProps[styleName] && (!nextProps || !nextProps[styleName])) {
                        styleUpdates = styleUpdates || {};
                        styleUpdates[styleName] = '';
                    }
                }
                // Update styles that changed since `lastProps`.
                for (styleName in nextProps) {
                    if (nextProps[styleName] && lastProps[styleName] !== nextProps[styleName]) {
                        styleUpdates = styleUpdates || {};
                        styleUpdates[styleName] = nextProps[styleName];
                    }
                }
            }
        } else if (nextProps != null) {
            styleUpdates = nextProps;
        }

        if (styleUpdates) {
            setValueForStyles(element, styleUpdates);
        }

    } else {

        if (events[propKey] != null) {
			// TODO!! Is this working as it should? Add tests!!
            if (nextProps != null) {
                eventManager.addListener(element, propKey, nextProps);
            } else {
                eventManager.removeListener(element, propKey);
            }
        } else {
			// TODO!! Should we no something here if lastProps or nextProps are null ???
            setValueForProperty(element, propKey, nextProps);
        }
    }
}

export default updateDOMProperties;<commit_msg>refactoring<commit_after>import deleteValueForProperty from './deleteValueForProperty';
import setValueForProperty from './setValueForProperty';
import setValueForStyles from './setValueForStyles';
import eventManager from '../events/eventManager';
import events from '../events/shared/events';

/**
 * Detecting differences in property values and updating the DOM as necessary.
 * This function is probably the single most critical path for performance optimization.
 *
 * @param {DOMElement} node
 * @param {string} propKey
 * @param {object} lastProps
 * @param {object} nextProps
 */
function updateDOMProperties(element, propKey, lastProps, nextProps) {

    if (propKey === 'style') {

        let styleUpdates;
        let styleName;

        if (lastProps != null) {

            if (nextProps == null) {
                deleteValueForProperty(element, propKey);
            } else {

                // Unset styles on `lastProp` but not on `nextProp`.
                for (styleName in lastProps) {
                    if (lastProps[styleName] && (!nextProps || !nextProps[styleName])) {
                        styleUpdates = styleUpdates || {};
                        styleUpdates[styleName] = '';
                    }
                }
                // Update styles that changed since `lastProps`.
                for (styleName in nextProps) {
                    if (nextProps[styleName] && lastProps[styleName] !== nextProps[styleName]) {
                        styleUpdates = styleUpdates || {};
                        styleUpdates[styleName] = nextProps[styleName];
                    }
                }
            }
        } else if (nextProps != null) {
            styleUpdates = nextProps;
        }

        if (styleUpdates) {
            setValueForStyles(element, styleUpdates);
        }

    } else {

        // Check if there was a listener 
        if (events[propKey] != null) {

            // TODO!! Is this working as it should? Add tests!!
            if (lastProps != null) {

                if (nextProps == null) {
                    eventManager.removeListener(element, propKey);
                } else {
                    if (nextProps && lastProps !== nextProps) {
                        eventManager.addListener(element, propKey, nextProps);
                    }
                }
            } else if (nextProps != null) {
                eventManager.addListener(element, propKey, nextProps);
            }
        } else {
            // TODO!! Should we no something here if lastProps or nextProps are null ???
            setValueForProperty(element, propKey, nextProps);
        }
    }
}

export default updateDOMProperties;
{'fraction_non_alphanumeric': 0.09964342313787639, 'fraction_numerical': 0.0, 'mean_word_length': 1.8238255033557047, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6595351', 'n_tokens_mistral': 1269, 'n_tokens_neox': 1212, 'n_words': 347}