1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | 'use strict';
|
9 |
|
10 | var _prodInvariant = require('./reactProdInvariant');
|
11 |
|
12 | var React = require('react/lib/React');
|
13 | var ReactDOMContainerInfo = require('./ReactDOMContainerInfo');
|
14 | var ReactDefaultBatchingStrategy = require('./ReactDefaultBatchingStrategy');
|
15 | var ReactInstrumentation = require('./ReactInstrumentation');
|
16 | var ReactMarkupChecksum = require('./ReactMarkupChecksum');
|
17 | var ReactReconciler = require('./ReactReconciler');
|
18 | var ReactServerBatchingStrategy = require('./ReactServerBatchingStrategy');
|
19 | var ReactServerRenderingTransaction = require('./ReactServerRenderingTransaction');
|
20 | var ReactUpdates = require('./ReactUpdates');
|
21 |
|
22 | var emptyObject = require('fbjs/lib/emptyObject');
|
23 | var instantiateReactComponent = require('./instantiateReactComponent');
|
24 | var invariant = require('fbjs/lib/invariant');
|
25 |
|
26 | var pendingTransactions = 0;
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | function renderToStringImpl(element, makeStaticMarkup) {
|
33 | var transaction;
|
34 | try {
|
35 | ReactUpdates.injection.injectBatchingStrategy(ReactServerBatchingStrategy);
|
36 |
|
37 | transaction = ReactServerRenderingTransaction.getPooled(makeStaticMarkup);
|
38 |
|
39 | pendingTransactions++;
|
40 |
|
41 | return transaction.perform(function () {
|
42 | var componentInstance = instantiateReactComponent(element, true);
|
43 | var markup = ReactReconciler.mountComponent(componentInstance, transaction, null, ReactDOMContainerInfo(), emptyObject, 0
|
44 | );
|
45 | if (process.env.NODE_ENV !== 'production') {
|
46 | ReactInstrumentation.debugTool.onUnmountComponent(componentInstance._debugID);
|
47 | }
|
48 | if (!makeStaticMarkup) {
|
49 | markup = ReactMarkupChecksum.addChecksumToMarkup(markup);
|
50 | }
|
51 | return markup;
|
52 | }, null);
|
53 | } finally {
|
54 | pendingTransactions--;
|
55 | ReactServerRenderingTransaction.release(transaction);
|
56 |
|
57 |
|
58 | if (!pendingTransactions) {
|
59 | ReactUpdates.injection.injectBatchingStrategy(ReactDefaultBatchingStrategy);
|
60 | }
|
61 | }
|
62 | }
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | function renderToString(element) {
|
70 | !React.isValidElement(element) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'renderToString(): You must pass a valid ReactElement.') : _prodInvariant('46') : void 0;
|
71 | return renderToStringImpl(element, false);
|
72 | }
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | function renderToStaticMarkup(element) {
|
80 | !React.isValidElement(element) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'renderToStaticMarkup(): You must pass a valid ReactElement.') : _prodInvariant('47') : void 0;
|
81 | return renderToStringImpl(element, true);
|
82 | }
|
83 |
|
84 | module.exports = {
|
85 | renderToString: renderToString,
|
86 | renderToStaticMarkup: renderToStaticMarkup
|
87 | }; |
\ | No newline at end of file |