@samitouri / QOS-React / commits / 50d905b083

change the argument passed to CallbackQueue.getPooled (#10101)

* change the argument passed to CallbackQueue.getPooled * remove undefined from function call * add test for ReactNativeReconcileTransaction * update log of tests * change test to one that operates on setState * added new tests and fixed another instance of the bug * run prettier * update names of tests and minor clean up * remove arg from CallbackQueue and update tests

Garrett McCullough committed Jul 12, 2017 at 10:49 UTC 50d905b0838857e76f7eb2f0875047c264f4c24e
7 files changed +54 -9
scripts/fiber/tests-passing.txt
+3
@@ -397,6 +397,7 @@ src/renderers/__tests__/ReactCompositeComponent-test.js
397 * prepares new child before unmounting old
398 * respects a shallow shouldComponentUpdate implementation
399 * does not do a deep comparison for a shallow shouldComponentUpdate implementation
400 +* should call setState callback with no arguments
401
402 src/renderers/__tests__/ReactCompositeComponentDOMMinimalism-test.js
403 * should not render extra nodes for non-interpolated text
@@ -1975,6 +1976,7 @@ src/renderers/dom/test/__tests__/ReactTestUtils-test.js
1976 * should enable rendering of cloned element
1977 * should set the type of the event
1978 * should work with renderIntoDocument
1979 +* should call setState callback with no arguments
1980
1981 src/renderers/native/__tests__/ReactNativeAttributePayload-test.js
1982 * should work with simple example
@@ -2004,6 +2006,7 @@ src/renderers/native/__tests__/ReactNativeMount-test.js
2006 * should be able to create and update a native component
2007 * returns the correct instance and calls it in the callback
2008 * renders and reorders children
2009 +* calls setState with no arguments
2010
2011 src/renderers/native/__tests__/createReactNativeComponentClass-test.js
2012 * should register viewConfigs
src/renderers/__tests__/ReactCompositeComponent-test.js
+15
@@ -1472,4 +1472,19 @@ describe('ReactCompositeComponent', () => {
1472 instance.setState(getInitialState());
1473 expect(renderCalls).toBe(3);
1474 });
1475 +
1476 + it('should call setState callback with no arguments', () => {
1477 + let mockArgs;
1478 + class Component extends React.Component {
1479 + componentDidMount() {
1480 + this.setState({}, (...args) => (mockArgs = args));
1481 + }
1482 + render() {
1483 + return false;
1484 + }
1485 + }
1486 +
1487 + ReactTestUtils.renderIntoDocument(<Component />);
1488 + expect(mockArgs.length).toEqual(0);
1489 + });
1490 });
src/renderers/dom/stack/client/ReactReconcileTransaction.js
+1 -1
@@ -120,7 +120,7 @@ function ReactReconcileTransaction(useCreateElement) {
120 // accessible and defaults to false when `ReactDOMComponent` and
121 // `ReactDOMTextComponent` checks it in `mountComponent`.`
122 this.renderToStaticMarkup = false;
123 - this.reactMountReady = CallbackQueue.getPooled(null);
123 + this.reactMountReady = CallbackQueue.getPooled();
124 this.useCreateElement = useCreateElement;
125 }
126
src/renderers/dom/test/__tests__/ReactTestUtils-test.js
+15
@@ -946,4 +946,19 @@ describe('ReactTestUtils', () => {
946 );
947 });
948 });
949 +
950 + it('should call setState callback with no arguments', () => {
951 + let mockArgs;
952 + class Component extends React.Component {
953 + componentDidMount() {
954 + this.setState({}, (...args) => (mockArgs = args));
955 + }
956 + render() {
957 + return false;
958 + }
959 + }
960 +
961 + ReactTestUtils.renderIntoDocument(<Component />);
962 + expect(mockArgs.length).toEqual(0);
963 + });
964 });
src/renderers/native/ReactNativeReconcileTransaction.js
+1 -1
@@ -67,7 +67,7 @@ if (__DEV__) {
67 */
68 function ReactNativeReconcileTransaction() {
69 this.reinitializeTransaction();
70 - this.reactMountReady = CallbackQueue.getPooled(null);
70 + this.reactMountReady = CallbackQueue.getPooled();
71 }
72
73 var Mixin = {
src/renderers/native/__tests__/ReactNativeMount-test.js
+15
@@ -108,4 +108,19 @@ describe('ReactNative', () => {
108 ReactNative.render(<Component chars={after} />, 11);
109 expect(UIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
110 });
111 +
112 + it('calls setState with no arguments', () => {
113 + var mockArgs;
114 + class Component extends React.Component {
115 + componentDidMount() {
116 + this.setState({}, (...args) => (mockArgs = args));
117 + }
118 + render() {
119 + return false;
120 + }
121 + }
122 +
123 + ReactNative.render(<Component />, 11);
124 + expect(mockArgs.length).toEqual(0);
125 + });
126 });
src/renderers/shared/stack/reconciler/CallbackQueue.js
+4 -7
@@ -28,15 +28,13 @@ var validateCallback = require('validateCallback');
28 * @implements PooledClass
29 * @internal
30 */
31 -class CallbackQueue<T, Targ> {
32 - _callbacks: ?Array<(arg: Targ) => void>;
31 +class CallbackQueue<T> {
32 + _callbacks: ?Array<() => void>;
33 _contexts: ?Array<T>;
34 - _arg: Targ;
34
36 - constructor(arg) {
35 + constructor() {
36 this._callbacks = null;
37 this._contexts = null;
39 - this._arg = arg;
38 }
39
40 /**
@@ -62,7 +60,6 @@ class CallbackQueue<T, Targ> {
60 notifyAll() {
61 var callbacks = this._callbacks;
62 var contexts = this._contexts;
65 - var arg = this._arg;
63 if (callbacks && contexts) {
64 invariant(
65 callbacks.length === contexts.length,
@@ -72,7 +69,7 @@ class CallbackQueue<T, Targ> {
69 this._contexts = null;
70 for (var i = 0; i < callbacks.length; i++) {
71 validateCallback(callbacks[i]);
75 - callbacks[i].call(contexts[i], arg);
72 + callbacks[i].call(contexts[i]);
73 }
74 callbacks.length = 0;
75 contexts.length = 0;