@samitouri / QOS-React-2 / commits / 9b0534eb77

ReactRAFBatchingStrategy

This will go in React addons only for now until we figure out `pendingState`.

Pete Hunt committed Mar 3, 2014 at 09:39 UTC 9b0534eb775322735fe099d4c3dc600e47c20b4d
1 file changed +48
src/addons/ReactRAFBatchingStrategy.js new
+48
@@ -0,0 +1,48 @@
1 +/**
2 + * Copyright 2013-2014 Facebook, Inc.
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + *
16 + * @providesModule ReactRAFBatchingStrategy
17 + * @typechecks static-only
18 + */
19 +
20 +"use strict";
21 +
22 +var ExecutionEnvironment = require('ExecutionEnvironment');
23 +var ReactUpdates = require('ReactUpdates');
24 +
25 +var requestAnimationFrame = require('requestAnimationFrame');
26 +
27 +function tick() {
28 + ReactUpdates.flushBatchedUpdates();
29 + requestAnimationFrame(tick);
30 +}
31 +
32 +var ReactRAFBatchingStrategy = {
33 + isBatchingUpdates: true,
34 +
35 + /**
36 + * Call the provided function in a context within which calls to `setState`
37 + * and friends are batched such that components aren't updated unnecessarily.
38 + */
39 + batchedUpdates: function(callback, param) {
40 + callback(param);
41 + }
42 +};
43 +
44 +if (ExecutionEnvironment.canUseDOM) {
45 + requestAnimationFrame(tick);
46 +}
47 +
48 +module.exports = ReactRAFBatchingStrategy;