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

Make hasShouldComponentUpdate detect nested functions #99

Merged
merged 2 commits into from
May 8, 2015

Conversation

adamschoenemann
Copy link
Contributor

I haven't tested it thoroughly, but it works for me! :)

if (mixin.shouldComponentUpdate) {
return true;
}
if (mixin.mixins instanceof Array) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be changed to Array.isArray? instanceof checks are generally not too good in JS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, no problem

@mikaelbr
Copy link
Member

mikaelbr commented May 7, 2015

Is this something that React supports as well? Never seen nested objects as mixins in React before. Could you possibly do a test verifying this as well?

@adamschoenemann
Copy link
Contributor Author

Well, React certainly supports nested mixins. React does not attempt to set a default shouldComponentUpdate via a mixin operation, so this is not really an in issue.
As a user, I would expect the omniscient shouldComponentUpdate would only be supplied if I had not supplied one, through nested mixins or not - but maybe that's just me!

This example works fine with React:

var BaseHandler = {
    shouldComponentUpdate() {
        console.log('BaseHandler shouldComponentUpdate!');
        return true;
    }
};

var AppHandler = {
    mixins: [BaseHandler]
};

var FooHandler = React.createClass({
    mixins: [AppHandler],
    getInitialState() {
        return {foo: 1};
    },
    componentDidMount() {
        window.setTimeout(() => {
            this.setState({foo: this.state.foo + 1});
        }, 500);
    },
    render() {
        return DOM.div(null,
            this.state.foo,
            'FooHandler!'
        );
    }
});

Whereas with Omniscient, React will throw an error when attempting to set shouldComponentUpdate, as it is already defined by the nested mixin.

@mikaelbr
Copy link
Member

mikaelbr commented May 7, 2015

I see. This would fix that, so very good! 🍰

@adamschoenemann
Copy link
Contributor Author

Great! 👍

@mikaelbr mikaelbr merged commit a1e364e into omniscientjs:master May 8, 2015
mikaelbr added a commit that referenced this pull request May 8, 2015
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

Successfully merging this pull request may close these issues.

2 participants