Skip to content

Apply component spec + mixins specs deterministically #1589

Closed

Description

@zpao

Right now we don't do this consistently, so you could have behavior that varies depending on where you put the mixins key in your class spec. That's not great.

Here's an example: http://jsfiddle.net/zpao/9sW7n/ (using master)

var Mixin = {
  componentDidMount: function() {
    console.log('Mixin');
  }
};

var CompA = React.createClass({
  mixins: [Mixin],
  componentDidMount: function() {
    console.log('CompA');
  },
  render: function() {
    return <span>A</span>;
  }
})

var CompB = React.createClass({
  componentDidMount: function() {
    console.log('CompB');
  },
  mixins: [Mixin],
  render: function() {
    return <span>B</span>;
  }
})

This outputs:

"Mixin"
"CompA"
"CompB"
"Mixin"

I think we should consistently behave like CompB (component, then mixin methods) but @yungsters disagrees. Any other opinions. @petehunt @sebmarkbage @jordwalke

Potentially interested @gaearon (once we figure out which way we go)? This is relatively contained and testable but it does take you right into core.

Activity

  1. sophiebits commented on May 22, 2014

    @sophiebits
    Collaborator

    Doing mixins first is more intuitive to me because that's normally how people write the specs (in my experience, at least).

  2. gaearon commented on May 23, 2014

    @gaearon
    Collaborator

    Hi, thanks for the mention. I'd like to take on this if nobody minds.
    I agree with @spicyj that calling mixins first is more intuitive.

  3. sophiebits commented on May 23, 2014

    @sophiebits
    Collaborator

    @gaearon Go for it! Let me know if you have any questions; I'm happy to help.

  4. gaearon commented on May 23, 2014

    @gaearon
    Collaborator

    OK great. I'll try to do it tomorrow.

  5. gaearon commented on May 26, 2014

    @gaearon
    Collaborator

    @zpao @spicyj

    Mention me if there's something else I can take. I liked that although this task had a small scope, it introduced me to the way createClass actually works and how spec transforms into a component instance. It would be cool if I could take a few small tasks in other areas (rendering, batching) that introduce me to these areas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions