Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lodash isEqual does not support functions #43

Open
TuningGuide opened this issue Sep 22, 2016 · 1 comment
Open

lodash isEqual does not support functions #43

TuningGuide opened this issue Sep 22, 2016 · 1 comment

Comments

@TuningGuide
Copy link

isEqual always says false if object contains functions. Furthermore tinymce adds properties to the single items in the style_formats option.

I had to change the componentWillReceiveProps and shouldComponentUpdate to:

  componentWillReceiveProps: function componentWillReceiveProps(nextProps) {
    if (!(0, _lodashLangIsEqual2['default'])(this.props.config, nextProps.config, function(c1, c2) {
        if(typeof c1 === 'function' && typeof c2 === 'function') {
            return c1.toString() === c2.toString();
        }
        if(c1.hasOwnProperty('items') && c2.hasOwnProperty('items')) {
            return c1.length == c2.length;
        }
        })) {
        this._init(nextProps.config, nextProps.content);
        console.log('TODO: this._init(nextProps.config, nextProps.content);');
    }
    if (!(0, _lodashLangIsEqual2['default'])(this.props.id, nextProps.id)) {
      this.id = nextProps.id;
    }
  },

  shouldComponentUpdate: function shouldComponentUpdate(nextProps) {
    return !(0, _lodashLangIsEqual2['default'])(this.props.content, nextProps.content) || !(0, _lodashLangIsEqual2['default'])(this.props.config, nextProps.config, function(c1, c2) {
            if(typeof c1 === 'function' && typeof c2 === 'function') {
                return c1.toString() === c2.toString();
            }
            if(c1.hasOwnProperty('items') && c2.hasOwnProperty('items')) {
                return c1.length == c2.length;
            }
        });
  },
@SimonChris
Copy link

SimonChris commented Jun 6, 2017

This can also be solved by declaring the functions outside the component, so that the same function object is reused every time.

See also #47 and #62.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants