From 52d1c5c85cfc27e6f96e7eba83bbd60408aef9d7 Mon Sep 17 00:00:00 2001 From: abiduzz420 Date: Thu, 30 Nov 2017 03:34:19 +0530 Subject: [PATCH 1/6] WIP:use public API --- .../ReactIncrementalPerf-test.internal.js | 1094 ++++++++--------- 1 file changed, 542 insertions(+), 552 deletions(-) diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js b/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js index 8738e14c686..a342c6c9931 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js @@ -10,556 +10,546 @@ 'use strict'; describe('ReactDebugFiberPerf', () => { - let React; - let ReactCallReturn; - let ReactNoop; - let ReactPortal; - let PropTypes; - - let root; - let activeMeasure; - let knownMarks; - let knownMeasures; - let comments; - - function resetFlamechart() { - root = { - children: [], - indent: -1, - markName: null, - label: null, - parent: null, - toString() { - return this.children.map(c => c.toString()).join('\n'); - }, - }; - activeMeasure = root; - knownMarks = new Set(); - knownMeasures = new Set(); - comments = []; - } - - function addComment(comment) { - comments.push(comment); - } - - function getFlameChart() { - // Make sure we unwind the measurement stack every time. - expect(activeMeasure.indent).toBe(-1); - expect(activeMeasure).toBe(root); - // We should always clean them up because browsers - // buffer user timing measurements forever. - expect(knownMarks.size).toBe(0); - expect(knownMeasures.size).toBe(0); - return root.toString(); - } - - function createUserTimingPolyfill() { - // This is not a true polyfill, but it gives us enough - // to capture measurements in a readable tree-like output. - // Reference: https://developer.mozilla.org/en-US/docs/Web/API/User_Timing_API - return { - mark(markName) { - const measure = { - children: [], - indent: activeMeasure.indent + 1, - markName: markName, - // Will be assigned on measure() call: - label: null, - parent: activeMeasure, - comments, - toString() { - return ( - [ - ...this.comments.map(c => ' '.repeat(this.indent) + '// ' + c), - ' '.repeat(this.indent) + this.label, - ...this.children.map(c => c.toString()), - ].join('\n') + - // Extra newline after each root reconciliation - (this.indent === 0 ? '\n' : '') - ); - }, - }; - comments = []; - // Step one level deeper - activeMeasure.children.push(measure); - activeMeasure = measure; - knownMarks.add(markName); - }, - // We don't use the overload with three arguments. - measure(label, markName) { - if (markName !== activeMeasure.markName) { - throw new Error('Unexpected measure() call.'); - } - // Step one level up - activeMeasure.label = label; - activeMeasure = activeMeasure.parent; - knownMeasures.add(label); - }, - clearMarks(markName) { - if (markName === activeMeasure.markName) { - // Step one level up if we're in this measure - activeMeasure = activeMeasure.parent; - activeMeasure.children.length--; - } - knownMarks.delete(markName); - }, - clearMeasures(label) { - knownMeasures.delete(label); - }, - }; - } - - beforeEach(() => { - jest.resetModules(); - resetFlamechart(); - global.performance = createUserTimingPolyfill(); - - require('shared/ReactFeatureFlags').enableUserTimingAPI = true; - - // Import after the polyfill is set up: - React = require('react'); - ReactNoop = require('react-noop-renderer'); - ReactCallReturn = require('react-call-return'); - // TODO: can we express this test with only public API? - ReactPortal = require('../ReactPortal'); - PropTypes = require('prop-types'); - }); - - afterEach(() => { - delete global.performance; - }); - - function Parent(props) { - return
{props.children}
; - } - - function Child(props) { - return
{props.children}
; - } - - it('measures a simple reconciliation', () => { - ReactNoop.render( - - - , - ); - addComment('Mount'); - ReactNoop.flush(); - - ReactNoop.render( - - - , - ); - addComment('Update'); - ReactNoop.flush(); - - ReactNoop.render(null); - addComment('Unmount'); - ReactNoop.flush(); - - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('skips parents during setState', () => { - class A extends React.Component { - render() { - return
{this.props.children}
; - } - } - - class B extends React.Component { - render() { - return
{this.props.children}
; - } - } - - let a; - let b; - ReactNoop.render( - - - - (a = inst)} /> - - - - (b = inst)} /> - - , - ); - ReactNoop.flush(); - resetFlamechart(); - - a.setState({}); - b.setState({}); - addComment('Should include just A and B, no Parents'); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('warns on cascading renders from setState', () => { - class Cascading extends React.Component { - componentDidMount() { - this.setState({}); - } - render() { - return
{this.props.children}
; - } - } - - ReactNoop.render( - - - , - ); - addComment('Should print a warning'); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('warns on cascading renders from top-level render', () => { - class Cascading extends React.Component { - componentDidMount() { - ReactNoop.renderToRootWithID(, 'b'); - addComment('Scheduling another root from componentDidMount'); - ReactNoop.flush(); - } - render() { - return
{this.props.children}
; - } - } - - ReactNoop.renderToRootWithID(, 'a'); - addComment('Rendering the first root'); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('does not treat setState from cWM or cWRP as cascading', () => { - class NotCascading extends React.Component { - componentWillMount() { - this.setState({}); - } - componentWillReceiveProps() { - this.setState({}); - } - render() { - return
{this.props.children}
; - } - } - - ReactNoop.render( - - - , - ); - addComment('Should not print a warning'); - ReactNoop.flush(); - ReactNoop.render( - - - , - ); - addComment('Should not print a warning'); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('captures all lifecycles', () => { - class AllLifecycles extends React.Component { - static childContextTypes = { - foo: PropTypes.any, - }; - shouldComponentUpdate() { - return true; - } - getChildContext() { - return {foo: 42}; - } - componentWillMount() {} - componentDidMount() {} - componentWillReceiveProps() {} - componentWillUpdate() {} - componentDidUpdate() {} - componentWillUnmount() {} - render() { - return
; - } - } - ReactNoop.render(); - addComment('Mount'); - ReactNoop.flush(); - ReactNoop.render(); - addComment('Update'); - ReactNoop.flush(); - ReactNoop.render(null); - addComment('Unmount'); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('measures deprioritized work', () => { - addComment('Flush the parent'); - ReactNoop.flushSync(() => { - ReactNoop.render( - - - , - ); - }); - addComment('Flush the child'); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('measures deferred work in chunks', () => { - class A extends React.Component { - render() { - return
{this.props.children}
; - } - } - - class B extends React.Component { - render() { - return
{this.props.children}
; - } - } - - ReactNoop.render( - -
- - - - - - , - ); - addComment('Start mounting Parent and A'); - ReactNoop.flushDeferredPri(40); - addComment('Mount B just a little (but not enough to memoize)'); - ReactNoop.flushDeferredPri(10); - addComment('Complete B and Parent'); - ReactNoop.flushDeferredPri(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('recovers from fatal errors', () => { - function Baddie() { - throw new Error('Game over'); - } - - ReactNoop.render( - - - , - ); - try { - addComment('Will fatal'); - ReactNoop.flush(); - } catch (err) { - expect(err.message).toBe('Game over'); - } - ReactNoop.render( - - - , - ); - addComment('Will reconcile from a clean state'); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('recovers from caught errors', () => { - function Baddie() { - throw new Error('Game over'); - } - - function ErrorReport() { - return
; - } - - class Boundary extends React.Component { - state = {error: null}; - componentDidCatch(error) { - this.setState({error}); - } - render() { - if (this.state.error) { - return ; - } - return this.props.children; - } - } - - ReactNoop.render( - - - - - - - , - ); - addComment('Stop on Baddie and restart from Boundary'); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('deduplicates lifecycle names during commit to reduce overhead', () => { - class A extends React.Component { - componentDidUpdate() {} - render() { - return
; - } - } - - class B extends React.Component { - componentDidUpdate(prevProps) { - if (this.props.cascade && !prevProps.cascade) { - this.setState({}); - } - } - render() { - return
; - } - } - - ReactNoop.render( - - - - - - , - ); - ReactNoop.flush(); - resetFlamechart(); - - ReactNoop.render( - - - - - - , - ); - addComment('The commit phase should mention A and B just once'); - ReactNoop.flush(); - ReactNoop.render( - - - - - - , - ); - addComment("Because of deduplication, we don't know B was cascading,"); - addComment('but we should still see the warning for the commit phase.'); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('supports returns', () => { - function Continuation({isSame}) { - return ; - } - - function CoChild({bar}) { - return ReactCallReturn.unstable_createReturn({ - props: { - bar: bar, - }, - continuation: Continuation, - }); - } - - function Indirection() { - return [, ]; - } - - function HandleReturns(props, returns) { - return returns.map((y, i) => ( - - )); - } - - function CoParent(props) { - return ReactCallReturn.unstable_createCall( - props.children, - HandleReturns, - props, - ); - } - - function App() { - return ( -
- - - -
- ); - } - - ReactNoop.render(); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('supports portals', () => { - const noopContainer = {children: []}; - ReactNoop.render( - - {ReactPortal.createPortal(, noopContainer, null)} - , - ); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('does not schedule an extra callback if setState is called during a synchronous commit phase', () => { - class Component extends React.Component { - state = {step: 1}; - componentDidMount() { - this.setState({step: 2}); - } - render() { - return ; - } - } - ReactNoop.flushSync(() => { - ReactNoop.render(); - }); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('warns if an in-progress update is interrupted', () => { - function Foo() { - return ; - } - - ReactNoop.render(); - ReactNoop.flushUnitsOfWork(2); - ReactNoop.flushSync(() => { - ReactNoop.render(); - }); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('warns if async work expires (starvation)', () => { - function Foo() { - return ; - } - - ReactNoop.render(); - ReactNoop.expire(5000); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); + let React; + let ReactCallReturn; + let ReactNoop; + let ReactDOM; + let PropTypes; + + let root; + let activeMeasure; + let knownMarks; + let knownMeasures; + let comments; + + function resetFlamechart() { + root = { + children: [], + indent: -1, + markName: null, + label: null, + parent: null, + toString() { + return this.children.map(c => c.toString()).join('\n'); + }, + }; + activeMeasure = root; + knownMarks = new Set(); + knownMeasures = new Set(); + comments = []; + } + + function addComment(comment) { + comments.push(comment); + } + + function getFlameChart() { + // Make sure we unwind the measurement stack every time. + expect(activeMeasure.indent).toBe(-1); + expect(activeMeasure).toBe(root); + // We should always clean them up because browsers + // buffer user timing measurements forever. + expect(knownMarks.size).toBe(0); + expect(knownMeasures.size).toBe(0); + return root.toString(); + } + + function createUserTimingPolyfill() { + // This is not a true polyfill, but it gives us enough + // to capture measurements in a readable tree-like output. + // Reference: https://developer.mozilla.org/en-US/docs/Web/API/User_Timing_API + return { + mark(markName) { + const measure = { + children: [], + indent: activeMeasure.indent + 1, + markName: markName, + // Will be assigned on measure() call: + label: null, + parent: activeMeasure, + comments, + toString() { + return ( + [ + ...this.comments.map(c => ' '.repeat(this.indent) + '// ' + c), + ' '.repeat(this.indent) + this.label, + ...this.children.map(c => c.toString()), + ].join('\n') + + // Extra newline after each root reconciliation + (this.indent === 0 ? '\n' : '') + ); + }, + }; + comments = []; + // Step one level deeper + activeMeasure.children.push(measure); + activeMeasure = measure; + knownMarks.add(markName); + }, + // We don't use the overload with three arguments. + measure(label, markName) { + if (markName !== activeMeasure.markName) { + throw new Error('Unexpected measure() call.'); + } + // Step one level up + activeMeasure.label = label; + activeMeasure = activeMeasure.parent; + knownMeasures.add(label); + }, + clearMarks(markName) { + if (markName === activeMeasure.markName) { + // Step one level up if we're in this measure + activeMeasure = activeMeasure.parent; + activeMeasure.children.length--; + } + knownMarks.delete(markName); + }, + clearMeasures(label) { + knownMeasures.delete(label); + }, + }; + } + + beforeEach(() => { + jest.resetModules(); + resetFlamechart(); + global.performance = createUserTimingPolyfill(); + + require('shared/ReactFeatureFlags').enableUserTimingAPI = true; + + // Import after the polyfill is set up: + React = require('react'); + ReactNoop = require('react-noop-renderer'); + ReactCallReturn = require('react-call-return'); + // TODO: can we express this test with only public API? + ReactDOM = require('react-dom'); + PropTypes = require('prop-types'); + }); + + afterEach(() => { + delete global.performance; + }); + + function Parent(props) { + return
{props.children}
; + } + + function Child(props) { + return
{props.children}
; + } + + it('measures a simple reconciliation', () => { + ReactNoop.render( + + + + ); + addComment('Mount'); + ReactNoop.flush(); + + ReactNoop.render( + + + + ); + addComment('Update'); + ReactNoop.flush(); + + ReactNoop.render(null); + addComment('Unmount'); + ReactNoop.flush(); + + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('skips parents during setState', () => { + class A extends React.Component { + render() { + return
{this.props.children}
; + } + } + + class B extends React.Component { + render() { + return
{this.props.children}
; + } + } + + let a; + let b; + ReactNoop.render( + + + +
(a = inst)} /> + + + + (b = inst)} /> + + + ); + ReactNoop.flush(); + resetFlamechart(); + + a.setState({}); + b.setState({}); + addComment('Should include just A and B, no Parents'); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('warns on cascading renders from setState', () => { + class Cascading extends React.Component { + componentDidMount() { + this.setState({}); + } + render() { + return
{this.props.children}
; + } + } + + ReactNoop.render( + + + + ); + addComment('Should print a warning'); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('warns on cascading renders from top-level render', () => { + class Cascading extends React.Component { + componentDidMount() { + ReactNoop.renderToRootWithID(, 'b'); + addComment('Scheduling another root from componentDidMount'); + ReactNoop.flush(); + } + render() { + return
{this.props.children}
; + } + } + + ReactNoop.renderToRootWithID(, 'a'); + addComment('Rendering the first root'); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('does not treat setState from cWM or cWRP as cascading', () => { + class NotCascading extends React.Component { + componentWillMount() { + this.setState({}); + } + componentWillReceiveProps() { + this.setState({}); + } + render() { + return
{this.props.children}
; + } + } + + ReactNoop.render( + + + + ); + addComment('Should not print a warning'); + ReactNoop.flush(); + ReactNoop.render( + + + + ); + addComment('Should not print a warning'); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('captures all lifecycles', () => { + class AllLifecycles extends React.Component { + static childContextTypes = { + foo: PropTypes.any, + }; + shouldComponentUpdate() { + return true; + } + getChildContext() { + return { foo: 42 }; + } + componentWillMount() {} + componentDidMount() {} + componentWillReceiveProps() {} + componentWillUpdate() {} + componentDidUpdate() {} + componentWillUnmount() {} + render() { + return
; + } + } + ReactNoop.render(); + addComment('Mount'); + ReactNoop.flush(); + ReactNoop.render(); + addComment('Update'); + ReactNoop.flush(); + ReactNoop.render(null); + addComment('Unmount'); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('measures deprioritized work', () => { + addComment('Flush the parent'); + ReactNoop.flushSync(() => { + ReactNoop.render( + + + + ); + }); + addComment('Flush the child'); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('measures deferred work in chunks', () => { + class A extends React.Component { + render() { + return
{this.props.children}
; + } + } + + class B extends React.Component { + render() { + return
{this.props.children}
; + } + } + + ReactNoop.render( + +
+ + + + + + + ); + addComment('Start mounting Parent and A'); + ReactNoop.flushDeferredPri(40); + addComment('Mount B just a little (but not enough to memoize)'); + ReactNoop.flushDeferredPri(10); + addComment('Complete B and Parent'); + ReactNoop.flushDeferredPri(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('recovers from fatal errors', () => { + function Baddie() { + throw new Error('Game over'); + } + + ReactNoop.render( + + + + ); + try { + addComment('Will fatal'); + ReactNoop.flush(); + } catch (err) { + expect(err.message).toBe('Game over'); + } + ReactNoop.render( + + + + ); + addComment('Will reconcile from a clean state'); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('recovers from caught errors', () => { + function Baddie() { + throw new Error('Game over'); + } + + function ErrorReport() { + return
; + } + + class Boundary extends React.Component { + state = { error: null }; + componentDidCatch(error) { + this.setState({ error }); + } + render() { + if (this.state.error) { + return ; + } + return this.props.children; + } + } + + ReactNoop.render( + + + + + + + + ); + addComment('Stop on Baddie and restart from Boundary'); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('deduplicates lifecycle names during commit to reduce overhead', () => { + class A extends React.Component { + componentDidUpdate() {} + render() { + return
; + } + } + + class B extends React.Component { + componentDidUpdate(prevProps) { + if (this.props.cascade && !prevProps.cascade) { + this.setState({}); + } + } + render() { + return
; + } + } + + ReactNoop.render( + + + + + + + ); + ReactNoop.flush(); + resetFlamechart(); + + ReactNoop.render( + + + + + + + ); + addComment('The commit phase should mention A and B just once'); + ReactNoop.flush(); + ReactNoop.render( + + + + + + + ); + addComment("Because of deduplication, we don't know B was cascading,"); + addComment('but we should still see the warning for the commit phase.'); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('supports returns', () => { + function Continuation({ isSame }) { + return ; + } + + function CoChild({ bar }) { + return ReactCallReturn.unstable_createReturn({ + props: { + bar: bar, + }, + continuation: Continuation, + }); + } + + function Indirection() { + return [, ]; + } + + function HandleReturns(props, returns) { + return returns.map((y, i) => ); + } + + function CoParent(props) { + return ReactCallReturn.unstable_createCall(props.children, HandleReturns, props); + } + + function App() { + return ( +
+ + + +
+ ); + } + + ReactNoop.render(); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('supports portals', () => { + const noopContainer = { children: [] }; + ReactNoop.render({ReactDOM.createPortal(, noopContainer, null)}); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('does not schedule an extra callback if setState is called during a synchronous commit phase', () => { + class Component extends React.Component { + state = { step: 1 }; + componentDidMount() { + this.setState({ step: 2 }); + } + render() { + return ; + } + } + ReactNoop.flushSync(() => { + ReactNoop.render(); + }); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('warns if an in-progress update is interrupted', () => { + function Foo() { + return ; + } + + ReactNoop.render(); + ReactNoop.flushUnitsOfWork(2); + ReactNoop.flushSync(() => { + ReactNoop.render(); + }); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('warns if async work expires (starvation)', () => { + function Foo() { + return ; + } + + ReactNoop.render(); + ReactNoop.expire(5000); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); }); From a7177a92f8313913dafb4cdd54122ad480d27fed Mon Sep 17 00:00:00 2001 From: abiduzz420 Date: Thu, 30 Nov 2017 19:04:17 +0530 Subject: [PATCH 2/6] ReactPortal shifted to shared:all passed --- packages/react-dom/src/client/ReactDOM.js | 2 +- .../src/ReactNativeRenderer.js | 2 +- .../ReactIncrementalPerf-test.internal.js | 1094 +++++++++-------- .../ReactPersistent-test.internal.js | 2 +- .../react-rt-renderer/src/ReactNativeRT.js | 2 +- .../src => shared}/ReactPortal.js | 0 6 files changed, 556 insertions(+), 546 deletions(-) rename packages/{react-reconciler/src => shared}/ReactPortal.js (100%) diff --git a/packages/react-dom/src/client/ReactDOM.js b/packages/react-dom/src/client/ReactDOM.js index d257ac96798..a3639e2109e 100644 --- a/packages/react-dom/src/client/ReactDOM.js +++ b/packages/react-dom/src/client/ReactDOM.js @@ -21,7 +21,7 @@ import './ReactDOMClientInjection'; import ReactFiberReconciler from 'react-reconciler'; // TODO: direct imports like some-package/src/* are bad. Fix me. -import * as ReactPortal from 'react-reconciler/src/ReactPortal'; +import * as ReactPortal from 'shared/ReactPortal'; import ExecutionEnvironment from 'fbjs/lib/ExecutionEnvironment'; import * as ReactGenericBatching from 'events/ReactGenericBatching'; import * as ReactControlledComponent from 'events/ReactControlledComponent'; diff --git a/packages/react-native-renderer/src/ReactNativeRenderer.js b/packages/react-native-renderer/src/ReactNativeRenderer.js index 8b6dca0d551..67d8ff1e8db 100644 --- a/packages/react-native-renderer/src/ReactNativeRenderer.js +++ b/packages/react-native-renderer/src/ReactNativeRenderer.js @@ -14,7 +14,7 @@ import './ReactNativeInjection'; // TODO: direct imports like some-package/src/* are bad. Fix me. import * as ReactFiberErrorLogger from 'react-reconciler/src/ReactFiberErrorLogger'; -import * as ReactPortal from 'react-reconciler/src/ReactPortal'; +import * as ReactPortal from 'shared/ReactPortal'; import * as ReactGenericBatching from 'events/ReactGenericBatching'; import TouchHistoryMath from 'events/TouchHistoryMath'; import * as ReactGlobalSharedState from 'shared/ReactGlobalSharedState'; diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js b/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js index a342c6c9931..d3ba032bcdf 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js @@ -10,546 +10,556 @@ 'use strict'; describe('ReactDebugFiberPerf', () => { - let React; - let ReactCallReturn; - let ReactNoop; - let ReactDOM; - let PropTypes; - - let root; - let activeMeasure; - let knownMarks; - let knownMeasures; - let comments; - - function resetFlamechart() { - root = { - children: [], - indent: -1, - markName: null, - label: null, - parent: null, - toString() { - return this.children.map(c => c.toString()).join('\n'); - }, - }; - activeMeasure = root; - knownMarks = new Set(); - knownMeasures = new Set(); - comments = []; - } - - function addComment(comment) { - comments.push(comment); - } - - function getFlameChart() { - // Make sure we unwind the measurement stack every time. - expect(activeMeasure.indent).toBe(-1); - expect(activeMeasure).toBe(root); - // We should always clean them up because browsers - // buffer user timing measurements forever. - expect(knownMarks.size).toBe(0); - expect(knownMeasures.size).toBe(0); - return root.toString(); - } - - function createUserTimingPolyfill() { - // This is not a true polyfill, but it gives us enough - // to capture measurements in a readable tree-like output. - // Reference: https://developer.mozilla.org/en-US/docs/Web/API/User_Timing_API - return { - mark(markName) { - const measure = { - children: [], - indent: activeMeasure.indent + 1, - markName: markName, - // Will be assigned on measure() call: - label: null, - parent: activeMeasure, - comments, - toString() { - return ( - [ - ...this.comments.map(c => ' '.repeat(this.indent) + '// ' + c), - ' '.repeat(this.indent) + this.label, - ...this.children.map(c => c.toString()), - ].join('\n') + - // Extra newline after each root reconciliation - (this.indent === 0 ? '\n' : '') - ); - }, - }; - comments = []; - // Step one level deeper - activeMeasure.children.push(measure); - activeMeasure = measure; - knownMarks.add(markName); - }, - // We don't use the overload with three arguments. - measure(label, markName) { - if (markName !== activeMeasure.markName) { - throw new Error('Unexpected measure() call.'); - } - // Step one level up - activeMeasure.label = label; - activeMeasure = activeMeasure.parent; - knownMeasures.add(label); - }, - clearMarks(markName) { - if (markName === activeMeasure.markName) { - // Step one level up if we're in this measure - activeMeasure = activeMeasure.parent; - activeMeasure.children.length--; - } - knownMarks.delete(markName); - }, - clearMeasures(label) { - knownMeasures.delete(label); - }, - }; - } - - beforeEach(() => { - jest.resetModules(); - resetFlamechart(); - global.performance = createUserTimingPolyfill(); - - require('shared/ReactFeatureFlags').enableUserTimingAPI = true; - - // Import after the polyfill is set up: - React = require('react'); - ReactNoop = require('react-noop-renderer'); - ReactCallReturn = require('react-call-return'); - // TODO: can we express this test with only public API? - ReactDOM = require('react-dom'); - PropTypes = require('prop-types'); - }); - - afterEach(() => { - delete global.performance; - }); - - function Parent(props) { - return
{props.children}
; - } - - function Child(props) { - return
{props.children}
; - } - - it('measures a simple reconciliation', () => { - ReactNoop.render( - - - - ); - addComment('Mount'); - ReactNoop.flush(); - - ReactNoop.render( - - - - ); - addComment('Update'); - ReactNoop.flush(); - - ReactNoop.render(null); - addComment('Unmount'); - ReactNoop.flush(); - - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('skips parents during setState', () => { - class A extends React.Component { - render() { - return
{this.props.children}
; - } - } - - class B extends React.Component { - render() { - return
{this.props.children}
; - } - } - - let a; - let b; - ReactNoop.render( - - - -
(a = inst)} /> - - - - (b = inst)} /> - - - ); - ReactNoop.flush(); - resetFlamechart(); - - a.setState({}); - b.setState({}); - addComment('Should include just A and B, no Parents'); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('warns on cascading renders from setState', () => { - class Cascading extends React.Component { - componentDidMount() { - this.setState({}); - } - render() { - return
{this.props.children}
; - } - } - - ReactNoop.render( - - - - ); - addComment('Should print a warning'); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('warns on cascading renders from top-level render', () => { - class Cascading extends React.Component { - componentDidMount() { - ReactNoop.renderToRootWithID(, 'b'); - addComment('Scheduling another root from componentDidMount'); - ReactNoop.flush(); - } - render() { - return
{this.props.children}
; - } - } - - ReactNoop.renderToRootWithID(, 'a'); - addComment('Rendering the first root'); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('does not treat setState from cWM or cWRP as cascading', () => { - class NotCascading extends React.Component { - componentWillMount() { - this.setState({}); - } - componentWillReceiveProps() { - this.setState({}); - } - render() { - return
{this.props.children}
; - } - } - - ReactNoop.render( - - - - ); - addComment('Should not print a warning'); - ReactNoop.flush(); - ReactNoop.render( - - - - ); - addComment('Should not print a warning'); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('captures all lifecycles', () => { - class AllLifecycles extends React.Component { - static childContextTypes = { - foo: PropTypes.any, - }; - shouldComponentUpdate() { - return true; - } - getChildContext() { - return { foo: 42 }; - } - componentWillMount() {} - componentDidMount() {} - componentWillReceiveProps() {} - componentWillUpdate() {} - componentDidUpdate() {} - componentWillUnmount() {} - render() { - return
; - } - } - ReactNoop.render(); - addComment('Mount'); - ReactNoop.flush(); - ReactNoop.render(); - addComment('Update'); - ReactNoop.flush(); - ReactNoop.render(null); - addComment('Unmount'); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('measures deprioritized work', () => { - addComment('Flush the parent'); - ReactNoop.flushSync(() => { - ReactNoop.render( - - - - ); - }); - addComment('Flush the child'); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('measures deferred work in chunks', () => { - class A extends React.Component { - render() { - return
{this.props.children}
; - } - } - - class B extends React.Component { - render() { - return
{this.props.children}
; - } - } - - ReactNoop.render( - -
- - - - - - - ); - addComment('Start mounting Parent and A'); - ReactNoop.flushDeferredPri(40); - addComment('Mount B just a little (but not enough to memoize)'); - ReactNoop.flushDeferredPri(10); - addComment('Complete B and Parent'); - ReactNoop.flushDeferredPri(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('recovers from fatal errors', () => { - function Baddie() { - throw new Error('Game over'); - } - - ReactNoop.render( - - - - ); - try { - addComment('Will fatal'); - ReactNoop.flush(); - } catch (err) { - expect(err.message).toBe('Game over'); - } - ReactNoop.render( - - - - ); - addComment('Will reconcile from a clean state'); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('recovers from caught errors', () => { - function Baddie() { - throw new Error('Game over'); - } - - function ErrorReport() { - return
; - } - - class Boundary extends React.Component { - state = { error: null }; - componentDidCatch(error) { - this.setState({ error }); - } - render() { - if (this.state.error) { - return ; - } - return this.props.children; - } - } - - ReactNoop.render( - - - - - - - - ); - addComment('Stop on Baddie and restart from Boundary'); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('deduplicates lifecycle names during commit to reduce overhead', () => { - class A extends React.Component { - componentDidUpdate() {} - render() { - return
; - } - } - - class B extends React.Component { - componentDidUpdate(prevProps) { - if (this.props.cascade && !prevProps.cascade) { - this.setState({}); - } - } - render() { - return
; - } - } - - ReactNoop.render( - - - - - - - ); - ReactNoop.flush(); - resetFlamechart(); - - ReactNoop.render( - - - - - - - ); - addComment('The commit phase should mention A and B just once'); - ReactNoop.flush(); - ReactNoop.render( - - - - - - - ); - addComment("Because of deduplication, we don't know B was cascading,"); - addComment('but we should still see the warning for the commit phase.'); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('supports returns', () => { - function Continuation({ isSame }) { - return ; - } - - function CoChild({ bar }) { - return ReactCallReturn.unstable_createReturn({ - props: { - bar: bar, - }, - continuation: Continuation, - }); - } - - function Indirection() { - return [, ]; - } - - function HandleReturns(props, returns) { - return returns.map((y, i) => ); - } - - function CoParent(props) { - return ReactCallReturn.unstable_createCall(props.children, HandleReturns, props); - } - - function App() { - return ( -
- - - -
- ); - } - - ReactNoop.render(); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('supports portals', () => { - const noopContainer = { children: [] }; - ReactNoop.render({ReactDOM.createPortal(, noopContainer, null)}); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('does not schedule an extra callback if setState is called during a synchronous commit phase', () => { - class Component extends React.Component { - state = { step: 1 }; - componentDidMount() { - this.setState({ step: 2 }); - } - render() { - return ; - } - } - ReactNoop.flushSync(() => { - ReactNoop.render(); - }); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('warns if an in-progress update is interrupted', () => { - function Foo() { - return ; - } - - ReactNoop.render(); - ReactNoop.flushUnitsOfWork(2); - ReactNoop.flushSync(() => { - ReactNoop.render(); - }); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); - - it('warns if async work expires (starvation)', () => { - function Foo() { - return ; - } - - ReactNoop.render(); - ReactNoop.expire(5000); - ReactNoop.flush(); - expect(getFlameChart()).toMatchSnapshot(); - }); + let React; + let ReactCallReturn; + let ReactNoop; + let ReactPortal; + let PropTypes; + + let root; + let activeMeasure; + let knownMarks; + let knownMeasures; + let comments; + + function resetFlamechart() { + root = { + children: [], + indent: -1, + markName: null, + label: null, + parent: null, + toString() { + return this.children.map(c => c.toString()).join('\n'); + }, + }; + activeMeasure = root; + knownMarks = new Set(); + knownMeasures = new Set(); + comments = []; + } + + function addComment(comment) { + comments.push(comment); + } + + function getFlameChart() { + // Make sure we unwind the measurement stack every time. + expect(activeMeasure.indent).toBe(-1); + expect(activeMeasure).toBe(root); + // We should always clean them up because browsers + // buffer user timing measurements forever. + expect(knownMarks.size).toBe(0); + expect(knownMeasures.size).toBe(0); + return root.toString(); + } + + function createUserTimingPolyfill() { + // This is not a true polyfill, but it gives us enough + // to capture measurements in a readable tree-like output. + // Reference: https://developer.mozilla.org/en-US/docs/Web/API/User_Timing_API + return { + mark(markName) { + const measure = { + children: [], + indent: activeMeasure.indent + 1, + markName: markName, + // Will be assigned on measure() call: + label: null, + parent: activeMeasure, + comments, + toString() { + return ( + [ + ...this.comments.map(c => ' '.repeat(this.indent) + '// ' + c), + ' '.repeat(this.indent) + this.label, + ...this.children.map(c => c.toString()), + ].join('\n') + + // Extra newline after each root reconciliation + (this.indent === 0 ? '\n' : '') + ); + }, + }; + comments = []; + // Step one level deeper + activeMeasure.children.push(measure); + activeMeasure = measure; + knownMarks.add(markName); + }, + // We don't use the overload with three arguments. + measure(label, markName) { + if (markName !== activeMeasure.markName) { + throw new Error('Unexpected measure() call.'); + } + // Step one level up + activeMeasure.label = label; + activeMeasure = activeMeasure.parent; + knownMeasures.add(label); + }, + clearMarks(markName) { + if (markName === activeMeasure.markName) { + // Step one level up if we're in this measure + activeMeasure = activeMeasure.parent; + activeMeasure.children.length--; + } + knownMarks.delete(markName); + }, + clearMeasures(label) { + knownMeasures.delete(label); + }, + }; + } + + beforeEach(() => { + jest.resetModules(); + resetFlamechart(); + global.performance = createUserTimingPolyfill(); + + require('shared/ReactFeatureFlags').enableUserTimingAPI = true; + + // Import after the polyfill is set up: + React = require('react'); + ReactNoop = require('react-noop-renderer'); + ReactCallReturn = require('react-call-return'); + // TODO: can we express this test with only public API? + ReactPortal = require('shared/ReactPortal'); + PropTypes = require('prop-types'); + }); + + afterEach(() => { + delete global.performance; + }); + + function Parent(props) { + return
{props.children}
; + } + + function Child(props) { + return
{props.children}
; + } + + it('measures a simple reconciliation', () => { + ReactNoop.render( + + + , + ); + addComment('Mount'); + ReactNoop.flush(); + + ReactNoop.render( + + + , + ); + addComment('Update'); + ReactNoop.flush(); + + ReactNoop.render(null); + addComment('Unmount'); + ReactNoop.flush(); + + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('skips parents during setState', () => { + class A extends React.Component { + render() { + return
{this.props.children}
; + } + } + + class B extends React.Component { + render() { + return
{this.props.children}
; + } + } + + let a; + let b; + ReactNoop.render( + + + +
(a = inst)} /> + + + + (b = inst)} /> + + , + ); + ReactNoop.flush(); + resetFlamechart(); + + a.setState({}); + b.setState({}); + addComment('Should include just A and B, no Parents'); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('warns on cascading renders from setState', () => { + class Cascading extends React.Component { + componentDidMount() { + this.setState({}); + } + render() { + return
{this.props.children}
; + } + } + + ReactNoop.render( + + + , + ); + addComment('Should print a warning'); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('warns on cascading renders from top-level render', () => { + class Cascading extends React.Component { + componentDidMount() { + ReactNoop.renderToRootWithID(, 'b'); + addComment('Scheduling another root from componentDidMount'); + ReactNoop.flush(); + } + render() { + return
{this.props.children}
; + } + } + + ReactNoop.renderToRootWithID(, 'a'); + addComment('Rendering the first root'); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('does not treat setState from cWM or cWRP as cascading', () => { + class NotCascading extends React.Component { + componentWillMount() { + this.setState({}); + } + componentWillReceiveProps() { + this.setState({}); + } + render() { + return
{this.props.children}
; + } + } + + ReactNoop.render( + + + , + ); + addComment('Should not print a warning'); + ReactNoop.flush(); + ReactNoop.render( + + + , + ); + addComment('Should not print a warning'); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('captures all lifecycles', () => { + class AllLifecycles extends React.Component { + static childContextTypes = { + foo: PropTypes.any, + }; + shouldComponentUpdate() { + return true; + } + getChildContext() { + return {foo: 42}; + } + componentWillMount() {} + componentDidMount() {} + componentWillReceiveProps() {} + componentWillUpdate() {} + componentDidUpdate() {} + componentWillUnmount() {} + render() { + return
; + } + } + ReactNoop.render(); + addComment('Mount'); + ReactNoop.flush(); + ReactNoop.render(); + addComment('Update'); + ReactNoop.flush(); + ReactNoop.render(null); + addComment('Unmount'); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('measures deprioritized work', () => { + addComment('Flush the parent'); + ReactNoop.flushSync(() => { + ReactNoop.render( + + + , + ); + }); + addComment('Flush the child'); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('measures deferred work in chunks', () => { + class A extends React.Component { + render() { + return
{this.props.children}
; + } + } + + class B extends React.Component { + render() { + return
{this.props.children}
; + } + } + + ReactNoop.render( + +
+ + + + + + , + ); + addComment('Start mounting Parent and A'); + ReactNoop.flushDeferredPri(40); + addComment('Mount B just a little (but not enough to memoize)'); + ReactNoop.flushDeferredPri(10); + addComment('Complete B and Parent'); + ReactNoop.flushDeferredPri(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('recovers from fatal errors', () => { + function Baddie() { + throw new Error('Game over'); + } + + ReactNoop.render( + + + , + ); + try { + addComment('Will fatal'); + ReactNoop.flush(); + } catch (err) { + expect(err.message).toBe('Game over'); + } + ReactNoop.render( + + + , + ); + addComment('Will reconcile from a clean state'); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('recovers from caught errors', () => { + function Baddie() { + throw new Error('Game over'); + } + + function ErrorReport() { + return
; + } + + class Boundary extends React.Component { + state = {error: null}; + componentDidCatch(error) { + this.setState({error}); + } + render() { + if (this.state.error) { + return ; + } + return this.props.children; + } + } + + ReactNoop.render( + + + + + + + , + ); + addComment('Stop on Baddie and restart from Boundary'); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('deduplicates lifecycle names during commit to reduce overhead', () => { + class A extends React.Component { + componentDidUpdate() {} + render() { + return
; + } + } + + class B extends React.Component { + componentDidUpdate(prevProps) { + if (this.props.cascade && !prevProps.cascade) { + this.setState({}); + } + } + render() { + return
; + } + } + + ReactNoop.render( + + + + + + , + ); + ReactNoop.flush(); + resetFlamechart(); + + ReactNoop.render( + + + + + + , + ); + addComment('The commit phase should mention A and B just once'); + ReactNoop.flush(); + ReactNoop.render( + + + + + + , + ); + addComment("Because of deduplication, we don't know B was cascading,"); + addComment('but we should still see the warning for the commit phase.'); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('supports returns', () => { + function Continuation({isSame}) { + return ; + } + + function CoChild({bar}) { + return ReactCallReturn.unstable_createReturn({ + props: { + bar: bar, + }, + continuation: Continuation, + }); + } + + function Indirection() { + return [, ]; + } + + function HandleReturns(props, returns) { + return returns.map((y, i) => ( + + )); + } + + function CoParent(props) { + return ReactCallReturn.unstable_createCall( + props.children, + HandleReturns, + props, + ); + } + + function App() { + return ( +
+ + + +
+ ); + } + + ReactNoop.render(); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('supports portals', () => { + const noopContainer = {children: []}; + ReactNoop.render( + + {ReactPortal.createPortal(, noopContainer, null)} + , + ); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('does not schedule an extra callback if setState is called during a synchronous commit phase', () => { + class Component extends React.Component { + state = {step: 1}; + componentDidMount() { + this.setState({step: 2}); + } + render() { + return ; + } + } + ReactNoop.flushSync(() => { + ReactNoop.render(); + }); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('warns if an in-progress update is interrupted', () => { + function Foo() { + return ; + } + + ReactNoop.render(); + ReactNoop.flushUnitsOfWork(2); + ReactNoop.flushSync(() => { + ReactNoop.render(); + }); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); + + it('warns if async work expires (starvation)', () => { + function Foo() { + return ; + } + + ReactNoop.render(); + ReactNoop.expire(5000); + ReactNoop.flush(); + expect(getFlameChart()).toMatchSnapshot(); + }); }); diff --git a/packages/react-reconciler/src/__tests__/ReactPersistent-test.internal.js b/packages/react-reconciler/src/__tests__/ReactPersistent-test.internal.js index 48e7b646ff9..bba8cde849b 100644 --- a/packages/react-reconciler/src/__tests__/ReactPersistent-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactPersistent-test.internal.js @@ -24,7 +24,7 @@ describe('ReactPersistent', () => { React = require('react'); ReactNoop = require('react-noop-renderer'); - ReactPortal = require('../ReactPortal'); + ReactPortal = require('shared/ReactPortal'); }); const DEFAULT_ROOT_ID = 'persistent-test'; diff --git a/packages/react-rt-renderer/src/ReactNativeRT.js b/packages/react-rt-renderer/src/ReactNativeRT.js index 996e2ba147d..9cd67da903a 100644 --- a/packages/react-rt-renderer/src/ReactNativeRT.js +++ b/packages/react-rt-renderer/src/ReactNativeRT.js @@ -22,7 +22,7 @@ import './ReactNativeRTEventEmitter'; // TODO: direct imports like some-package/src/* are bad. Fix me. import * as ReactFiberErrorLogger from 'react-reconciler/src/ReactFiberErrorLogger'; import {showDialog} from 'react-native-renderer/src/ReactNativeFiberErrorDialog'; -import * as ReactPortal from 'react-reconciler/src/ReactPortal'; +import * as ReactPortal from 'shared/ReactPortal'; import * as ReactGenericBatching from 'events/ReactGenericBatching'; import ReactVersion from 'shared/ReactVersion'; diff --git a/packages/react-reconciler/src/ReactPortal.js b/packages/shared/ReactPortal.js similarity index 100% rename from packages/react-reconciler/src/ReactPortal.js rename to packages/shared/ReactPortal.js From 77ac389e1de7fb1933f0cf20283bbf65e5ad3043 Mon Sep 17 00:00:00 2001 From: abiduzz420 Date: Thu, 30 Nov 2017 20:59:50 +0530 Subject: [PATCH 3/6] wrote createPortal method for ReactNoop.(#11299) --- .../src/ReactNativeRenderer.js | 14 +-- .../ReactNativeEvents-test.internal.js | 95 ++++++++++--------- .../ReactNativeMount-test.internal.js | 20 ++-- packages/react-noop-renderer/src/ReactNoop.js | 79 ++++++++------- .../ReactPersistent-test.internal.js | 16 ++-- .../react-rt-renderer/src/ReactNativeRT.js | 12 +-- packages/shared/ReactPortal.js | 6 +- packages/shared/ReactTypes.js | 6 +- packages/shared/reactProdInvariant.js | 2 +- 9 files changed, 131 insertions(+), 119 deletions(-) diff --git a/packages/react-native-renderer/src/ReactNativeRenderer.js b/packages/react-native-renderer/src/ReactNativeRenderer.js index 67d8ff1e8db..39efe5357dd 100644 --- a/packages/react-native-renderer/src/ReactNativeRenderer.js +++ b/packages/react-native-renderer/src/ReactNativeRenderer.js @@ -7,8 +7,8 @@ * @flow */ -import type {ReactNativeType} from './ReactNativeTypes'; -import type {ReactNodeList} from 'shared/ReactTypes'; +import type { ReactNativeType } from './ReactNativeTypes'; +import type { ReactNodeList } from 'shared/ReactTypes'; import './ReactNativeInjection'; @@ -22,20 +22,20 @@ import ReactVersion from 'shared/ReactVersion'; // Module provided by RN: import UIManager from 'UIManager'; -import {showDialog} from './ReactNativeFiberErrorDialog'; +import { showDialog } from './ReactNativeFiberErrorDialog'; import NativeMethodsMixin from './NativeMethodsMixin'; import ReactNativeBridgeEventPlugin from './ReactNativeBridgeEventPlugin'; import ReactNativeComponent from './ReactNativeComponent'; import * as ReactNativeComponentTree from './ReactNativeComponentTree'; import ReactNativeFiberRenderer from './ReactNativeFiberRenderer'; import ReactNativePropRegistry from './ReactNativePropRegistry'; -import {getInspectorDataForViewTag} from './ReactNativeFiberInspector'; +import { getInspectorDataForViewTag } from './ReactNativeFiberInspector'; import createReactNativeComponentClass from './createReactNativeComponentClass'; import findNumericNodeHandle from './findNumericNodeHandle'; import takeSnapshot from './takeSnapshot'; ReactGenericBatching.injection.injectFiberBatchedUpdates( - ReactNativeFiberRenderer.batchedUpdates, + ReactNativeFiberRenderer.batchedUpdates ); const roots = new Map(); @@ -83,7 +83,7 @@ const ReactNativeRenderer: ReactNativeType = { createPortal( children: ReactNodeList, containerTag: number, - key: ?string = null, + key: ?string = null ) { return ReactPortal.createPortal(children, containerTag, null, key); }, @@ -124,7 +124,7 @@ if (__DEV__) { printInclusive() {}, printWasted() {}, }, - }, + } ); } diff --git a/packages/react-native-renderer/src/__tests__/ReactNativeEvents-test.internal.js b/packages/react-native-renderer/src/__tests__/ReactNativeEvents-test.internal.js index 3ff818a2550..91fe2eb2e08 100644 --- a/packages/react-native-renderer/src/__tests__/ReactNativeEvents-test.internal.js +++ b/packages/react-native-renderer/src/__tests__/ReactNativeEvents-test.internal.js @@ -92,8 +92,8 @@ it('fails if unknown/unsupported event types are dispatched', () => { expect(() => { EventEmitter.receiveTouches( 'unspecifiedEvent', - [{target, identifier: 17}], - [0], + [{ target, identifier: 17 }], + [0] ); }).toThrow('Unsupported top level event type "unspecifiedEvent" dispatched'); }); @@ -101,7 +101,7 @@ it('fails if unknown/unsupported event types are dispatched', () => { it('handles events', () => { expect(RCTEventEmitter.register.mock.calls.length).toBe(1); var EventEmitter = RCTEventEmitter.register.mock.calls[0][0]; - var View = fakeRequireNativeComponent('View', {foo: true}); + var View = fakeRequireNativeComponent('View', { foo: true }); var log = []; ReactNative.render( @@ -110,7 +110,8 @@ it('handles events', () => { onTouchEnd={() => log.push('outer touchend')} onTouchEndCapture={() => log.push('outer touchend capture')} onTouchStart={() => log.push('outer touchstart')} - onTouchStartCapture={() => log.push('outer touchstart capture')}> + onTouchStartCapture={() => log.push('outer touchstart capture')} + > log.push('inner touchend capture')} @@ -119,7 +120,7 @@ it('handles events', () => { onTouchStart={() => log.push('inner touchstart')} /> , - 1, + 1 ); expect(UIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot(); @@ -128,18 +129,18 @@ it('handles events', () => { // Don't depend on the order of createView() calls. // Stack creates views outside-in; fiber creates them inside-out. var innerTag = UIManager.createView.mock.calls.find( - args => args[3].foo === 'inner', + args => args[3].foo === 'inner' )[0]; EventEmitter.receiveTouches( 'topTouchStart', - [{target: innerTag, identifier: 17}], - [0], + [{ target: innerTag, identifier: 17 }], + [0] ); EventEmitter.receiveTouches( 'topTouchEnd', - [{target: innerTag, identifier: 17}], - [0], + [{ target: innerTag, identifier: 17 }], + [0] ); expect(log).toEqual([ @@ -160,9 +161,9 @@ it('handles events on text nodes', () => { var Text = fakeRequireNativeComponent('Text', {}); class ContextHack extends React.Component { - static childContextTypes = {isInAParentText: PropTypes.bool}; + static childContextTypes = { isInAParentText: PropTypes.bool }; getChildContext() { - return {isInAParentText: true}; + return { isInAParentText: true }; } render() { return this.props.children; @@ -177,19 +178,21 @@ it('handles events on text nodes', () => { onTouchEnd={() => log.push('string touchend')} onTouchEndCapture={() => log.push('string touchend capture')} onTouchStart={() => log.push('string touchstart')} - onTouchStartCapture={() => log.push('string touchstart capture')}> + onTouchStartCapture={() => log.push('string touchstart capture')} + > Text Content log.push('number touchend')} onTouchEndCapture={() => log.push('number touchend capture')} onTouchStart={() => log.push('number touchstart')} - onTouchStartCapture={() => log.push('number touchstart capture')}> + onTouchStartCapture={() => log.push('number touchstart capture')} + > {123} , - 1, + 1 ); expect(UIManager.createView.mock.calls.length).toBe(5); @@ -197,32 +200,32 @@ it('handles events on text nodes', () => { // Don't depend on the order of createView() calls. // Stack creates views outside-in; fiber creates them inside-out. var innerTagString = UIManager.createView.mock.calls.find( - args => args[3] && args[3].text === 'Text Content', + args => args[3] && args[3].text === 'Text Content' )[0]; var innerTagNumber = UIManager.createView.mock.calls.find( - args => args[3] && args[3].text === '123', + args => args[3] && args[3].text === '123' )[0]; EventEmitter.receiveTouches( 'topTouchStart', - [{target: innerTagString, identifier: 17}], - [0], + [{ target: innerTagString, identifier: 17 }], + [0] ); EventEmitter.receiveTouches( 'topTouchEnd', - [{target: innerTagString, identifier: 17}], - [0], + [{ target: innerTagString, identifier: 17 }], + [0] ); EventEmitter.receiveTouches( 'topTouchStart', - [{target: innerTagNumber, identifier: 18}], - [0], + [{ target: innerTagNumber, identifier: 18 }], + [0] ); EventEmitter.receiveTouches( 'topTouchEnd', - [{target: innerTagNumber, identifier: 18}], - [0], + [{ target: innerTagNumber, identifier: 18 }], + [0] ); expect(log).toEqual([ @@ -239,11 +242,11 @@ it('handles events on text nodes', () => { it('handles when a responder is unmounted while a touch sequence is in progress', () => { var EventEmitter = RCTEventEmitter.register.mock.calls[0][0]; - var View = fakeRequireNativeComponent('View', {id: true}); + var View = fakeRequireNativeComponent('View', { id: true }); function getViewById(id) { return UIManager.createView.mock.calls.find( - args => args[3] && args[3].id === id, + args => args[3] && args[3].id === id )[0]; } @@ -276,13 +279,13 @@ it('handles when a responder is unmounted while a touch sequence is in progress' /> , - 1, + 1 ); EventEmitter.receiveTouches( 'topTouchStart', - [{target: getViewById('one'), identifier: 17}], - [0], + [{ target: getViewById('one'), identifier: 17 }], + [0] ); expect(getResponderId()).toBe('one'); @@ -300,7 +303,7 @@ it('handles when a responder is unmounted while a touch sequence is in progress' /> , - 1, + 1 ); // TODO Verify the onResponderEnd listener has been called (before the unmount) @@ -309,8 +312,8 @@ it('handles when a responder is unmounted while a touch sequence is in progress' EventEmitter.receiveTouches( 'topTouchEnd', - [{target: getViewById('two'), identifier: 17}], - [0], + [{ target: getViewById('two'), identifier: 17 }], + [0] ); expect(getResponderId()).toBeNull(); @@ -318,8 +321,8 @@ it('handles when a responder is unmounted while a touch sequence is in progress' EventEmitter.receiveTouches( 'topTouchStart', - [{target: getViewById('two'), identifier: 17}], - [0], + [{ target: getViewById('two'), identifier: 17 }], + [0] ); expect(getResponderId()).toBe('two'); @@ -329,11 +332,11 @@ it('handles when a responder is unmounted while a touch sequence is in progress' it('handles events without target', () => { var EventEmitter = RCTEventEmitter.register.mock.calls[0][0]; - var View = fakeRequireNativeComponent('View', {id: true}); + var View = fakeRequireNativeComponent('View', { id: true }); function getViewById(id) { return UIManager.createView.mock.calls.find( - args => args[3] && args[3].id === id, + args => args[3] && args[3].id === id )[0]; } @@ -370,7 +373,7 @@ it('handles events without target', () => { /> , - 1, + 1 ); } @@ -378,8 +381,8 @@ it('handles events without target', () => { EventEmitter.receiveTouches( 'topTouchStart', - [{target: getViewById('one'), identifier: 17}], - [0], + [{ target: getViewById('one'), identifier: 17 }], + [0] ); // Unmounting component 'one'. @@ -387,24 +390,24 @@ it('handles events without target', () => { EventEmitter.receiveTouches( 'topTouchEnd', - [{target: getViewById('one'), identifier: 17}], - [0], + [{ target: getViewById('one'), identifier: 17 }], + [0] ); expect(getResponderId()).toBe(null); EventEmitter.receiveTouches( 'topTouchStart', - [{target: getViewById('two'), identifier: 18}], - [0], + [{ target: getViewById('two'), identifier: 18 }], + [0] ); expect(getResponderId()).toBe('two'); EventEmitter.receiveTouches( 'topTouchEnd', - [{target: getViewById('two'), identifier: 18}], - [0], + [{ target: getViewById('two'), identifier: 18 }], + [0] ); expect(getResponderId()).toBe(null); diff --git a/packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js b/packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js index aded93a90ee..2701e066583 100644 --- a/packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js +++ b/packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js @@ -27,7 +27,7 @@ describe('ReactNative', () => { it('should be able to create and render a native component', () => { var View = createReactNativeComponentClass('View', () => ({ - validAttributes: {foo: true}, + validAttributes: { foo: true }, uiViewClassName: 'View', })); @@ -40,7 +40,7 @@ describe('ReactNative', () => { it('should be able to create and update a native component', () => { var View = createReactNativeComponentClass('View', () => ({ - validAttributes: {foo: true}, + validAttributes: { foo: true }, uiViewClassName: 'View', })); @@ -56,12 +56,12 @@ describe('ReactNative', () => { expect(UIManager.createView.mock.calls.length).toBe(1); expect(UIManager.setChildren.mock.calls.length).toBe(1); expect(UIManager.manageChildren).not.toBeCalled(); - expect(UIManager.updateView).toBeCalledWith(2, 'View', {foo: 'bar'}); + expect(UIManager.updateView).toBeCalledWith(2, 'View', { foo: 'bar' }); }); it('should not call UIManager.updateView after render for properties that have not changed', () => { const Text = createReactNativeComponentClass('Text', () => ({ - validAttributes: {foo: true}, + validAttributes: { foo: true }, uiViewClassName: 'Text', })); @@ -87,7 +87,7 @@ describe('ReactNative', () => { it('should not call UIManager.updateView from setNativeProps for properties that have not changed', () => { const View = createReactNativeComponentClass('View', () => ({ - validAttributes: {foo: true}, + validAttributes: { foo: true }, uiViewClassName: 'View', })); @@ -108,21 +108,21 @@ describe('ReactNative', () => { viewRef = ref; }} />, - 11, + 11 ); expect(UIManager.updateView).not.toBeCalled(); viewRef.setNativeProps({}); expect(UIManager.updateView).not.toBeCalled(); - viewRef.setNativeProps({foo: 'baz'}); + viewRef.setNativeProps({ foo: 'baz' }); expect(UIManager.updateView.mock.calls.length).toBe(1); }); }); it('returns the correct instance and calls it in the callback', () => { var View = createReactNativeComponentClass('View', () => ({ - validAttributes: {foo: true}, + validAttributes: { foo: true }, uiViewClassName: 'View', })); @@ -133,7 +133,7 @@ describe('ReactNative', () => { 11, function() { b = this; - }, + } ); expect(a).toBeTruthy(); @@ -143,7 +143,7 @@ describe('ReactNative', () => { it('renders and reorders children', () => { var View = createReactNativeComponentClass('View', () => ({ - validAttributes: {title: true}, + validAttributes: { title: true }, uiViewClassName: 'View', })); diff --git a/packages/react-noop-renderer/src/ReactNoop.js b/packages/react-noop-renderer/src/ReactNoop.js index f472da3a975..96e775d22f0 100644 --- a/packages/react-noop-renderer/src/ReactNoop.js +++ b/packages/react-noop-renderer/src/ReactNoop.js @@ -14,12 +14,13 @@ * environment. */ -import type {Fiber} from 'react-reconciler/src/ReactFiber'; -import type {UpdateQueue} from 'react-reconciler/src/ReactFiberUpdateQueue'; +import type { Fiber } from 'react-reconciler/src/ReactFiber'; +import type { UpdateQueue } from 'react-reconciler/src/ReactFiberUpdateQueue'; import ReactFiberReconciler from 'react-reconciler'; -import {enablePersistentReconciler} from 'shared/ReactFeatureFlags'; +import { enablePersistentReconciler } from 'shared/ReactFeatureFlags'; import * as ReactInstanceMap from 'shared/ReactInstanceMap'; +import * as ReactPortal from 'shared/ReactPortal'; import emptyObject from 'fbjs/lib/emptyObject'; import expect from 'expect'; @@ -27,15 +28,15 @@ const UPDATE_SIGNAL = {}; var scheduledCallback = null; -type Container = {rootID: string, children: Array}; -type Props = {prop: any, hidden?: boolean}; +type Container = { rootID: string, children: Array }; +type Props = { prop: any, hidden?: boolean }; type Instance = {| type: string, id: number, children: Array, - prop: any, + prop: any |}; -type TextInstance = {|text: string, id: number|}; +type TextInstance = {| text: string, id: number |}; var instanceCounter = 0; @@ -43,7 +44,7 @@ var failInBeginPhase = false; function appendChild( parentInstance: Instance | Container, - child: Instance | TextInstance, + child: Instance | TextInstance ): void { const index = parentInstance.children.indexOf(child); if (index !== -1) { @@ -55,7 +56,7 @@ function appendChild( function insertBefore( parentInstance: Instance | Container, child: Instance | TextInstance, - beforeChild: Instance | TextInstance, + beforeChild: Instance | TextInstance ): void { const index = parentInstance.children.indexOf(child); if (index !== -1) { @@ -70,7 +71,7 @@ function insertBefore( function removeChild( parentInstance: Instance | Container, - child: Instance | TextInstance, + child: Instance | TextInstance ): void { const index = parentInstance.children.indexOf(child); if (index === -1) { @@ -105,13 +106,13 @@ var SharedHostConfig = { prop: props.prop, }; // Hide from unit tests - Object.defineProperty(inst, 'id', {value: inst.id, enumerable: false}); + Object.defineProperty(inst, 'id', { value: inst.id, enumerable: false }); return inst; }, appendInitialChild( parentInstance: Instance, - child: Instance | TextInstance, + child: Instance | TextInstance ): void { parentInstance.children.push(child); }, @@ -119,7 +120,7 @@ var SharedHostConfig = { finalizeInitialChildren( domElement: Instance, type: string, - props: Props, + props: Props ): boolean { return false; }, @@ -128,7 +129,7 @@ var SharedHostConfig = { instance: Instance, type: string, oldProps: Props, - newProps: Props, + newProps: Props ): null | {} { return UPDATE_SIGNAL; }, @@ -147,11 +148,11 @@ var SharedHostConfig = { text: string, rootContainerInstance: Container, hostContext: Object, - internalInstanceHandle: Object, + internalInstanceHandle: Object ): TextInstance { - var inst = {text: text, id: instanceCounter++}; + var inst = { text: text, id: instanceCounter++ }; // Hide from unit tests - Object.defineProperty(inst, 'id', {value: inst.id, enumerable: false}); + Object.defineProperty(inst, 'id', { value: inst.id, enumerable: false }); return inst; }, @@ -159,7 +160,7 @@ var SharedHostConfig = { if (scheduledCallback) { throw new Error( 'Scheduling a callback twice is excessive. Instead, keep track of ' + - 'whether the callback has already been scheduled.', + 'whether the callback has already been scheduled.' ); } scheduledCallback = callback; @@ -194,7 +195,7 @@ var NoopRenderer = ReactFiberReconciler({ updatePayload: Object, type: string, oldProps: Props, - newProps: Props, + newProps: Props ): void { instance.prop = newProps.prop; }, @@ -202,7 +203,7 @@ var NoopRenderer = ReactFiberReconciler({ commitTextUpdate( textInstance: TextInstance, oldText: string, - newText: string, + newText: string ): void { textInstance.text = newText; }, @@ -230,7 +231,7 @@ var PersistentNoopRenderer = enablePersistentReconciler newProps: Props, internalInstanceHandle: Object, keepChildren: boolean, - recyclableInstance: null | Instance, + recyclableInstance: null | Instance ): Instance { const clone = { id: instance.id, @@ -246,26 +247,26 @@ var PersistentNoopRenderer = enablePersistentReconciler }, createContainerChildSet( - container: Container, + container: Container ): Array { return []; }, appendChildToContainerChildSet( childSet: Array, - child: Instance | TextInstance, + child: Instance | TextInstance ): void { childSet.push(child); }, finalizeContainerChildren( container: Container, - newChildren: Array, + newChildren: Array ): void {}, replaceContainerChildren( container: Container, - newChildren: Array, + newChildren: Array ): void { container.children = newChildren; }, @@ -318,6 +319,14 @@ var ReactNoop = { } }, + createPortal( + children: ReactNodeList, + container: Container, + key: ?string = null + ) { + return ReactPortal.createPortal(children, container, null, key); + }, + // Shortcut for testing a single root render(element: React$Element, callback: ?Function) { ReactNoop.renderToRootWithID(element, DEFAULT_ROOT_ID, callback); @@ -326,11 +335,11 @@ var ReactNoop = { renderToRootWithID( element: React$Element, rootID: string, - callback: ?Function, + callback: ?Function ) { let root = roots.get(rootID); if (!root) { - const container = {rootID: rootID, children: []}; + const container = { rootID: rootID, children: [] }; rootContainers.set(rootID, container); root = NoopRenderer.createContainer(container, false); roots.set(rootID, root); @@ -341,16 +350,16 @@ var ReactNoop = { renderToPersistentRootWithID( element: React$Element, rootID: string, - callback: ?Function, + callback: ?Function ) { if (PersistentNoopRenderer === null) { throw new Error( - 'Enable ReactFeatureFlags.enablePersistentReconciler to use it in tests.', + 'Enable ReactFeatureFlags.enablePersistentReconciler to use it in tests.' ); } let root = persistentRoots.get(rootID); if (!root) { - const container = {rootID: rootID, children: []}; + const container = { rootID: rootID, children: [] }; rootContainers.set(rootID, container); root = PersistentNoopRenderer.createContainer(container, false); persistentRoots.set(rootID, root); @@ -369,7 +378,7 @@ var ReactNoop = { }, findInstance( - componentOrElement: Element | ?React$Component, + componentOrElement: Element | ?React$Component ): null | Instance | TextInstance { if (componentOrElement == null) { return null; @@ -401,7 +410,7 @@ var ReactNoop = { }, flushAndYield( - unitsOfWork: number = Infinity, + unitsOfWork: number = Infinity ): Generator, void, void> { return flushUnitsOfWork(unitsOfWork); }, @@ -503,7 +512,7 @@ var ReactNoop = { ' '.repeat(depth + 1) + '~', firstUpdate && firstUpdate.partialState, firstUpdate.callback ? 'with callback' : '', - '[' + firstUpdate.expirationTime + ']', + '[' + firstUpdate.expirationTime + ']' ); var next; while ((next = firstUpdate.next)) { @@ -511,7 +520,7 @@ var ReactNoop = { ' '.repeat(depth + 1) + '~', next.partialState, next.callback ? 'with callback' : '', - '[' + firstUpdate.expirationTime + ']', + '[' + firstUpdate.expirationTime + ']' ); } } @@ -522,7 +531,7 @@ var ReactNoop = { '- ' + // need to explicitly coerce Symbol to a string (fiber.type ? fiber.type.name || fiber.type.toString() : '[root]'), - '[' + fiber.expirationTime + (fiber.pendingProps ? '*' : '') + ']', + '[' + fiber.expirationTime + (fiber.pendingProps ? '*' : '') + ']' ); if (fiber.updateQueue) { logUpdateQueue(fiber.updateQueue, depth); diff --git a/packages/react-reconciler/src/__tests__/ReactPersistent-test.internal.js b/packages/react-reconciler/src/__tests__/ReactPersistent-test.internal.js index bba8cde849b..a6bd9687044 100644 --- a/packages/react-reconciler/src/__tests__/ReactPersistent-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactPersistent-test.internal.js @@ -34,12 +34,12 @@ describe('ReactPersistent', () => { } function div(...children) { - children = children.map(c => (typeof c === 'string' ? {text: c} : c)); - return {type: 'div', children, prop: undefined}; + children = children.map(c => (typeof c === 'string' ? { text: c } : c)); + return { type: 'div', children, prop: undefined }; } function span(prop) { - return {type: 'span', children: [], prop}; + return { type: 'span', children: [], prop }; } function getChildren() { @@ -159,12 +159,12 @@ describe('ReactPersistent', () => {
); } - const portalContainer = {rootID: 'persistent-portal-test', children: []}; + const portalContainer = { rootID: 'persistent-portal-test', children: [] }; const emptyPortalChildSet = portalContainer.children; render( {ReactPortal.createPortal(, portalContainer, null)} - , + ); ReactNoop.flush(); @@ -180,9 +180,9 @@ describe('ReactPersistent', () => { {ReactPortal.createPortal( Hello {'World'}, portalContainer, - null, + null )} - , + ); ReactNoop.flush(); @@ -196,7 +196,7 @@ describe('ReactPersistent', () => { // Reused portal children should have reference equality expect(newPortalChildren[0].children[0]).toBe( - originalPortalChildren[0].children[0], + originalPortalChildren[0].children[0] ); // Deleting the Portal, should clear its children diff --git a/packages/react-rt-renderer/src/ReactNativeRT.js b/packages/react-rt-renderer/src/ReactNativeRT.js index 9cd67da903a..ad188e42f52 100644 --- a/packages/react-rt-renderer/src/ReactNativeRT.js +++ b/packages/react-rt-renderer/src/ReactNativeRT.js @@ -7,8 +7,8 @@ * @flow */ -import type {ReactNativeRTType} from './ReactNativeRTTypes'; -import type {ReactNodeList} from 'shared/ReactTypes'; +import type { ReactNativeRTType } from './ReactNativeRTTypes'; +import type { ReactNodeList } from 'shared/ReactTypes'; /** * Make sure essential globals are available and are patched correctly. Please don't remove this @@ -21,17 +21,17 @@ import './ReactNativeRTEventEmitter'; // TODO: direct imports like some-package/src/* are bad. Fix me. import * as ReactFiberErrorLogger from 'react-reconciler/src/ReactFiberErrorLogger'; -import {showDialog} from 'react-native-renderer/src/ReactNativeFiberErrorDialog'; +import { showDialog } from 'react-native-renderer/src/ReactNativeFiberErrorDialog'; import * as ReactPortal from 'shared/ReactPortal'; import * as ReactGenericBatching from 'events/ReactGenericBatching'; import ReactVersion from 'shared/ReactVersion'; -import {getFiberFromTag} from './ReactNativeRTComponentTree'; +import { getFiberFromTag } from './ReactNativeRTComponentTree'; import ReactNativeRTFiberRenderer from './ReactNativeRTFiberRenderer'; import ReactNativeRTFiberInspector from './ReactNativeRTFiberInspector'; ReactGenericBatching.injection.injectFiberBatchedUpdates( - ReactNativeRTFiberRenderer.batchedUpdates, + ReactNativeRTFiberRenderer.batchedUpdates ); const roots = new Map(); @@ -68,7 +68,7 @@ const ReactNativeRTFiber: ReactNativeRTType = { createPortal( children: ReactNodeList, containerTag: number, - key: ?string = null, + key: ?string = null ) { return ReactPortal.createPortal(children, containerTag, null, key); }, diff --git a/packages/shared/ReactPortal.js b/packages/shared/ReactPortal.js index c20459c4b62..09ff27db395 100644 --- a/packages/shared/ReactPortal.js +++ b/packages/shared/ReactPortal.js @@ -7,16 +7,16 @@ * @flow */ -import {REACT_PORTAL_TYPE} from 'shared/ReactSymbols'; +import { REACT_PORTAL_TYPE } from 'shared/ReactSymbols'; -import type {ReactNodeList, ReactPortal} from 'shared/ReactTypes'; +import type { ReactNodeList, ReactPortal } from 'shared/ReactTypes'; export function createPortal( children: ReactNodeList, containerInfo: any, // TODO: figure out the API for cross-renderer implementation. implementation: any, - key: ?string = null, + key: ?string = null ): ReactPortal { return { // This tag allow us to uniquely identify this as a React Portal diff --git a/packages/shared/ReactTypes.js b/packages/shared/ReactTypes.js index 900582e5d5a..30b6e2ad398 100644 --- a/packages/shared/ReactTypes.js +++ b/packages/shared/ReactTypes.js @@ -30,12 +30,12 @@ export type ReactCall = { children: any, // This should be a more specific CallHandler handler: (props: any, returns: Array) => ReactNodeList, - props: any, + props: any }; export type ReactReturn = { $$typeof: Symbol | number, - value: mixed, + value: mixed }; export type ReactPortal = { @@ -44,5 +44,5 @@ export type ReactPortal = { containerInfo: any, children: ReactNodeList, // TODO: figure out the API for cross-renderer implementation. - implementation: any, + implementation: any }; diff --git a/packages/shared/reactProdInvariant.js b/packages/shared/reactProdInvariant.js index e9d63051fcc..8d6f62cb6d3 100644 --- a/packages/shared/reactProdInvariant.js +++ b/packages/shared/reactProdInvariant.js @@ -31,7 +31,7 @@ function reactProdInvariant(code: string): void { ' for the full message or use the non-minified dev environment' + ' for full errors and additional helpful warnings.'; - var error: Error & {framesToPop?: number} = new Error(message); + var error: Error & { framesToPop?: number } = new Error(message); error.name = 'Invariant Violation'; error.framesToPop = 1; // we don't care about reactProdInvariant's own frame From df77730f56e11356e2eaecfc6debd57fa23dc0ab Mon Sep 17 00:00:00 2001 From: abiduzz420 Date: Thu, 30 Nov 2017 21:04:26 +0530 Subject: [PATCH 4/6] imported ReactNodeList type into ReactNoop.(#11299) --- packages/react-noop-renderer/src/ReactNoop.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-noop-renderer/src/ReactNoop.js b/packages/react-noop-renderer/src/ReactNoop.js index 96e775d22f0..2b5310b260b 100644 --- a/packages/react-noop-renderer/src/ReactNoop.js +++ b/packages/react-noop-renderer/src/ReactNoop.js @@ -16,7 +16,7 @@ import type { Fiber } from 'react-reconciler/src/ReactFiber'; import type { UpdateQueue } from 'react-reconciler/src/ReactFiberUpdateQueue'; - +import type { ReactNodeList } from 'shared/ReactTypes'; import ReactFiberReconciler from 'react-reconciler'; import { enablePersistentReconciler } from 'shared/ReactFeatureFlags'; import * as ReactInstanceMap from 'shared/ReactInstanceMap'; From 1042be9d6983305d1fc2a536fd1e461b0b6d052a Mon Sep 17 00:00:00 2001 From: abiduzz420 Date: Thu, 30 Nov 2017 22:54:56 +0530 Subject: [PATCH 5/6] createPortal method implemented.(#11299) --- .../ReactIncrementalPerf-test.internal.js | 53 +++++++++---------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js b/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js index d3ba032bcdf..a53e036de25 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js @@ -13,7 +13,6 @@ describe('ReactDebugFiberPerf', () => { let React; let ReactCallReturn; let ReactNoop; - let ReactPortal; let PropTypes; let root; @@ -121,8 +120,6 @@ describe('ReactDebugFiberPerf', () => { React = require('react'); ReactNoop = require('react-noop-renderer'); ReactCallReturn = require('react-call-return'); - // TODO: can we express this test with only public API? - ReactPortal = require('shared/ReactPortal'); PropTypes = require('prop-types'); }); @@ -142,7 +139,7 @@ describe('ReactDebugFiberPerf', () => { ReactNoop.render( - , + ); addComment('Mount'); ReactNoop.flush(); @@ -150,7 +147,7 @@ describe('ReactDebugFiberPerf', () => { ReactNoop.render( - , + ); addComment('Update'); ReactNoop.flush(); @@ -187,7 +184,7 @@ describe('ReactDebugFiberPerf', () => { (b = inst)} /> - , + ); ReactNoop.flush(); resetFlamechart(); @@ -212,7 +209,7 @@ describe('ReactDebugFiberPerf', () => { ReactNoop.render( - , + ); addComment('Should print a warning'); ReactNoop.flush(); @@ -253,14 +250,14 @@ describe('ReactDebugFiberPerf', () => { ReactNoop.render( - , + ); addComment('Should not print a warning'); ReactNoop.flush(); ReactNoop.render( - , + ); addComment('Should not print a warning'); ReactNoop.flush(); @@ -276,7 +273,7 @@ describe('ReactDebugFiberPerf', () => { return true; } getChildContext() { - return {foo: 42}; + return { foo: 42 }; } componentWillMount() {} componentDidMount() {} @@ -308,7 +305,7 @@ describe('ReactDebugFiberPerf', () => { - , + ); }); addComment('Flush the child'); @@ -337,7 +334,7 @@ describe('ReactDebugFiberPerf', () => { - , + ); addComment('Start mounting Parent and A'); ReactNoop.flushDeferredPri(40); @@ -356,7 +353,7 @@ describe('ReactDebugFiberPerf', () => { ReactNoop.render( - , + ); try { addComment('Will fatal'); @@ -367,7 +364,7 @@ describe('ReactDebugFiberPerf', () => { ReactNoop.render( - , + ); addComment('Will reconcile from a clean state'); ReactNoop.flush(); @@ -384,9 +381,9 @@ describe('ReactDebugFiberPerf', () => { } class Boundary extends React.Component { - state = {error: null}; + state = { error: null }; componentDidCatch(error) { - this.setState({error}); + this.setState({ error }); } render() { if (this.state.error) { @@ -403,7 +400,7 @@ describe('ReactDebugFiberPerf', () => { - , + ); addComment('Stop on Baddie and restart from Boundary'); ReactNoop.flush(); @@ -435,7 +432,7 @@ describe('ReactDebugFiberPerf', () => { - , + ); ReactNoop.flush(); resetFlamechart(); @@ -446,7 +443,7 @@ describe('ReactDebugFiberPerf', () => { - , + ); addComment('The commit phase should mention A and B just once'); ReactNoop.flush(); @@ -456,7 +453,7 @@ describe('ReactDebugFiberPerf', () => { - , + ); addComment("Because of deduplication, we don't know B was cascading,"); addComment('but we should still see the warning for the commit phase.'); @@ -465,11 +462,11 @@ describe('ReactDebugFiberPerf', () => { }); it('supports returns', () => { - function Continuation({isSame}) { + function Continuation({ isSame }) { return ; } - function CoChild({bar}) { + function CoChild({ bar }) { return ReactCallReturn.unstable_createReturn({ props: { bar: bar, @@ -492,7 +489,7 @@ describe('ReactDebugFiberPerf', () => { return ReactCallReturn.unstable_createCall( props.children, HandleReturns, - props, + props ); } @@ -512,11 +509,9 @@ describe('ReactDebugFiberPerf', () => { }); it('supports portals', () => { - const noopContainer = {children: []}; + const noopContainer = { children: [] }; ReactNoop.render( - - {ReactPortal.createPortal(, noopContainer, null)} - , + {ReactNoop.createPortal(, noopContainer, null)} ); ReactNoop.flush(); expect(getFlameChart()).toMatchSnapshot(); @@ -524,9 +519,9 @@ describe('ReactDebugFiberPerf', () => { it('does not schedule an extra callback if setState is called during a synchronous commit phase', () => { class Component extends React.Component { - state = {step: 1}; + state = { step: 1 }; componentDidMount() { - this.setState({step: 2}); + this.setState({ step: 2 }); } render() { return ; From 33c3dc188e218de221ed4a3fe880dae18d8d7f9c Mon Sep 17 00:00:00 2001 From: abiduzz420 Date: Thu, 30 Nov 2017 23:23:24 +0530 Subject: [PATCH 6/6] exec yarn prettier-all.(#11299) --- .../src/ReactNativeRenderer.js | 14 +-- .../ReactNativeEvents-test.internal.js | 95 +++++++++---------- .../ReactNativeMount-test.internal.js | 20 ++-- packages/react-noop-renderer/src/ReactNoop.js | 74 +++++++-------- .../ReactIncrementalPerf-test.internal.js | 48 +++++----- .../ReactPersistent-test.internal.js | 16 ++-- .../react-rt-renderer/src/ReactNativeRT.js | 12 +-- packages/shared/ReactPortal.js | 6 +- packages/shared/ReactTypes.js | 6 +- packages/shared/reactProdInvariant.js | 2 +- 10 files changed, 145 insertions(+), 148 deletions(-) diff --git a/packages/react-native-renderer/src/ReactNativeRenderer.js b/packages/react-native-renderer/src/ReactNativeRenderer.js index 39efe5357dd..67d8ff1e8db 100644 --- a/packages/react-native-renderer/src/ReactNativeRenderer.js +++ b/packages/react-native-renderer/src/ReactNativeRenderer.js @@ -7,8 +7,8 @@ * @flow */ -import type { ReactNativeType } from './ReactNativeTypes'; -import type { ReactNodeList } from 'shared/ReactTypes'; +import type {ReactNativeType} from './ReactNativeTypes'; +import type {ReactNodeList} from 'shared/ReactTypes'; import './ReactNativeInjection'; @@ -22,20 +22,20 @@ import ReactVersion from 'shared/ReactVersion'; // Module provided by RN: import UIManager from 'UIManager'; -import { showDialog } from './ReactNativeFiberErrorDialog'; +import {showDialog} from './ReactNativeFiberErrorDialog'; import NativeMethodsMixin from './NativeMethodsMixin'; import ReactNativeBridgeEventPlugin from './ReactNativeBridgeEventPlugin'; import ReactNativeComponent from './ReactNativeComponent'; import * as ReactNativeComponentTree from './ReactNativeComponentTree'; import ReactNativeFiberRenderer from './ReactNativeFiberRenderer'; import ReactNativePropRegistry from './ReactNativePropRegistry'; -import { getInspectorDataForViewTag } from './ReactNativeFiberInspector'; +import {getInspectorDataForViewTag} from './ReactNativeFiberInspector'; import createReactNativeComponentClass from './createReactNativeComponentClass'; import findNumericNodeHandle from './findNumericNodeHandle'; import takeSnapshot from './takeSnapshot'; ReactGenericBatching.injection.injectFiberBatchedUpdates( - ReactNativeFiberRenderer.batchedUpdates + ReactNativeFiberRenderer.batchedUpdates, ); const roots = new Map(); @@ -83,7 +83,7 @@ const ReactNativeRenderer: ReactNativeType = { createPortal( children: ReactNodeList, containerTag: number, - key: ?string = null + key: ?string = null, ) { return ReactPortal.createPortal(children, containerTag, null, key); }, @@ -124,7 +124,7 @@ if (__DEV__) { printInclusive() {}, printWasted() {}, }, - } + }, ); } diff --git a/packages/react-native-renderer/src/__tests__/ReactNativeEvents-test.internal.js b/packages/react-native-renderer/src/__tests__/ReactNativeEvents-test.internal.js index 91fe2eb2e08..3ff818a2550 100644 --- a/packages/react-native-renderer/src/__tests__/ReactNativeEvents-test.internal.js +++ b/packages/react-native-renderer/src/__tests__/ReactNativeEvents-test.internal.js @@ -92,8 +92,8 @@ it('fails if unknown/unsupported event types are dispatched', () => { expect(() => { EventEmitter.receiveTouches( 'unspecifiedEvent', - [{ target, identifier: 17 }], - [0] + [{target, identifier: 17}], + [0], ); }).toThrow('Unsupported top level event type "unspecifiedEvent" dispatched'); }); @@ -101,7 +101,7 @@ it('fails if unknown/unsupported event types are dispatched', () => { it('handles events', () => { expect(RCTEventEmitter.register.mock.calls.length).toBe(1); var EventEmitter = RCTEventEmitter.register.mock.calls[0][0]; - var View = fakeRequireNativeComponent('View', { foo: true }); + var View = fakeRequireNativeComponent('View', {foo: true}); var log = []; ReactNative.render( @@ -110,8 +110,7 @@ it('handles events', () => { onTouchEnd={() => log.push('outer touchend')} onTouchEndCapture={() => log.push('outer touchend capture')} onTouchStart={() => log.push('outer touchstart')} - onTouchStartCapture={() => log.push('outer touchstart capture')} - > + onTouchStartCapture={() => log.push('outer touchstart capture')}> log.push('inner touchend capture')} @@ -120,7 +119,7 @@ it('handles events', () => { onTouchStart={() => log.push('inner touchstart')} /> , - 1 + 1, ); expect(UIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot(); @@ -129,18 +128,18 @@ it('handles events', () => { // Don't depend on the order of createView() calls. // Stack creates views outside-in; fiber creates them inside-out. var innerTag = UIManager.createView.mock.calls.find( - args => args[3].foo === 'inner' + args => args[3].foo === 'inner', )[0]; EventEmitter.receiveTouches( 'topTouchStart', - [{ target: innerTag, identifier: 17 }], - [0] + [{target: innerTag, identifier: 17}], + [0], ); EventEmitter.receiveTouches( 'topTouchEnd', - [{ target: innerTag, identifier: 17 }], - [0] + [{target: innerTag, identifier: 17}], + [0], ); expect(log).toEqual([ @@ -161,9 +160,9 @@ it('handles events on text nodes', () => { var Text = fakeRequireNativeComponent('Text', {}); class ContextHack extends React.Component { - static childContextTypes = { isInAParentText: PropTypes.bool }; + static childContextTypes = {isInAParentText: PropTypes.bool}; getChildContext() { - return { isInAParentText: true }; + return {isInAParentText: true}; } render() { return this.props.children; @@ -178,21 +177,19 @@ it('handles events on text nodes', () => { onTouchEnd={() => log.push('string touchend')} onTouchEndCapture={() => log.push('string touchend capture')} onTouchStart={() => log.push('string touchstart')} - onTouchStartCapture={() => log.push('string touchstart capture')} - > + onTouchStartCapture={() => log.push('string touchstart capture')}> Text Content log.push('number touchend')} onTouchEndCapture={() => log.push('number touchend capture')} onTouchStart={() => log.push('number touchstart')} - onTouchStartCapture={() => log.push('number touchstart capture')} - > + onTouchStartCapture={() => log.push('number touchstart capture')}> {123} , - 1 + 1, ); expect(UIManager.createView.mock.calls.length).toBe(5); @@ -200,32 +197,32 @@ it('handles events on text nodes', () => { // Don't depend on the order of createView() calls. // Stack creates views outside-in; fiber creates them inside-out. var innerTagString = UIManager.createView.mock.calls.find( - args => args[3] && args[3].text === 'Text Content' + args => args[3] && args[3].text === 'Text Content', )[0]; var innerTagNumber = UIManager.createView.mock.calls.find( - args => args[3] && args[3].text === '123' + args => args[3] && args[3].text === '123', )[0]; EventEmitter.receiveTouches( 'topTouchStart', - [{ target: innerTagString, identifier: 17 }], - [0] + [{target: innerTagString, identifier: 17}], + [0], ); EventEmitter.receiveTouches( 'topTouchEnd', - [{ target: innerTagString, identifier: 17 }], - [0] + [{target: innerTagString, identifier: 17}], + [0], ); EventEmitter.receiveTouches( 'topTouchStart', - [{ target: innerTagNumber, identifier: 18 }], - [0] + [{target: innerTagNumber, identifier: 18}], + [0], ); EventEmitter.receiveTouches( 'topTouchEnd', - [{ target: innerTagNumber, identifier: 18 }], - [0] + [{target: innerTagNumber, identifier: 18}], + [0], ); expect(log).toEqual([ @@ -242,11 +239,11 @@ it('handles events on text nodes', () => { it('handles when a responder is unmounted while a touch sequence is in progress', () => { var EventEmitter = RCTEventEmitter.register.mock.calls[0][0]; - var View = fakeRequireNativeComponent('View', { id: true }); + var View = fakeRequireNativeComponent('View', {id: true}); function getViewById(id) { return UIManager.createView.mock.calls.find( - args => args[3] && args[3].id === id + args => args[3] && args[3].id === id, )[0]; } @@ -279,13 +276,13 @@ it('handles when a responder is unmounted while a touch sequence is in progress' /> , - 1 + 1, ); EventEmitter.receiveTouches( 'topTouchStart', - [{ target: getViewById('one'), identifier: 17 }], - [0] + [{target: getViewById('one'), identifier: 17}], + [0], ); expect(getResponderId()).toBe('one'); @@ -303,7 +300,7 @@ it('handles when a responder is unmounted while a touch sequence is in progress' /> , - 1 + 1, ); // TODO Verify the onResponderEnd listener has been called (before the unmount) @@ -312,8 +309,8 @@ it('handles when a responder is unmounted while a touch sequence is in progress' EventEmitter.receiveTouches( 'topTouchEnd', - [{ target: getViewById('two'), identifier: 17 }], - [0] + [{target: getViewById('two'), identifier: 17}], + [0], ); expect(getResponderId()).toBeNull(); @@ -321,8 +318,8 @@ it('handles when a responder is unmounted while a touch sequence is in progress' EventEmitter.receiveTouches( 'topTouchStart', - [{ target: getViewById('two'), identifier: 17 }], - [0] + [{target: getViewById('two'), identifier: 17}], + [0], ); expect(getResponderId()).toBe('two'); @@ -332,11 +329,11 @@ it('handles when a responder is unmounted while a touch sequence is in progress' it('handles events without target', () => { var EventEmitter = RCTEventEmitter.register.mock.calls[0][0]; - var View = fakeRequireNativeComponent('View', { id: true }); + var View = fakeRequireNativeComponent('View', {id: true}); function getViewById(id) { return UIManager.createView.mock.calls.find( - args => args[3] && args[3].id === id + args => args[3] && args[3].id === id, )[0]; } @@ -373,7 +370,7 @@ it('handles events without target', () => { /> , - 1 + 1, ); } @@ -381,8 +378,8 @@ it('handles events without target', () => { EventEmitter.receiveTouches( 'topTouchStart', - [{ target: getViewById('one'), identifier: 17 }], - [0] + [{target: getViewById('one'), identifier: 17}], + [0], ); // Unmounting component 'one'. @@ -390,24 +387,24 @@ it('handles events without target', () => { EventEmitter.receiveTouches( 'topTouchEnd', - [{ target: getViewById('one'), identifier: 17 }], - [0] + [{target: getViewById('one'), identifier: 17}], + [0], ); expect(getResponderId()).toBe(null); EventEmitter.receiveTouches( 'topTouchStart', - [{ target: getViewById('two'), identifier: 18 }], - [0] + [{target: getViewById('two'), identifier: 18}], + [0], ); expect(getResponderId()).toBe('two'); EventEmitter.receiveTouches( 'topTouchEnd', - [{ target: getViewById('two'), identifier: 18 }], - [0] + [{target: getViewById('two'), identifier: 18}], + [0], ); expect(getResponderId()).toBe(null); diff --git a/packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js b/packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js index 2701e066583..aded93a90ee 100644 --- a/packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js +++ b/packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js @@ -27,7 +27,7 @@ describe('ReactNative', () => { it('should be able to create and render a native component', () => { var View = createReactNativeComponentClass('View', () => ({ - validAttributes: { foo: true }, + validAttributes: {foo: true}, uiViewClassName: 'View', })); @@ -40,7 +40,7 @@ describe('ReactNative', () => { it('should be able to create and update a native component', () => { var View = createReactNativeComponentClass('View', () => ({ - validAttributes: { foo: true }, + validAttributes: {foo: true}, uiViewClassName: 'View', })); @@ -56,12 +56,12 @@ describe('ReactNative', () => { expect(UIManager.createView.mock.calls.length).toBe(1); expect(UIManager.setChildren.mock.calls.length).toBe(1); expect(UIManager.manageChildren).not.toBeCalled(); - expect(UIManager.updateView).toBeCalledWith(2, 'View', { foo: 'bar' }); + expect(UIManager.updateView).toBeCalledWith(2, 'View', {foo: 'bar'}); }); it('should not call UIManager.updateView after render for properties that have not changed', () => { const Text = createReactNativeComponentClass('Text', () => ({ - validAttributes: { foo: true }, + validAttributes: {foo: true}, uiViewClassName: 'Text', })); @@ -87,7 +87,7 @@ describe('ReactNative', () => { it('should not call UIManager.updateView from setNativeProps for properties that have not changed', () => { const View = createReactNativeComponentClass('View', () => ({ - validAttributes: { foo: true }, + validAttributes: {foo: true}, uiViewClassName: 'View', })); @@ -108,21 +108,21 @@ describe('ReactNative', () => { viewRef = ref; }} />, - 11 + 11, ); expect(UIManager.updateView).not.toBeCalled(); viewRef.setNativeProps({}); expect(UIManager.updateView).not.toBeCalled(); - viewRef.setNativeProps({ foo: 'baz' }); + viewRef.setNativeProps({foo: 'baz'}); expect(UIManager.updateView.mock.calls.length).toBe(1); }); }); it('returns the correct instance and calls it in the callback', () => { var View = createReactNativeComponentClass('View', () => ({ - validAttributes: { foo: true }, + validAttributes: {foo: true}, uiViewClassName: 'View', })); @@ -133,7 +133,7 @@ describe('ReactNative', () => { 11, function() { b = this; - } + }, ); expect(a).toBeTruthy(); @@ -143,7 +143,7 @@ describe('ReactNative', () => { it('renders and reorders children', () => { var View = createReactNativeComponentClass('View', () => ({ - validAttributes: { title: true }, + validAttributes: {title: true}, uiViewClassName: 'View', })); diff --git a/packages/react-noop-renderer/src/ReactNoop.js b/packages/react-noop-renderer/src/ReactNoop.js index 2b5310b260b..ab778ddbce6 100644 --- a/packages/react-noop-renderer/src/ReactNoop.js +++ b/packages/react-noop-renderer/src/ReactNoop.js @@ -14,11 +14,11 @@ * environment. */ -import type { Fiber } from 'react-reconciler/src/ReactFiber'; -import type { UpdateQueue } from 'react-reconciler/src/ReactFiberUpdateQueue'; -import type { ReactNodeList } from 'shared/ReactTypes'; +import type {Fiber} from 'react-reconciler/src/ReactFiber'; +import type {UpdateQueue} from 'react-reconciler/src/ReactFiberUpdateQueue'; +import type {ReactNodeList} from 'shared/ReactTypes'; import ReactFiberReconciler from 'react-reconciler'; -import { enablePersistentReconciler } from 'shared/ReactFeatureFlags'; +import {enablePersistentReconciler} from 'shared/ReactFeatureFlags'; import * as ReactInstanceMap from 'shared/ReactInstanceMap'; import * as ReactPortal from 'shared/ReactPortal'; import emptyObject from 'fbjs/lib/emptyObject'; @@ -28,15 +28,15 @@ const UPDATE_SIGNAL = {}; var scheduledCallback = null; -type Container = { rootID: string, children: Array }; -type Props = { prop: any, hidden?: boolean }; +type Container = {rootID: string, children: Array}; +type Props = {prop: any, hidden?: boolean}; type Instance = {| type: string, id: number, children: Array, - prop: any + prop: any, |}; -type TextInstance = {| text: string, id: number |}; +type TextInstance = {|text: string, id: number|}; var instanceCounter = 0; @@ -44,7 +44,7 @@ var failInBeginPhase = false; function appendChild( parentInstance: Instance | Container, - child: Instance | TextInstance + child: Instance | TextInstance, ): void { const index = parentInstance.children.indexOf(child); if (index !== -1) { @@ -56,7 +56,7 @@ function appendChild( function insertBefore( parentInstance: Instance | Container, child: Instance | TextInstance, - beforeChild: Instance | TextInstance + beforeChild: Instance | TextInstance, ): void { const index = parentInstance.children.indexOf(child); if (index !== -1) { @@ -71,7 +71,7 @@ function insertBefore( function removeChild( parentInstance: Instance | Container, - child: Instance | TextInstance + child: Instance | TextInstance, ): void { const index = parentInstance.children.indexOf(child); if (index === -1) { @@ -106,13 +106,13 @@ var SharedHostConfig = { prop: props.prop, }; // Hide from unit tests - Object.defineProperty(inst, 'id', { value: inst.id, enumerable: false }); + Object.defineProperty(inst, 'id', {value: inst.id, enumerable: false}); return inst; }, appendInitialChild( parentInstance: Instance, - child: Instance | TextInstance + child: Instance | TextInstance, ): void { parentInstance.children.push(child); }, @@ -120,7 +120,7 @@ var SharedHostConfig = { finalizeInitialChildren( domElement: Instance, type: string, - props: Props + props: Props, ): boolean { return false; }, @@ -129,7 +129,7 @@ var SharedHostConfig = { instance: Instance, type: string, oldProps: Props, - newProps: Props + newProps: Props, ): null | {} { return UPDATE_SIGNAL; }, @@ -148,11 +148,11 @@ var SharedHostConfig = { text: string, rootContainerInstance: Container, hostContext: Object, - internalInstanceHandle: Object + internalInstanceHandle: Object, ): TextInstance { - var inst = { text: text, id: instanceCounter++ }; + var inst = {text: text, id: instanceCounter++}; // Hide from unit tests - Object.defineProperty(inst, 'id', { value: inst.id, enumerable: false }); + Object.defineProperty(inst, 'id', {value: inst.id, enumerable: false}); return inst; }, @@ -160,7 +160,7 @@ var SharedHostConfig = { if (scheduledCallback) { throw new Error( 'Scheduling a callback twice is excessive. Instead, keep track of ' + - 'whether the callback has already been scheduled.' + 'whether the callback has already been scheduled.', ); } scheduledCallback = callback; @@ -195,7 +195,7 @@ var NoopRenderer = ReactFiberReconciler({ updatePayload: Object, type: string, oldProps: Props, - newProps: Props + newProps: Props, ): void { instance.prop = newProps.prop; }, @@ -203,7 +203,7 @@ var NoopRenderer = ReactFiberReconciler({ commitTextUpdate( textInstance: TextInstance, oldText: string, - newText: string + newText: string, ): void { textInstance.text = newText; }, @@ -231,7 +231,7 @@ var PersistentNoopRenderer = enablePersistentReconciler newProps: Props, internalInstanceHandle: Object, keepChildren: boolean, - recyclableInstance: null | Instance + recyclableInstance: null | Instance, ): Instance { const clone = { id: instance.id, @@ -247,26 +247,26 @@ var PersistentNoopRenderer = enablePersistentReconciler }, createContainerChildSet( - container: Container + container: Container, ): Array { return []; }, appendChildToContainerChildSet( childSet: Array, - child: Instance | TextInstance + child: Instance | TextInstance, ): void { childSet.push(child); }, finalizeContainerChildren( container: Container, - newChildren: Array + newChildren: Array, ): void {}, replaceContainerChildren( container: Container, - newChildren: Array + newChildren: Array, ): void { container.children = newChildren; }, @@ -322,7 +322,7 @@ var ReactNoop = { createPortal( children: ReactNodeList, container: Container, - key: ?string = null + key: ?string = null, ) { return ReactPortal.createPortal(children, container, null, key); }, @@ -335,11 +335,11 @@ var ReactNoop = { renderToRootWithID( element: React$Element, rootID: string, - callback: ?Function + callback: ?Function, ) { let root = roots.get(rootID); if (!root) { - const container = { rootID: rootID, children: [] }; + const container = {rootID: rootID, children: []}; rootContainers.set(rootID, container); root = NoopRenderer.createContainer(container, false); roots.set(rootID, root); @@ -350,16 +350,16 @@ var ReactNoop = { renderToPersistentRootWithID( element: React$Element, rootID: string, - callback: ?Function + callback: ?Function, ) { if (PersistentNoopRenderer === null) { throw new Error( - 'Enable ReactFeatureFlags.enablePersistentReconciler to use it in tests.' + 'Enable ReactFeatureFlags.enablePersistentReconciler to use it in tests.', ); } let root = persistentRoots.get(rootID); if (!root) { - const container = { rootID: rootID, children: [] }; + const container = {rootID: rootID, children: []}; rootContainers.set(rootID, container); root = PersistentNoopRenderer.createContainer(container, false); persistentRoots.set(rootID, root); @@ -378,7 +378,7 @@ var ReactNoop = { }, findInstance( - componentOrElement: Element | ?React$Component + componentOrElement: Element | ?React$Component, ): null | Instance | TextInstance { if (componentOrElement == null) { return null; @@ -410,7 +410,7 @@ var ReactNoop = { }, flushAndYield( - unitsOfWork: number = Infinity + unitsOfWork: number = Infinity, ): Generator, void, void> { return flushUnitsOfWork(unitsOfWork); }, @@ -512,7 +512,7 @@ var ReactNoop = { ' '.repeat(depth + 1) + '~', firstUpdate && firstUpdate.partialState, firstUpdate.callback ? 'with callback' : '', - '[' + firstUpdate.expirationTime + ']' + '[' + firstUpdate.expirationTime + ']', ); var next; while ((next = firstUpdate.next)) { @@ -520,7 +520,7 @@ var ReactNoop = { ' '.repeat(depth + 1) + '~', next.partialState, next.callback ? 'with callback' : '', - '[' + firstUpdate.expirationTime + ']' + '[' + firstUpdate.expirationTime + ']', ); } } @@ -531,7 +531,7 @@ var ReactNoop = { '- ' + // need to explicitly coerce Symbol to a string (fiber.type ? fiber.type.name || fiber.type.toString() : '[root]'), - '[' + fiber.expirationTime + (fiber.pendingProps ? '*' : '') + ']' + '[' + fiber.expirationTime + (fiber.pendingProps ? '*' : '') + ']', ); if (fiber.updateQueue) { logUpdateQueue(fiber.updateQueue, depth); diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js b/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js index a53e036de25..e1e21dc2fc0 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js @@ -139,7 +139,7 @@ describe('ReactDebugFiberPerf', () => { ReactNoop.render( - + , ); addComment('Mount'); ReactNoop.flush(); @@ -147,7 +147,7 @@ describe('ReactDebugFiberPerf', () => { ReactNoop.render( - + , ); addComment('Update'); ReactNoop.flush(); @@ -184,7 +184,7 @@ describe('ReactDebugFiberPerf', () => { (b = inst)} /> - + , ); ReactNoop.flush(); resetFlamechart(); @@ -209,7 +209,7 @@ describe('ReactDebugFiberPerf', () => { ReactNoop.render( - + , ); addComment('Should print a warning'); ReactNoop.flush(); @@ -250,14 +250,14 @@ describe('ReactDebugFiberPerf', () => { ReactNoop.render( - + , ); addComment('Should not print a warning'); ReactNoop.flush(); ReactNoop.render( - + , ); addComment('Should not print a warning'); ReactNoop.flush(); @@ -273,7 +273,7 @@ describe('ReactDebugFiberPerf', () => { return true; } getChildContext() { - return { foo: 42 }; + return {foo: 42}; } componentWillMount() {} componentDidMount() {} @@ -305,7 +305,7 @@ describe('ReactDebugFiberPerf', () => { - + , ); }); addComment('Flush the child'); @@ -334,7 +334,7 @@ describe('ReactDebugFiberPerf', () => { - + , ); addComment('Start mounting Parent and A'); ReactNoop.flushDeferredPri(40); @@ -353,7 +353,7 @@ describe('ReactDebugFiberPerf', () => { ReactNoop.render( - + , ); try { addComment('Will fatal'); @@ -364,7 +364,7 @@ describe('ReactDebugFiberPerf', () => { ReactNoop.render( - + , ); addComment('Will reconcile from a clean state'); ReactNoop.flush(); @@ -381,9 +381,9 @@ describe('ReactDebugFiberPerf', () => { } class Boundary extends React.Component { - state = { error: null }; + state = {error: null}; componentDidCatch(error) { - this.setState({ error }); + this.setState({error}); } render() { if (this.state.error) { @@ -400,7 +400,7 @@ describe('ReactDebugFiberPerf', () => { - + , ); addComment('Stop on Baddie and restart from Boundary'); ReactNoop.flush(); @@ -432,7 +432,7 @@ describe('ReactDebugFiberPerf', () => { - + , ); ReactNoop.flush(); resetFlamechart(); @@ -443,7 +443,7 @@ describe('ReactDebugFiberPerf', () => { - + , ); addComment('The commit phase should mention A and B just once'); ReactNoop.flush(); @@ -453,7 +453,7 @@ describe('ReactDebugFiberPerf', () => { - + , ); addComment("Because of deduplication, we don't know B was cascading,"); addComment('but we should still see the warning for the commit phase.'); @@ -462,11 +462,11 @@ describe('ReactDebugFiberPerf', () => { }); it('supports returns', () => { - function Continuation({ isSame }) { + function Continuation({isSame}) { return ; } - function CoChild({ bar }) { + function CoChild({bar}) { return ReactCallReturn.unstable_createReturn({ props: { bar: bar, @@ -489,7 +489,7 @@ describe('ReactDebugFiberPerf', () => { return ReactCallReturn.unstable_createCall( props.children, HandleReturns, - props + props, ); } @@ -509,9 +509,9 @@ describe('ReactDebugFiberPerf', () => { }); it('supports portals', () => { - const noopContainer = { children: [] }; + const noopContainer = {children: []}; ReactNoop.render( - {ReactNoop.createPortal(, noopContainer, null)} + {ReactNoop.createPortal(, noopContainer, null)}, ); ReactNoop.flush(); expect(getFlameChart()).toMatchSnapshot(); @@ -519,9 +519,9 @@ describe('ReactDebugFiberPerf', () => { it('does not schedule an extra callback if setState is called during a synchronous commit phase', () => { class Component extends React.Component { - state = { step: 1 }; + state = {step: 1}; componentDidMount() { - this.setState({ step: 2 }); + this.setState({step: 2}); } render() { return ; diff --git a/packages/react-reconciler/src/__tests__/ReactPersistent-test.internal.js b/packages/react-reconciler/src/__tests__/ReactPersistent-test.internal.js index a6bd9687044..bba8cde849b 100644 --- a/packages/react-reconciler/src/__tests__/ReactPersistent-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactPersistent-test.internal.js @@ -34,12 +34,12 @@ describe('ReactPersistent', () => { } function div(...children) { - children = children.map(c => (typeof c === 'string' ? { text: c } : c)); - return { type: 'div', children, prop: undefined }; + children = children.map(c => (typeof c === 'string' ? {text: c} : c)); + return {type: 'div', children, prop: undefined}; } function span(prop) { - return { type: 'span', children: [], prop }; + return {type: 'span', children: [], prop}; } function getChildren() { @@ -159,12 +159,12 @@ describe('ReactPersistent', () => {
); } - const portalContainer = { rootID: 'persistent-portal-test', children: [] }; + const portalContainer = {rootID: 'persistent-portal-test', children: []}; const emptyPortalChildSet = portalContainer.children; render( {ReactPortal.createPortal(, portalContainer, null)} - + , ); ReactNoop.flush(); @@ -180,9 +180,9 @@ describe('ReactPersistent', () => { {ReactPortal.createPortal( Hello {'World'}, portalContainer, - null + null, )} - + , ); ReactNoop.flush(); @@ -196,7 +196,7 @@ describe('ReactPersistent', () => { // Reused portal children should have reference equality expect(newPortalChildren[0].children[0]).toBe( - originalPortalChildren[0].children[0] + originalPortalChildren[0].children[0], ); // Deleting the Portal, should clear its children diff --git a/packages/react-rt-renderer/src/ReactNativeRT.js b/packages/react-rt-renderer/src/ReactNativeRT.js index ad188e42f52..9cd67da903a 100644 --- a/packages/react-rt-renderer/src/ReactNativeRT.js +++ b/packages/react-rt-renderer/src/ReactNativeRT.js @@ -7,8 +7,8 @@ * @flow */ -import type { ReactNativeRTType } from './ReactNativeRTTypes'; -import type { ReactNodeList } from 'shared/ReactTypes'; +import type {ReactNativeRTType} from './ReactNativeRTTypes'; +import type {ReactNodeList} from 'shared/ReactTypes'; /** * Make sure essential globals are available and are patched correctly. Please don't remove this @@ -21,17 +21,17 @@ import './ReactNativeRTEventEmitter'; // TODO: direct imports like some-package/src/* are bad. Fix me. import * as ReactFiberErrorLogger from 'react-reconciler/src/ReactFiberErrorLogger'; -import { showDialog } from 'react-native-renderer/src/ReactNativeFiberErrorDialog'; +import {showDialog} from 'react-native-renderer/src/ReactNativeFiberErrorDialog'; import * as ReactPortal from 'shared/ReactPortal'; import * as ReactGenericBatching from 'events/ReactGenericBatching'; import ReactVersion from 'shared/ReactVersion'; -import { getFiberFromTag } from './ReactNativeRTComponentTree'; +import {getFiberFromTag} from './ReactNativeRTComponentTree'; import ReactNativeRTFiberRenderer from './ReactNativeRTFiberRenderer'; import ReactNativeRTFiberInspector from './ReactNativeRTFiberInspector'; ReactGenericBatching.injection.injectFiberBatchedUpdates( - ReactNativeRTFiberRenderer.batchedUpdates + ReactNativeRTFiberRenderer.batchedUpdates, ); const roots = new Map(); @@ -68,7 +68,7 @@ const ReactNativeRTFiber: ReactNativeRTType = { createPortal( children: ReactNodeList, containerTag: number, - key: ?string = null + key: ?string = null, ) { return ReactPortal.createPortal(children, containerTag, null, key); }, diff --git a/packages/shared/ReactPortal.js b/packages/shared/ReactPortal.js index 09ff27db395..c20459c4b62 100644 --- a/packages/shared/ReactPortal.js +++ b/packages/shared/ReactPortal.js @@ -7,16 +7,16 @@ * @flow */ -import { REACT_PORTAL_TYPE } from 'shared/ReactSymbols'; +import {REACT_PORTAL_TYPE} from 'shared/ReactSymbols'; -import type { ReactNodeList, ReactPortal } from 'shared/ReactTypes'; +import type {ReactNodeList, ReactPortal} from 'shared/ReactTypes'; export function createPortal( children: ReactNodeList, containerInfo: any, // TODO: figure out the API for cross-renderer implementation. implementation: any, - key: ?string = null + key: ?string = null, ): ReactPortal { return { // This tag allow us to uniquely identify this as a React Portal diff --git a/packages/shared/ReactTypes.js b/packages/shared/ReactTypes.js index 30b6e2ad398..900582e5d5a 100644 --- a/packages/shared/ReactTypes.js +++ b/packages/shared/ReactTypes.js @@ -30,12 +30,12 @@ export type ReactCall = { children: any, // This should be a more specific CallHandler handler: (props: any, returns: Array) => ReactNodeList, - props: any + props: any, }; export type ReactReturn = { $$typeof: Symbol | number, - value: mixed + value: mixed, }; export type ReactPortal = { @@ -44,5 +44,5 @@ export type ReactPortal = { containerInfo: any, children: ReactNodeList, // TODO: figure out the API for cross-renderer implementation. - implementation: any + implementation: any, }; diff --git a/packages/shared/reactProdInvariant.js b/packages/shared/reactProdInvariant.js index 8d6f62cb6d3..e9d63051fcc 100644 --- a/packages/shared/reactProdInvariant.js +++ b/packages/shared/reactProdInvariant.js @@ -31,7 +31,7 @@ function reactProdInvariant(code: string): void { ' for the full message or use the non-minified dev environment' + ' for full errors and additional helpful warnings.'; - var error: Error & { framesToPop?: number } = new Error(message); + var error: Error & {framesToPop?: number} = new Error(message); error.name = 'Invariant Violation'; error.framesToPop = 1; // we don't care about reactProdInvariant's own frame