UNPKG

3.35 kBJavaScriptView Raw
1/**
2 * Copyright (c) 2015-present, Facebook, Inc.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 *
8 */
9'use strict';
10
11var _assign = require('object-assign');
12
13var CallbackQueue = require('./CallbackQueue');
14var PooledClass = require('./PooledClass');
15var Transaction = require('./Transaction');
16var ReactUpdateQueue = require('./ReactUpdateQueue');
17
18/**
19 * Provides a `CallbackQueue` queue for collecting `onDOMReady` callbacks during
20 * the performing of the transaction.
21 */
22var ON_DOM_READY_QUEUEING = {
23 /**
24 * Initializes the internal `onDOMReady` queue.
25 */
26 initialize: function () {
27 this.reactMountReady.reset();
28 },
29
30 /**
31 * After DOM is flushed, invoke all registered `onDOMReady` callbacks.
32 */
33 close: function () {
34 this.reactMountReady.notifyAll();
35 }
36};
37
38/**
39 * Executed within the scope of the `Transaction` instance. Consider these as
40 * being member methods, but with an implied ordering while being isolated from
41 * each other.
42 */
43var TRANSACTION_WRAPPERS = [ON_DOM_READY_QUEUEING];
44
45/**
46 * Currently:
47 * - The order that these are listed in the transaction is critical:
48 * - Suppresses events.
49 * - Restores selection range.
50 *
51 * Future:
52 * - Restore document/overflow scroll positions that were unintentionally
53 * modified via DOM insertions above the top viewport boundary.
54 * - Implement/integrate with customized constraint based layout system and keep
55 * track of which dimensions must be remeasured.
56 *
57 * @class ReactTestReconcileTransaction
58 */
59function ReactTestReconcileTransaction(testOptions) {
60 this.reinitializeTransaction();
61 this.testOptions = testOptions;
62 this.reactMountReady = CallbackQueue.getPooled(this);
63}
64
65var Mixin = {
66 /**
67 * @see Transaction
68 * @abstract
69 * @final
70 * @return {array<object>} List of operation wrap procedures.
71 * TODO: convert to array<TransactionWrapper>
72 */
73 getTransactionWrappers: function () {
74 return TRANSACTION_WRAPPERS;
75 },
76
77 /**
78 * @return {object} The queue to collect `onDOMReady` callbacks with.
79 * TODO: convert to ReactMountReady
80 */
81 getReactMountReady: function () {
82 return this.reactMountReady;
83 },
84
85 /**
86 * @return {object} the options passed to ReactTestRenderer
87 */
88 getTestOptions: function () {
89 return this.testOptions;
90 },
91
92 /**
93 * @return {object} The queue to collect React async events.
94 */
95 getUpdateQueue: function () {
96 return ReactUpdateQueue;
97 },
98
99 /**
100 * Save current transaction state -- if the return value from this method is
101 * passed to `rollback`, the transaction will be reset to that state.
102 */
103 checkpoint: function () {
104 // reactMountReady is the our only stateful wrapper
105 return this.reactMountReady.checkpoint();
106 },
107
108 rollback: function (checkpoint) {
109 this.reactMountReady.rollback(checkpoint);
110 },
111
112 /**
113 * `PooledClass` looks for this, and will invoke this before allowing this
114 * instance to be reused.
115 */
116 destructor: function () {
117 CallbackQueue.release(this.reactMountReady);
118 this.reactMountReady = null;
119 }
120};
121
122_assign(ReactTestReconcileTransaction.prototype, Transaction, ReactTestReconcileTransaction, Mixin);
123
124PooledClass.addPoolingTo(ReactTestReconcileTransaction);
125
126module.exports = ReactTestReconcileTransaction;
\No newline at end of file