react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / core / ReactDefaultBatchingStrategy.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 ReactDefaultBatchingStrategy9*/1011"use strict";1213var ReactUpdates = require('ReactUpdates');14var Transaction = require('Transaction');1516var assign = require('Object.assign');17var emptyFunction = require('emptyFunction');1819var RESET_BATCHED_UPDATES = {20initialize: emptyFunction,21close: function() {22ReactDefaultBatchingStrategy.isBatchingUpdates = false;23}24};2526var FLUSH_BATCHED_UPDATES = {27initialize: emptyFunction,28close: ReactUpdates.flushBatchedUpdates.bind(ReactUpdates)29};3031var TRANSACTION_WRAPPERS = [FLUSH_BATCHED_UPDATES, RESET_BATCHED_UPDATES];3233function ReactDefaultBatchingStrategyTransaction() {34this.reinitializeTransaction();35}3637assign(38ReactDefaultBatchingStrategyTransaction.prototype,39Transaction.Mixin,40{41getTransactionWrappers: function() {42return TRANSACTION_WRAPPERS;43}44}45);4647var transaction = new ReactDefaultBatchingStrategyTransaction();4849var ReactDefaultBatchingStrategy = {50isBatchingUpdates: false,5152/**53* Call the provided function in a context within which calls to `setState`54* and friends are batched such that components aren't updated unnecessarily.55*/56batchedUpdates: function(callback, a, b) {57var alreadyBatchingUpdates = ReactDefaultBatchingStrategy.isBatchingUpdates;5859ReactDefaultBatchingStrategy.isBatchingUpdates = true;6061// The code is written this way to avoid extra allocations62if (alreadyBatchingUpdates) {63callback(a, b);64} else {65transaction.perform(callback, null, a, b);66}67}68};6970module.exports = ReactDefaultBatchingStrategy;717273