Skip to content

Commit

Permalink
Remove dependency on create-react-class
Browse files Browse the repository at this point in the history
  • Loading branch information
salehhamadeh committed Nov 3, 2017
1 parent 9232e77 commit 40b36cd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
48 changes: 26 additions & 22 deletions packages/react-server/core/components/FragmentDataCache.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

var ReactServerAgent = require("../ReactServerAgent"),
React = require('react'),
PropTypes = require('prop-types'),
createReactClass = require("create-react-class");
PropTypes = require('prop-types');

/**
* FragmentDataCache writes out a serialized form of the ReactServerAgent request
Expand Down Expand Up @@ -38,37 +37,42 @@ var ReactServerAgent = require("../ReactServerAgent"),
* * entry.res and entry.err.response won't have any `body` entry if
* the response from the server was HTML instead of JSON.
*/
var FragmentDataCache = module.exports = createReactClass({
class FragmentDataCache extends React.Component {

propTypes: {
cacheNodeId: PropTypes.string,
},
static get displayName() {
return 'FragmentDataCache';
}

displayName: 'FragmentDataCache',
static get propTypes() {
return {
cacheNodeId: PropTypes.string,
};
}

getDefaultProps: function () {
static get defaultProps() {
return {
cacheNodeId: "react-server-fragment-data-cache",
}
},
};
}

render: function () {
render() {
return (
<div
id={this.props.cacheNodeId}
data-react-server-data-cache={JSON.stringify(ReactServerAgent.cache().dehydrate({ responseBodyOnly: true }))}>
</div>
);
},
}

});
/**
* Return a promise that resolves with the FragmentDataCache component
* when all pending data requests have resolved.
*/
createWhenReady(fragmentDataCacheProps = {}) {
return ReactServerAgent.cache().whenAllPendingResolve().then(() => {
return <FragmentDataCache {...fragmentDataCacheProps} />;
});
}
};

/**
* Return a promise that resolves with the FragmentDataCache component
* when all pending data requests have resolved.
*/
FragmentDataCache.createWhenReady = function (fragmentDataCacheProps = {}) {
return ReactServerAgent.cache().whenAllPendingResolve().then(() => {
return <FragmentDataCache {...fragmentDataCacheProps} />;
});
}
module.exports = FragmentDataCache;
2 changes: 0 additions & 2 deletions packages/react-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"winston": "^2.3.0"
},
"peerDependencies": {
"create-react-class": "^15.6.2",
"react": "~0.14.9 || ^15.3.0 || ^16.0.0",
"react-dom": "~0.14.9 || ^15.3.0 || ^16.0.0",
"superagent": "1.8.4"
Expand All @@ -52,7 +51,6 @@
"babel-preset-stage-1": "^6.16.0",
"benchmark": "^2.1.4",
"cheerio": "^0.22.0",
"create-react-class": "^15.6.2",
"eslint": "^3.8.1",
"eslint-plugin-react": "^6.4.1",
"express": "^4.14.0",
Expand Down

0 comments on commit 40b36cd

Please sign in to comment.