From a10dbdaaf6873b126ae5b565377748ff24962e6a Mon Sep 17 00:00:00 2001 From: Spencer Ahrens Date: Tue, 28 Feb 2017 02:08:58 -0800 Subject: [PATCH] Rename flow type Viewable -> ViewToken Summary: `Viewable` is a weird name - I think `ViewToken` is more clear? Also easier to grep for. Reviewed By: yungsters, bvaughn Differential Revision: D4600762 fbshipit-source-id: dbfa5eec1b91166c4889dcb6b87d7832090be9e9 --- Libraries/Experimental/FlatList.js | 6 ++--- Libraries/Experimental/SectionList.js | 6 ++--- Libraries/Experimental/ViewabilityHelper.js | 16 ++++++------ Libraries/Experimental/VirtualizedList.js | 8 +++--- .../Experimental/VirtualizedSectionList.js | 12 ++++----- .../__tests__/ViewabilityHelper-test.js | 26 +++++++++---------- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/Libraries/Experimental/FlatList.js b/Libraries/Experimental/FlatList.js index d82c5ef1c..99c1b880f 100644 --- a/Libraries/Experimental/FlatList.js +++ b/Libraries/Experimental/FlatList.js @@ -40,7 +40,7 @@ const VirtualizedList = require('VirtualizedList'); const invariant = require('invariant'); import type {StyleObj} from 'StyleSheetTypes'; -import type {ViewabilityConfig, Viewable} from 'ViewabilityHelper'; +import type {ViewabilityConfig, ViewToken} from 'ViewabilityHelper'; import type {Props as VirtualizedListProps} from 'VirtualizedList'; type Item = any; @@ -111,7 +111,7 @@ type OptionalProps = { * Called when the viewability of rows changes, as defined by the * `viewablePercentThreshold` prop. */ - onViewableItemsChanged?: ?({viewableItems: Array, changed: Array}) => void, + onViewableItemsChanged?: ?({viewableItems: Array, changed: Array}) => void, legacyImplementation?: ?boolean, /** * Set this true while waiting for new data from a refresh. @@ -281,7 +281,7 @@ class FlatList extends React.PureComponent, vo } }; - _pushMultiColumnViewable(arr: Array, v: Viewable): void { + _pushMultiColumnViewable(arr: Array, v: ViewToken): void { const {numColumns, keyExtractor} = this.props; v.item.forEach((item, ii) => { invariant(v.index != null, 'Missing index!'); diff --git a/Libraries/Experimental/SectionList.js b/Libraries/Experimental/SectionList.js index ad946e062..1bf35eedc 100644 --- a/Libraries/Experimental/SectionList.js +++ b/Libraries/Experimental/SectionList.js @@ -36,7 +36,7 @@ const MetroListView = require('MetroListView'); const React = require('React'); const VirtualizedSectionList = require('VirtualizedSectionList'); -import type {Viewable} from 'ViewabilityHelper'; +import type {ViewToken} from 'ViewabilityHelper'; import type {Props as VirtualizedSectionListProps} from 'VirtualizedSectionList'; type Item = any; @@ -54,7 +54,7 @@ type SectionBase = { // TODO: support more optional/override props // FooterComponent?: ?ReactClass<*>, // HeaderComponent?: ?ReactClass<*>, - // onViewableItemsChanged?: ({viewableItems: Array, changed: Array}) => void, + // onViewableItemsChanged?: ({viewableItems: Array, changed: Array}) => void, // TODO: support recursive sections // SectionHeaderComponent?: ?ReactClass<{section: SectionBase<*>}>, @@ -107,7 +107,7 @@ type OptionalProps> = { * Called when the viewability of rows changes, as defined by the * `viewablePercentThreshold` prop. */ - onViewableItemsChanged?: ?({viewableItems: Array, changed: Array}) => void, + onViewableItemsChanged?: ?({viewableItems: Array, changed: Array}) => void, /** * Set this true while waiting for new data from a refresh. */ diff --git a/Libraries/Experimental/ViewabilityHelper.js b/Libraries/Experimental/ViewabilityHelper.js index 0b26c514f..a8a185165 100644 --- a/Libraries/Experimental/ViewabilityHelper.js +++ b/Libraries/Experimental/ViewabilityHelper.js @@ -13,7 +13,7 @@ const invariant = require('invariant'); -export type Viewable = {item: any, key: string, index: ?number, isViewable: boolean, section?: any}; +export type ViewToken = {item: any, key: string, index: ?number, isViewable: boolean, section?: any}; export type ViewabilityConfig = {| /** @@ -68,7 +68,7 @@ class ViewabilityHelper { _lastUpdateTime: number = 0; _timers: Set = new Set(); _viewableIndices: Array = []; - _viewableItems: Map = new Map(); + _viewableItems: Map = new Map(); constructor(config: ViewabilityConfig = {viewAreaCoveragePercentThreshold: 0}) { invariant( @@ -140,8 +140,8 @@ class ViewabilityHelper { scrollOffset: number, viewportHeight: number, getFrameMetrics: (index: number) => ?{length: number, offset: number}, - createViewable: (index: number, isViewable: boolean) => Viewable, - onViewableItemsChanged: ({viewableItems: Array, changed: Array}) => void, + createViewToken: (index: number, isViewable: boolean) => ViewToken, + onViewableItemsChanged: ({viewableItems: Array, changed: Array}) => void, renderRange?: {first: number, last: number}, // Optional optimization to reduce the scan size ): void { const updateTime = Date.now(); @@ -186,13 +186,13 @@ class ViewabilityHelper { const handle = setTimeout( () => { this._timers.delete(handle); - this._onUpdateSync(viewableIndices, onViewableItemsChanged, createViewable); + this._onUpdateSync(viewableIndices, onViewableItemsChanged, createViewToken); }, this._config.minViewTime, ); this._timers.add(handle); } else { - this._onUpdateSync(viewableIndices, onViewableItemsChanged, createViewable); + this._onUpdateSync(viewableIndices, onViewableItemsChanged, createViewToken); } } @@ -200,7 +200,7 @@ class ViewabilityHelper { this._hasInteracted = true; } - _onUpdateSync(viewableIndicesToCheck, onViewableItemsChanged, createViewable) { + _onUpdateSync(viewableIndicesToCheck, onViewableItemsChanged, createViewToken) { // Filter out indices that have gone out of view since this call was scheduled. viewableIndicesToCheck = viewableIndicesToCheck.filter( (ii) => this._viewableIndices.includes(ii) @@ -208,7 +208,7 @@ class ViewabilityHelper { const prevItems = this._viewableItems; const nextItems = new Map( viewableIndicesToCheck.map(ii => { - const viewable = createViewable(ii, true); + const viewable = createViewToken(ii, true); return [viewable.key, viewable]; }) ); diff --git a/Libraries/Experimental/VirtualizedList.js b/Libraries/Experimental/VirtualizedList.js index b90cd4e80..0c8dfb7e8 100644 --- a/Libraries/Experimental/VirtualizedList.js +++ b/Libraries/Experimental/VirtualizedList.js @@ -44,7 +44,7 @@ const invariant = require('fbjs/lib/invariant'); const {computeWindowedRenderLimits} = require('VirtualizeUtils'); -import type {ViewabilityConfig, Viewable} from 'ViewabilityHelper'; +import type {ViewabilityConfig, ViewToken} from 'ViewabilityHelper'; type Item = any; type ItemComponentType = ReactClass<{item: Item, index: number}>; @@ -105,7 +105,7 @@ type OptionalProps = { * Called when the viewability of rows changes, as defined by the * `viewablePercentThreshold` prop. */ - onViewableItemsChanged?: ?({viewableItems: Array, changed: Array}) => void, + onViewableItemsChanged?: ?({viewableItems: Array, changed: Array}) => void, /** * Set this true while waiting for new data from a refresh. */ @@ -572,7 +572,7 @@ class VirtualizedList extends React.PureComponent { }); }; - _createViewable = (index: number, isViewable: boolean): Viewable => { + _createViewToken = (index: number, isViewable: boolean): ViewToken => { const {data, getItem, keyExtractor} = this.props; const item = getItem(data, index); invariant(item, 'Missing item for index ' + index); @@ -619,7 +619,7 @@ class VirtualizedList extends React.PureComponent { this._scrollMetrics.offset, this._scrollMetrics.visibleLength, this._getFrameMetrics, - this._createViewable, + this._createViewToken, onViewableItemsChanged, this.state, ); diff --git a/Libraries/Experimental/VirtualizedSectionList.js b/Libraries/Experimental/VirtualizedSectionList.js index 88d9c3ac4..74cb54b20 100644 --- a/Libraries/Experimental/VirtualizedSectionList.js +++ b/Libraries/Experimental/VirtualizedSectionList.js @@ -39,7 +39,7 @@ const VirtualizedList = require('VirtualizedList'); const invariant = require('invariant'); const warning = require('warning'); -import type {Viewable} from 'ViewabilityHelper'; +import type {ViewToken} from 'ViewabilityHelper'; import type {Props as VirtualizedListProps} from 'VirtualizedList'; type Item = any; @@ -58,7 +58,7 @@ type SectionBase = { // TODO: support more optional/override props // FooterComponent?: ?ReactClass<*>, // HeaderComponent?: ?ReactClass<*>, - // onViewableItemsChanged?: ({viewableItems: Array, changed: Array}) => void, + // onViewableItemsChanged?: ({viewableItems: Array, changed: Array}) => void, // TODO: support recursive sections // SectionHeaderComponent?: ?ReactClass<{section: SectionBase}>, @@ -108,7 +108,7 @@ type OptionalProps = { * Called when the viewability of rows changes, as defined by the * `viewablePercentThreshold` prop. */ - onViewableItemsChanged?: ?({viewableItems: Array, changed: Array}) => void, + onViewableItemsChanged?: ?({viewableItems: Array, changed: Array}) => void, /** * Set this true while waiting for new data from a refresh. */ @@ -184,8 +184,8 @@ class VirtualizedSectionList } } - _convertViewable = (viewable: Viewable): ?Viewable => { - invariant(viewable.index != null, 'Received a broken Viewable'); + _convertViewable = (viewable: ViewToken): ?ViewToken => { + invariant(viewable.index != null, 'Received a broken ViewToken'); const info = this._subExtractor(viewable.index); if (!info) { return null; @@ -200,7 +200,7 @@ class VirtualizedSectionList }; _onViewableItemsChanged = ( - {viewableItems, changed}: {viewableItems: Array, changed: Array} + {viewableItems, changed}: {viewableItems: Array, changed: Array} ) => { if (this.props.onViewableItemsChanged) { this.props.onViewableItemsChanged({ diff --git a/Libraries/Experimental/__tests__/ViewabilityHelper-test.js b/Libraries/Experimental/__tests__/ViewabilityHelper-test.js index 2e272900a..9d7876f49 100644 --- a/Libraries/Experimental/__tests__/ViewabilityHelper-test.js +++ b/Libraries/Experimental/__tests__/ViewabilityHelper-test.js @@ -18,7 +18,7 @@ function getFrameMetrics(index: number) { const frame = rowFrames[data[index].key]; return {length: frame.height, offset: frame.y}; } -function createViewable(index: number, isViewable: boolean) { +function createViewToken(index: number, isViewable: boolean) { return {key: data[index].key, isViewable}; } @@ -161,7 +161,7 @@ describe('onUpdate', function() { 0, 200, getFrameMetrics, - createViewable, + createViewToken, onViewableItemsChanged, ); expect(onViewableItemsChanged.mock.calls.length).toBe(1); @@ -174,7 +174,7 @@ describe('onUpdate', function() { 0, 200, getFrameMetrics, - createViewable, + createViewToken, onViewableItemsChanged, ); expect(onViewableItemsChanged.mock.calls.length).toBe(1); // nothing changed! @@ -183,7 +183,7 @@ describe('onUpdate', function() { 100, 200, getFrameMetrics, - createViewable, + createViewToken, onViewableItemsChanged, ); expect(onViewableItemsChanged.mock.calls.length).toBe(2); @@ -209,7 +209,7 @@ describe('onUpdate', function() { 0, 200, getFrameMetrics, - createViewable, + createViewToken, onViewableItemsChanged, ); expect(onViewableItemsChanged.mock.calls.length).toBe(1); @@ -222,7 +222,7 @@ describe('onUpdate', function() { 100, 200, getFrameMetrics, - createViewable, + createViewToken, onViewableItemsChanged, ); expect(onViewableItemsChanged.mock.calls.length).toBe(2); @@ -236,7 +236,7 @@ describe('onUpdate', function() { 200, 200, getFrameMetrics, - createViewable, + createViewToken, onViewableItemsChanged, ); expect(onViewableItemsChanged.mock.calls.length).toBe(3); @@ -262,7 +262,7 @@ describe('onUpdate', function() { 0, 200, getFrameMetrics, - createViewable, + createViewToken, onViewableItemsChanged, ); expect(onViewableItemsChanged).not.toBeCalled(); @@ -292,7 +292,7 @@ describe('onUpdate', function() { 0, 200, getFrameMetrics, - createViewable, + createViewToken, onViewableItemsChanged, ); helper.onUpdate( @@ -300,7 +300,7 @@ describe('onUpdate', function() { 300, // scroll past item 'a' 200, getFrameMetrics, - createViewable, + createViewToken, onViewableItemsChanged, ); @@ -335,7 +335,7 @@ describe('onUpdate', function() { 0, 100, getFrameMetrics, - createViewable, + createViewToken, onViewableItemsChanged, ); expect(onViewableItemsChanged).not.toBeCalled(); @@ -344,7 +344,7 @@ describe('onUpdate', function() { 10, // not far enough to meet minimumOffset 100, getFrameMetrics, - createViewable, + createViewToken, onViewableItemsChanged, ); expect(onViewableItemsChanged).not.toBeCalled(); @@ -353,7 +353,7 @@ describe('onUpdate', function() { 20, 100, getFrameMetrics, - createViewable, + createViewToken, onViewableItemsChanged, ); expect(onViewableItemsChanged.mock.calls.length).toBe(1);