Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

Only wrap descendants with render method, closes #84 #86

Merged
merged 4 commits into from
Mar 4, 2016

Conversation

nfcampos
Copy link
Collaborator

closes #84 (see the issue for a discussion of the changes)

todo

  • fix current tests
  • make change to index.js
  • write additional tests

@nfcampos
Copy link
Collaborator Author

@gaearon should i write a new test for each of the cases the current tests used to cover?

@gaearon
Copy link
Owner

gaearon commented Feb 18, 2016

Please do.

@nfcampos
Copy link
Collaborator Author

something like this is not supposed to be wrapped, is it?

import React, { Component } from 'react'
class Foo extends Component {
  render() {}
}

@gaearon
Copy link
Owner

gaearon commented Feb 18, 2016

This looks like a React component to me, why not?

@nfcampos
Copy link
Collaborator Author

because it requires changing this line https://github.com/gaearon/babel-plugin-react-transform/blob/master/src/index.js#L174
to superClasses: options.superClasses || ['React.Component', 'Component'],
which mean that any class that extends a class called Component and has a render method is wrapped.
is that ok? or is there some other way of doing this?

@gaearon
Copy link
Owner

gaearon commented Feb 18, 2016

Good catch. I would say let’s add Component to defaults. It’s a too common pattern.

@nfcampos
Copy link
Collaborator Author

yeah i agree. does that go into this PR or another one (it's not really related to this)?

@gaearon
Copy link
Owner

gaearon commented Feb 18, 2016

It’s fine to do this here.

@nfcampos
Copy link
Collaborator Author

Alright, it's all done i think.
changes:

  • only wrap classes that extend the correct superClass and have a render method
  • changed tests to reflect change above
  • added Component to default superClasses
  • added test for the above

@nfcampos nfcampos changed the title (wip) only wrap descendants with render method, closes #84 Only wrap descendants with render method, closes #84 Feb 18, 2016
@gaearon
Copy link
Owner

gaearon commented Feb 18, 2016

Seems like technically this wouldn’t even be a breaking change because we used to allow any class with render() anyway.

@nfcampos
Copy link
Collaborator Author

well it breaks some stuff that shouldn't work anyways, so that part is fine

to me it looks like the only breaking change would be stuff like this:

import React from 'react'
const Comp = React.Component
class Foo extends Comp {
  render() {}
}

this would have worked previously because it had a render method and now won't, but would anyone actually do something like this?

@gaearon
Copy link
Owner

gaearon commented Feb 18, 2016

Even if they used this pattern, we’re not technically “breaking” it because the code would still work. Transforms are meant for development only anyway.

@nfcampos
Copy link
Collaborator Author

yeah that's true

gaearon added a commit that referenced this pull request Mar 4, 2016
Only wrap descendants with render method, closes #84
@gaearon gaearon merged commit 84878e0 into gaearon:master Mar 4, 2016
@gaearon
Copy link
Owner

gaearon commented Mar 4, 2016

Out in 2.0.1, thank you a lot!

@nfcampos
Copy link
Collaborator Author

nfcampos commented Mar 4, 2016

Happy to help!

@gaearon
Copy link
Owner

gaearon commented Mar 4, 2016

If you have time, I’d appreciate you looking into why #87 fails, merging/updating it if it’s correct, and checking whether it fixes another correctness issue: #88.

@nfcampos
Copy link
Collaborator Author

nfcampos commented Mar 4, 2016

I'll look into it

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

Successfully merging this pull request may close these issues.

Appears to wrap other functions than createClass()
2 participants