<commit_before>import React, {Component, PropTypes} from 'react';
import {IntlProvider, injectIntl} from 'react-intl';
import NoOp from '../components/utils/NoOp';

export const decorateContainer = function(DecoratedComponent, options = {}) {
    const ConnectedDecoratedComponent = injectIntl(DecoratedComponent);    

    const EnvelopedContainer = class extends Component {
        static get propTypes() {
            return options.propTypes;
        }

        static get contextTypes() {
            return {
                policy: PropTypes.func,
                permissions: PropTypes.object,
                config: PropTypes.object
            };
        }

        createDispatch(props) {
            let {dispatch} = this.props;
            
            if (!dispatch) {
                dispatch = (action) => {
                    if (typeof action === 'function') {
                        action((action) => {
                            // Unwrap all the thunk layers
                            dispatch(action);
                        }, () => {
                            return props;
                        });
                    } else {
                        this.setState(action.payload || {});
                    }
                };
            }

            return dispatch;
        }

        calculateIntlProps() {
            const {messages} = this.props;
            const {locale = options.locale || 'en'} = this.props;

            const props = {locale};

            if (typeof messages !== 'undefined') {
                props.messages = messages;
            }
            
            return props;
        }

        createConfigProp() {
            return this.context ? (this.context.config || {}) : {};
        }

        createRBAProp() {
            return this.context ? ({
                policy: this.context.policy || NoOp,
                permissions: this.context.permissions || {}
            } || {}) : {};
        }

        mergeProps() {
            // TODO: Deep merge? Performance on render?
            const contextConfig = this.createConfigProp();
            const rba = this.createRBAProp();

            const propsConfig = this.props ? (this.props.config || {}) : {};
            const stateConfig = this.state ? (this.state.config || {}) : {};

            const config = {...options.config, ...contextConfig, ...propsConfig, ...stateConfig};

            const props = {
                ...this.props,
                ...this.state,
                config,
                rba
            };

            return props;
        }

        render() {
            const intlProps = this.calculateIntlProps();
            const props = this.mergeProps();
            const dispatch = this.createDispatch(props);

            return (  
                <IntlProvider {...intlProps}>
                    <ConnectedDecoratedComponent {...props} dispatch={dispatch} />
                </IntlProvider>
            );
        }
    };

    Object.defineProperty(EnvelopedContainer, 'name', {writable: true});
    EnvelopedContainer.name = `${DecoratedComponent.name}Container`;
    Object.defineProperty(EnvelopedContainer, 'name', {writable: false});
    EnvelopedContainer.Component = DecoratedComponent;

    return EnvelopedContainer;
};

export default function Container(options = {}) {
    // `options` is the class being decorated
    let result;

    if (typeof options !== 'function') {
        result = (DecoratedComponent) => decorateContainer(DecoratedComponent, options);
    } else {
        result = decorateContainer(options);
    }

    return result;
}

<commit_msg>Fix for Safari browser<commit_after>import React, {Component, PropTypes} from 'react';
import {IntlProvider, injectIntl} from 'react-intl';
import NoOp from '../components/utils/NoOp';

export const decorateContainer = function(DecoratedComponent, options = {}) {
    const ConnectedDecoratedComponent = injectIntl(DecoratedComponent);    

    const EnvelopedContainer = class extends Component {
        static get propTypes() {
            return options.propTypes;
        }

        static get contextTypes() {
            return {
                policy: PropTypes.func,
                permissions: PropTypes.object,
                config: PropTypes.object
            };
        }

        createDispatch(props) {
            let {dispatch} = this.props;
            
            if (!dispatch) {
                dispatch = (action) => {
                    if (typeof action === 'function') {
                        action((action) => {
                            // Unwrap all the thunk layers
                            dispatch(action);
                        }, () => {
                            return props;
                        });
                    } else {
                        this.setState(action.payload || {});
                    }
                };
            }

            return dispatch;
        }

        calculateIntlProps() {
            const {messages} = this.props;
            const {locale = options.locale || 'en'} = this.props;

            const props = {locale};

            if (typeof messages !== 'undefined') {
                props.messages = messages;
            }
            
            return props;
        }

        createConfigProp() {
            return this.context ? (this.context.config || {}) : {};
        }

        createRBAProp() {
            return this.context ? ({
                policy: this.context.policy || NoOp,
                permissions: this.context.permissions || {}
            } || {}) : {};
        }

        mergeProps() {
            // TODO: Deep merge? Performance on render?
            const contextConfig = this.createConfigProp();
            const rba = this.createRBAProp();

            const propsConfig = this.props ? (this.props.config || {}) : {};
            const stateConfig = this.state ? (this.state.config || {}) : {};

            const config = {...options.config, ...contextConfig, ...propsConfig, ...stateConfig};

            const props = {
                ...this.props,
                ...this.state,
                config,
                rba
            };

            return props;
        }

        render() {
            const intlProps = this.calculateIntlProps();
            const props = this.mergeProps();
            const dispatch = this.createDispatch(props);

            return (  
                <IntlProvider {...intlProps}>
                    <ConnectedDecoratedComponent {...props} dispatch={dispatch} />
                </IntlProvider>
            );
        }
    };

    // Object.defineProperty(EnvelopedContainer, 'name', {writable: true});
    // EnvelopedContainer.name = `${DecoratedComponent.name}Container`;
    // Object.defineProperty(EnvelopedContainer, 'name', {writable: false});
    EnvelopedContainer.Component = DecoratedComponent;

    return EnvelopedContainer;
};

export default function Container(options = {}) {
    // `options` is the class being decorated
    let result;

    if (typeof options !== 'function') {
        result = (DecoratedComponent) => decorateContainer(DecoratedComponent, options);
    } else {
        result = decorateContainer(options);
    }

    return result;
}


{'fraction_non_alphanumeric': 0.11417645452062278, 'fraction_numerical': 0.0, 'mean_word_length': 1.4648266576910132, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, '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': '4710507', 'n_tokens_mistral': 1794, 'n_tokens_neox': 1737, 'n_words': 385}