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