From 2bda21fbf0e6cd5de0619b776bdaf30ec42dd6c3 Mon Sep 17 00:00:00 2001 From: Tadeu Zagallo Date: Wed, 22 Apr 2015 17:50:54 -0700 Subject: [PATCH] [ReactNative] Flush ReactUpdates only once per batch --- Libraries/Utilities/MessageQueue.js | 32 ++++++++++++++++------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/Libraries/Utilities/MessageQueue.js b/Libraries/Utilities/MessageQueue.js index c047d06de..576aaa991 100644 --- a/Libraries/Utilities/MessageQueue.js +++ b/Libraries/Utilities/MessageQueue.js @@ -10,7 +10,9 @@ * @flow */ 'use strict'; + var ErrorUtils = require('ErrorUtils'); +var ReactUpdates = require('ReactUpdates'); var invariant = require('invariant'); var warning = require('warning'); @@ -307,21 +309,23 @@ var MessageQueueMixin = { ); }, - processBatch: function (batch) { + processBatch: function(batch) { var self = this; - batch.forEach(function (call) { - invariant( - call.module === 'BatchedBridge', - 'All the calls should pass through the BatchedBridge module' - ); - if (call.method === 'callFunctionReturnFlushedQueue') { - self.callFunction.apply(self, call.args); - } else if (call.method === 'invokeCallbackAndReturnFlushedQueue') { - self.invokeCallback.apply(self, call.args); - } else { - throw new Error( - 'Unrecognized method called on BatchedBridge: ' + call.method); - } + ReactUpdates.batchedUpdates(function() { + batch.forEach(function(call) { + invariant( + call.module === 'BatchedBridge', + 'All the calls should pass through the BatchedBridge module' + ); + if (call.method === 'callFunctionReturnFlushedQueue') { + self.callFunction.apply(self, call.args); + } else if (call.method === 'invokeCallbackAndReturnFlushedQueue') { + self.invokeCallback.apply(self, call.args); + } else { + throw new Error( + 'Unrecognized method called on BatchedBridge: ' + call.method); + } + }); }); return this.flushedQueue(); },