<commit_before>import get         from 'lodash.get';
import isEqual     from 'lodash.isequal';
import {Component} from 'react';
import {PropTypes} from 'react';

import BaseForm from '../forms/BaseForm';
import joinName from '../../helpers/joinName';

export default class BaseField extends Component {
    static propTypes = {
        id: PropTypes.string,

        name:     PropTypes.string,
        disabled: PropTypes.bool,

        label:       PropTypes.oneOfType([PropTypes.bool, PropTypes.string, PropTypes.node]),
        placeholder: PropTypes.oneOfType([PropTypes.bool, PropTypes.string])
    };

    static contextTypes      = BaseForm.childContextTypes;
    static childContextTypes = BaseForm.childContextTypes;

    constructor () {
        super(...arguments);

        this.randomId = this.context.uniforms.randomId();

        this.getFieldProps = this.getFieldProps.bind(this);

        this.getChildContextName     = this.getChildContextName.bind(this);
        this.getChildContextError    = this.getChildContextError.bind(this);
        this.getChildContextModel    = this.getChildContextModel.bind(this);
        this.getChildContextState    = this.getChildContextState.bind(this);
        this.getChildContextSchema   = this.getChildContextSchema.bind(this);
        this.getChildContextOnChange = this.getChildContextOnChange.bind(this);
    }

    shouldComponentUpdate (nextProps, nextState, {uniforms: nextContext}) {
        const prevProps   = this.props;
        const prevContext = this.context.uniforms;

        if (!isEqual(prevProps.value, nextProps.value)) {
            return true;
        }

        const prevName = joinName(prevContext.name, prevProps.name);
        const nextName = joinName(nextContext.name, nextProps.name);

        if (prevName !== nextName) {
            return true;
        }

        if (nextName.indexOf('.') !== -1) {
            const prevParentValue = get(prevContext.model, prevName.replace(/(.+)\..+$/, '$1'));
            const nextParentValue = get(nextContext.model, nextName.replace(/(.+)\..+$/, '$1'));

            if (Array.isArray(nextParentValue) && !isEqual(prevParentValue, nextParentValue)) {
                return true;
            }
        }

        const prevValue = get(prevContext.model, prevName);
        const nextValue = get(nextContext.model, nextName);

        if (!isEqual(prevValue, nextValue)) {
            return true;
        }

        return false;
    }

    getChildContext () {
        return {
            uniforms: {<commit_msg>Improved performance of BaseField (#70).<commit_after>import get         from 'lodash.get';
import isEqual     from 'lodash.isequal';
import {Component} from 'react';
import {PropTypes} from 'react';

import BaseForm from '../forms/BaseForm';
import joinName from '../../helpers/joinName';

export default class BaseField extends Component {
    static propTypes = {
        id: PropTypes.string,

        name:     PropTypes.string,
        disabled: PropTypes.bool,

        label:       PropTypes.oneOfType([PropTypes.bool, PropTypes.string, PropTypes.node]),
        placeholder: PropTypes.oneOfType([PropTypes.bool, PropTypes.string])
    };

    static contextTypes      = BaseForm.childContextTypes;
    static childContextTypes = BaseForm.childContextTypes;

    constructor () {
        super(...arguments);

        this.randomId = this.context.uniforms.randomId();

        this.getFieldProps = this.getFieldProps.bind(this);

        this.getChildContextName     = this.getChildContextName.bind(this);
        this.getChildContextError    = this.getChildContextError.bind(this);
        this.getChildContextModel    = this.getChildContextModel.bind(this);
        this.getChildContextState    = this.getChildContextState.bind(this);
        this.getChildContextSchema   = this.getChildContextSchema.bind(this);
        this.getChildContextOnChange = this.getChildContextOnChange.bind(this);
    }

    shouldComponentUpdate (nextProps, nextState, {uniforms: nextContext}) {
        const prevProps   = this.props;
        const prevContext = this.context.uniforms;

        if (!isEqual(prevProps.value, nextProps.value)) {
            return true;
        }

        const prevName = joinName(prevContext.name, prevProps.name);
        const nextName = joinName(nextContext.name, nextProps.name);

        if (prevName !== nextName) {
            return true;
        }

        if (nextName.indexOf('.') !== -1) {
            const prevParentValue = get(prevContext.model, prevName.replace(/(.+)\..+$/, '$1'));
            const nextParentValue = get(nextContext.model, nextName.replace(/(.+)\..+$/, '$1'));

            if (Array.isArray(nextParentValue) && !isEqual(prevParentValue, nextParentValue)) {
                return true;
            }
        }

        const prevValue = get(prevContext.model, prevName);
        const nextValue = get(nextContext.model, nextName);

        if (!isEqual(prevValue, nextValue)) {
            return true;
        }

        if (prevContext.error !== nextContext.error) {
            const prevError = prevContext.error && prevContext.schema.getError(prevName, prevContext.error);
            const nextError = nextContext.error && nextContext.schema.getError(nextName, nextContext.error);

            if (!isEqual(prevError, nextError)) {
                return true;
            }
        }

        return false;
    }

    getChildContext () {
        return {
            uniforms: {
{'fraction_non_alphanumeric': 0.11691859406301221, 'fraction_numerical': 0.0014569295210344199, 'mean_word_length': 2.5409413281753706, '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': '2762962', 'n_tokens_mistral': 1517, 'n_tokens_neox': 1486, 'n_words': 292}