|
1 | 1 |
|
2 | 2 | var ReactServerAgent = require("../ReactServerAgent"),
|
3 |
| - React = require("react"); |
| 3 | + React = require('react'), |
| 4 | + PropTypes = require('prop-types'); |
4 | 5 |
|
5 | 6 | /**
|
6 | 7 | * FragmentDataCache writes out a serialized form of the ReactServerAgent request
|
@@ -36,37 +37,42 @@ var ReactServerAgent = require("../ReactServerAgent"),
|
36 | 37 | * * entry.res and entry.err.response won't have any `body` entry if
|
37 | 38 | * the response from the server was HTML instead of JSON.
|
38 | 39 | */
|
39 |
| -var FragmentDataCache = module.exports = React.createClass({ |
| 40 | +class FragmentDataCache extends React.Component { |
40 | 41 |
|
41 |
| - propTypes: { |
42 |
| - cacheNodeId: React.PropTypes.string, |
43 |
| - }, |
| 42 | + static get displayName() { |
| 43 | + return 'FragmentDataCache'; |
| 44 | + } |
44 | 45 |
|
45 |
| - displayName: 'FragmentDataCache', |
| 46 | + static get propTypes() { |
| 47 | + return { |
| 48 | + cacheNodeId: PropTypes.string, |
| 49 | + }; |
| 50 | + } |
46 | 51 |
|
47 |
| - getDefaultProps: function () { |
| 52 | + static get defaultProps() { |
48 | 53 | return {
|
49 | 54 | cacheNodeId: "react-server-fragment-data-cache",
|
50 |
| - } |
51 |
| - }, |
| 55 | + }; |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Return a promise that resolves with the FragmentDataCache component |
| 60 | + * when all pending data requests have resolved. |
| 61 | + */ |
| 62 | + static createWhenReady(fragmentDataCacheProps = {}) { |
| 63 | + return ReactServerAgent.cache().whenAllPendingResolve().then(() => { |
| 64 | + return <FragmentDataCache {...fragmentDataCacheProps} />; |
| 65 | + }); |
| 66 | + } |
52 | 67 |
|
53 |
| - render: function () { |
| 68 | + render() { |
54 | 69 | return (
|
55 | 70 | <div
|
56 | 71 | id={this.props.cacheNodeId}
|
57 | 72 | data-react-server-data-cache={JSON.stringify(ReactServerAgent.cache().dehydrate({ responseBodyOnly: true }))}>
|
58 | 73 | </div>
|
59 | 74 | );
|
60 |
| - }, |
61 |
| - |
62 |
| -}); |
| 75 | + } |
| 76 | +}; |
63 | 77 |
|
64 |
| -/** |
65 |
| - * Return a promise that resolves with the FragmentDataCache component |
66 |
| - * when all pending data requests have resolved. |
67 |
| - */ |
68 |
| -FragmentDataCache.createWhenReady = function (fragmentDataCacheProps = {}) { |
69 |
| - return ReactServerAgent.cache().whenAllPendingResolve().then(() => { |
70 |
| - return <FragmentDataCache {...fragmentDataCacheProps} />; |
71 |
| - }); |
72 |
| -} |
| 78 | +module.exports = FragmentDataCache; |
0 commit comments