Skip to content
This repository has been archived by the owner on Sep 11, 2018. It is now read-only.

Pure component notes #292

Merged
merged 2 commits into from
Dec 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions src/layouts/CoreLayout.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import React from 'react'
import 'styles/core.scss'

export default class CoreLayout extends React.Component {
static propTypes = {
children: React.PropTypes.element
}

render () {
return (
<div className='page-container'>
<div className='view-container'>
{this.props.children}
</div>
// Note: Stateless/function components *will not* hot reload!
// react-transform *only* works on component classes.
//
// Since layouts rarely change, they are a good place to
// leverage React's new Statelesss Functions:
// https://facebook.github.io/react/docs/reusable-components.html#stateless-functions
//
// CoreLayout is a pure function of it's props, so we can
// define it with a plain javascript function...
function CoreLayout ({ children }) {
return (
<div className='page-container'>
<div className='view-container'>
{children}
</div>
)
}
</div>
)
}

CoreLayout.propTypes = {
children: React.PropTypes.element
}

export default CoreLayout
18 changes: 11 additions & 7 deletions src/views/AboutView.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import React from 'react'
import { Link } from 'react-router'

const AboutView = () => (
<div className='container text-center'>
<h1>This is the about view!</h1>
<hr />
<Link to='/'>Back To Home View</Link>
</div>
)
export class AboutView extends React.Component {
render () {
return (
<div className='container text-center'>
<h1>This is the about view!</h1>
<hr />
<Link to='/'>Back To Home View</Link>
</div>
)
}
}

export default AboutView
7 changes: 0 additions & 7 deletions tests/layouts/CoreLayout.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,4 @@ describe('(Layout) Core', function () {
expect(_component.type).to.equal('div')
})

it('Should render a child component.', function () {
const child = TestUtils.findRenderedDOMComponentWithClass(
_rendered, 'child'
)

expect(child).to.exist
})
})
Copy link
Owner

Choose a reason for hiding this comment

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

This is because the test utils don't work with pure components yet, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

exactly... do you want me to revert this commit to leave this as component class too?

Copy link
Owner

Choose a reason for hiding this comment

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

Not at all, was just making sure. And I'm not totally caught up to speed here: A regular React component class rendered inside of a pure component will still work w/ HMR, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@davezuko yes all transforms are working, see below. i also tested hmr with multiple nested AboutViews to be sure react-transform is walking the full component tree 👍

Copy link
Owner

Choose a reason for hiding this comment

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

That would be amazing, and thanks for all the gifs, they help a lot!