Skip to content
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
25 changes: 13 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var React = require('react'),
PropTypes = require('prop-types'),
withSideEffect = require('react-side-effect');

function reducePropsToState(propsList) {
Expand All @@ -17,21 +18,21 @@ function handleStateChangeOnClient(title) {
}
}

var DocumentTitle = React.createClass({
displayName: 'DocumentTitle',
function DocumentTitle() {}
DocumentTitle.prototype = Object.create(React.Component.prototype);

propTypes: {
title: React.PropTypes.string.isRequired
},
DocumentTitle.displayName = 'DocumentTitle';
DocumentTitle.propTypes = {
title: PropTypes.string.isRequired
};

render: function render() {
if (this.props.children) {
return React.Children.only(this.props.children);
} else {
return null;
}
DocumentTitle.prototype.render = function() {
if (this.props.children) {
return React.Children.only(this.props.children);
} else {
return null;
}
});
};

module.exports = withSideEffect(
reducePropsToState,
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
},
"homepage": "https://github.com/gaearon/react-document-title",
"devDependencies": {
"create-react-class": "^15.5.2",
Copy link
Owner

Choose a reason for hiding this comment

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

We can remove this now, right?

Copy link
Owner

Choose a reason for hiding this comment

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

Ah nevermind, it's dev deps.

"expect.js": "^0.3.1",
"global": "^4.3.0",
"jshint": "^2.5.6",
"mocha": "^2.0.1",
"react": "^0.13.0"
},
"dependencies": {
"prop-types": "^15.5.6",
"react-side-effect": "^1.0.2"
}
}
7 changes: 4 additions & 3 deletions test/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'use strict';
var expect = require('expect.js'),
React = require('react'),
createReactClass = require('create-react-class'),
DocumentTitle = require('../');

describe('DocumentTitle (in a browser)', function () {
Expand All @@ -27,7 +28,7 @@ describe('DocumentTitle (in a browser)', function () {
});
it('changes the document title on mount', function (done) {
var title = 'hello world';
var Component = React.createClass({
var Component = createReactClass({
componentDidMount: function () {
expect(global.document.title).to.equal(title);
done();
Expand All @@ -41,7 +42,7 @@ describe('DocumentTitle (in a browser)', function () {
it('supports nesting', function (done) {
var called = false;
var title = 'hello world';
var Component1 = React.createClass({
var Component1 = createReactClass({
componentDidMount: function () {
setTimeout(function () {
expect(called).to.be(true);
Expand All @@ -53,7 +54,7 @@ describe('DocumentTitle (in a browser)', function () {
return React.createElement(DocumentTitle, {title: title});
}
});
var Component2 = React.createClass({
var Component2 = createReactClass({
componentDidMount: function () {
called = true;
},
Expand Down
9 changes: 5 additions & 4 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'use strict';
var expect = require('expect.js'),
React = require('react'),
createReactClass = require('create-react-class'),
DocumentTitle = require('../');

describe('DocumentTitle', function () {
Expand All @@ -17,7 +18,7 @@ describe('DocumentTitle', function () {
expect(el.type.displayName).to.equal('SideEffect(DocumentTitle)');
});
it('hides itself from the DOM', function () {
var Component = React.createClass({
var Component = createReactClass({
render: function () {
return React.createElement(DocumentTitle, {title: 'irrelevant'},
React.createElement('div', null, 'hello')
Expand All @@ -28,7 +29,7 @@ describe('DocumentTitle', function () {
expect(markup).to.equal('<div>hello</div>');
});
it('throws an error if it has multiple children', function (done) {
var Component = React.createClass({
var Component = createReactClass({
render: function () {
return React.createElement(DocumentTitle, {title: 'irrelevant'},
React.createElement('div', null, 'hello'),
Expand All @@ -44,15 +45,15 @@ describe('DocumentTitle', function () {
});
});
it('works with complex children', function () {
var Component1 = React.createClass({
var Component1 = createReactClass({
render: function() {
return React.createElement('p', null,
React.createElement('span', null, 'c'),
React.createElement('span', null, 'd')
);
}
});
var Component2 = React.createClass({
var Component2 = createReactClass({
render: function () {
return React.createElement(DocumentTitle, {title: 'irrelevant'},
React.createElement('div', null,
Expand Down