From 15d5e57e928da1160cf7bfd4e322f2cb134d1d6c Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Sat, 19 May 2018 08:42:32 -0700 Subject: [PATCH] [fix] convert VirtualizedList vendor code to ES modules Webpack has trouble bundling a mix of CommonJS and ES modules in the same package. Fix #957 --- .../src/vendor/Batchinator/index.js | 2 +- .../src/vendor/FillRateHelper/index.js | 14 +++----------- .../src/vendor/ViewabilityHelper/index.js | 5 ++--- .../src/vendor/VirtualizeUtils/index.js | 11 +++++------ .../src/vendor/VirtualizedList/index.js | 2 +- 5 files changed, 12 insertions(+), 22 deletions(-) diff --git a/packages/react-native-web/src/vendor/Batchinator/index.js b/packages/react-native-web/src/vendor/Batchinator/index.js index 9280ff80..62ba16c9 100644 --- a/packages/react-native-web/src/vendor/Batchinator/index.js +++ b/packages/react-native-web/src/vendor/Batchinator/index.js @@ -70,4 +70,4 @@ class Batchinator { } } -module.exports = Batchinator; +export default Batchinator; diff --git a/packages/react-native-web/src/vendor/FillRateHelper/index.js b/packages/react-native-web/src/vendor/FillRateHelper/index.js index 6d829e7a..06bb89e1 100644 --- a/packages/react-native-web/src/vendor/FillRateHelper/index.js +++ b/packages/react-native-web/src/vendor/FillRateHelper/index.js @@ -8,16 +8,8 @@ * @format */ -'use strict'; - -/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error - * found when Flow v0.54 was deployed. To see the error delete this comment and - * run Flow. */ -const performanceNow = require('fbjs/lib/performanceNow'); -/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error - * found when Flow v0.54 was deployed. To see the error delete this comment and - * run Flow. */ -const warning = require('fbjs/lib/warning'); +import performanceNow from 'fbjs/lib/performanceNow'; +import warning from 'fbjs/lib/warning'; export type FillRateInfo = Info; @@ -221,4 +213,4 @@ class FillRateHelper { } } -module.exports = FillRateHelper; +export default FillRateHelper; diff --git a/packages/react-native-web/src/vendor/ViewabilityHelper/index.js b/packages/react-native-web/src/vendor/ViewabilityHelper/index.js index 122814d8..08dbe5af 100644 --- a/packages/react-native-web/src/vendor/ViewabilityHelper/index.js +++ b/packages/react-native-web/src/vendor/ViewabilityHelper/index.js @@ -7,9 +7,8 @@ * @noflow * @format */ -'use strict'; -const invariant = require('fbjs/lib/invariant'); +import invariant from 'fbjs/lib/invariant'; export type ViewToken = { item: any, @@ -275,4 +274,4 @@ function _isEntirelyVisible(top: number, bottom: number, viewportHeight: number) return top >= 0 && bottom <= viewportHeight && bottom > top; } -module.exports = ViewabilityHelper; +export default ViewabilityHelper; diff --git a/packages/react-native-web/src/vendor/VirtualizeUtils/index.js b/packages/react-native-web/src/vendor/VirtualizeUtils/index.js index cb4f0fcb..c7f41095 100644 --- a/packages/react-native-web/src/vendor/VirtualizeUtils/index.js +++ b/packages/react-native-web/src/vendor/VirtualizeUtils/index.js @@ -7,16 +7,15 @@ * @flow * @format */ -'use strict'; -const invariant = require('fbjs/lib/invariant'); +import invariant from 'fbjs/lib/invariant'; /** * Used to find the indices of the frames that overlap the given offsets. Useful for finding the * items that bound different windows of content, such as the visible area or the buffered overscan * area. */ -function elementsThatOverlapOffsets( +export function elementsThatOverlapOffsets( offsets: Array, itemCount: number, getFrameMetrics: (index: number) => { length: number, offset: number } @@ -50,7 +49,7 @@ function elementsThatOverlapOffsets( * can restrict the number of new items render at once so that content can appear on the screen * faster. */ -function newRangeCount( +export function newRangeCount( prev: { first: number, last: number }, next: { first: number, last: number } ): number { @@ -68,7 +67,7 @@ function newRangeCount( * prioritizes the visible area first, then expands that with overscan regions ahead and behind, * biased in the direction of scroll. */ -function computeWindowedRenderLimits( +export function computeWindowedRenderLimits( props: { data: any, getItemCount: (data: any) => number, @@ -201,4 +200,4 @@ const VirtualizeUtils = { newRangeCount }; -module.exports = VirtualizeUtils; +export default VirtualizeUtils; diff --git a/packages/react-native-web/src/vendor/VirtualizedList/index.js b/packages/react-native-web/src/vendor/VirtualizedList/index.js index dc0b3120..e3f9d9ff 100644 --- a/packages/react-native-web/src/vendor/VirtualizedList/index.js +++ b/packages/react-native-web/src/vendor/VirtualizedList/index.js @@ -1593,4 +1593,4 @@ const styles = StyleSheet.create({ } }); -module.exports = VirtualizedList; +export default VirtualizedList;