react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / browser / ReactReconcileTransaction.js
81152 views/**1* Copyright 2013-2014, Facebook, Inc.2* All rights reserved.3*4* This source code is licensed under the BSD-style license found in the5* LICENSE file in the root directory of this source tree. An additional grant6* of patent rights can be found in the PATENTS file in the same directory.7*8* @providesModule ReactReconcileTransaction9* @typechecks static-only10*/1112"use strict";1314var CallbackQueue = require('CallbackQueue');15var PooledClass = require('PooledClass');16var ReactBrowserEventEmitter = require('ReactBrowserEventEmitter');17var ReactInputSelection = require('ReactInputSelection');18var ReactPutListenerQueue = require('ReactPutListenerQueue');19var Transaction = require('Transaction');2021var assign = require('Object.assign');2223/**24* Ensures that, when possible, the selection range (currently selected text25* input) is not disturbed by performing the transaction.26*/27var SELECTION_RESTORATION = {28/**29* @return {Selection} Selection information.30*/31initialize: ReactInputSelection.getSelectionInformation,32/**33* @param {Selection} sel Selection information returned from `initialize`.34*/35close: ReactInputSelection.restoreSelection36};3738/**39* Suppresses events (blur/focus) that could be inadvertently dispatched due to40* high level DOM manipulations (like temporarily removing a text input from the41* DOM).42*/43var EVENT_SUPPRESSION = {44/**45* @return {boolean} The enabled status of `ReactBrowserEventEmitter` before46* the reconciliation.47*/48initialize: function() {49var currentlyEnabled = ReactBrowserEventEmitter.isEnabled();50ReactBrowserEventEmitter.setEnabled(false);51return currentlyEnabled;52},5354/**55* @param {boolean} previouslyEnabled Enabled status of56* `ReactBrowserEventEmitter` before the reconciliation occured. `close`57* restores the previous value.58*/59close: function(previouslyEnabled) {60ReactBrowserEventEmitter.setEnabled(previouslyEnabled);61}62};6364/**65* Provides a queue for collecting `componentDidMount` and66* `componentDidUpdate` callbacks during the the transaction.67*/68var ON_DOM_READY_QUEUEING = {69/**70* Initializes the internal `onDOMReady` queue.71*/72initialize: function() {73this.reactMountReady.reset();74},7576/**77* After DOM is flushed, invoke all registered `onDOMReady` callbacks.78*/79close: function() {80this.reactMountReady.notifyAll();81}82};8384var PUT_LISTENER_QUEUEING = {85initialize: function() {86this.putListenerQueue.reset();87},8889close: function() {90this.putListenerQueue.putListeners();91}92};9394/**95* Executed within the scope of the `Transaction` instance. Consider these as96* being member methods, but with an implied ordering while being isolated from97* each other.98*/99var TRANSACTION_WRAPPERS = [100PUT_LISTENER_QUEUEING,101SELECTION_RESTORATION,102EVENT_SUPPRESSION,103ON_DOM_READY_QUEUEING104];105106/**107* Currently:108* - The order that these are listed in the transaction is critical:109* - Suppresses events.110* - Restores selection range.111*112* Future:113* - Restore document/overflow scroll positions that were unintentionally114* modified via DOM insertions above the top viewport boundary.115* - Implement/integrate with customized constraint based layout system and keep116* track of which dimensions must be remeasured.117*118* @class ReactReconcileTransaction119*/120function ReactReconcileTransaction() {121this.reinitializeTransaction();122// Only server-side rendering really needs this option (see123// `ReactServerRendering`), but server-side uses124// `ReactServerRenderingTransaction` instead. This option is here so that it's125// accessible and defaults to false when `ReactDOMComponent` and126// `ReactTextComponent` checks it in `mountComponent`.`127this.renderToStaticMarkup = false;128this.reactMountReady = CallbackQueue.getPooled(null);129this.putListenerQueue = ReactPutListenerQueue.getPooled();130}131132var Mixin = {133/**134* @see Transaction135* @abstract136* @final137* @return {array<object>} List of operation wrap proceedures.138* TODO: convert to array<TransactionWrapper>139*/140getTransactionWrappers: function() {141return TRANSACTION_WRAPPERS;142},143144/**145* @return {object} The queue to collect `onDOMReady` callbacks with.146*/147getReactMountReady: function() {148return this.reactMountReady;149},150151getPutListenerQueue: function() {152return this.putListenerQueue;153},154155/**156* `PooledClass` looks for this, and will invoke this before allowing this157* instance to be resused.158*/159destructor: function() {160CallbackQueue.release(this.reactMountReady);161this.reactMountReady = null;162163ReactPutListenerQueue.release(this.putListenerQueue);164this.putListenerQueue = null;165}166};167168169assign(ReactReconcileTransaction.prototype, Transaction.Mixin, Mixin);170171PooledClass.addPoolingTo(ReactReconcileTransaction);172173module.exports = ReactReconcileTransaction;174175176