Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81158 views
1
/**
2
* Copyright 2014, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @providesModule ReactServerRenderingTransaction
10
* @typechecks
11
*/
12
13
"use strict";
14
15
var PooledClass = require('PooledClass');
16
var CallbackQueue = require('CallbackQueue');
17
var ReactPutListenerQueue = require('ReactPutListenerQueue');
18
var Transaction = require('Transaction');
19
20
var assign = require('Object.assign');
21
var emptyFunction = require('emptyFunction');
22
23
/**
24
* Provides a `CallbackQueue` queue for collecting `onDOMReady` callbacks
25
* during the performing of the transaction.
26
*/
27
var ON_DOM_READY_QUEUEING = {
28
/**
29
* Initializes the internal `onDOMReady` queue.
30
*/
31
initialize: function() {
32
this.reactMountReady.reset();
33
},
34
35
close: emptyFunction
36
};
37
38
var PUT_LISTENER_QUEUEING = {
39
initialize: function() {
40
this.putListenerQueue.reset();
41
},
42
43
close: emptyFunction
44
};
45
46
/**
47
* Executed within the scope of the `Transaction` instance. Consider these as
48
* being member methods, but with an implied ordering while being isolated from
49
* each other.
50
*/
51
var TRANSACTION_WRAPPERS = [
52
PUT_LISTENER_QUEUEING,
53
ON_DOM_READY_QUEUEING
54
];
55
56
/**
57
* @class ReactServerRenderingTransaction
58
* @param {boolean} renderToStaticMarkup
59
*/
60
function ReactServerRenderingTransaction(renderToStaticMarkup) {
61
this.reinitializeTransaction();
62
this.renderToStaticMarkup = renderToStaticMarkup;
63
this.reactMountReady = CallbackQueue.getPooled(null);
64
this.putListenerQueue = ReactPutListenerQueue.getPooled();
65
}
66
67
var Mixin = {
68
/**
69
* @see Transaction
70
* @abstract
71
* @final
72
* @return {array} Empty list of operation wrap proceedures.
73
*/
74
getTransactionWrappers: function() {
75
return TRANSACTION_WRAPPERS;
76
},
77
78
/**
79
* @return {object} The queue to collect `onDOMReady` callbacks with.
80
*/
81
getReactMountReady: function() {
82
return this.reactMountReady;
83
},
84
85
getPutListenerQueue: function() {
86
return this.putListenerQueue;
87
},
88
89
/**
90
* `PooledClass` looks for this, and will invoke this before allowing this
91
* instance to be resused.
92
*/
93
destructor: function() {
94
CallbackQueue.release(this.reactMountReady);
95
this.reactMountReady = null;
96
97
ReactPutListenerQueue.release(this.putListenerQueue);
98
this.putListenerQueue = null;
99
}
100
};
101
102
103
assign(
104
ReactServerRenderingTransaction.prototype,
105
Transaction.Mixin,
106
Mixin
107
);
108
109
PooledClass.addPoolingTo(ReactServerRenderingTransaction);
110
111
module.exports = ReactServerRenderingTransaction;
112
113