Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nihgwu committed May 1, 2019
1 parent 481f90d commit 5d7fb35
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
29 changes: 26 additions & 3 deletions src/__tests__/FixedSizeGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,21 +288,44 @@ describe('FixedSizeGrid', () => {
it('should warn about deprecated overscanCount prop', () => {
spyOn(console, 'warn');

const renderer = ReactTestRenderer.create(
<FixedSizeGrid {...defaultProps} overscanCount={1} />
);
expect(console.warn).toHaveBeenCalledTimes(1);
expect(console.warn).toHaveBeenLastCalledWith(
'The overscanCount prop has been deprecated. ' +
'Please use the overscanColumnCount and overscanRowCount props instead.'
);

renderer.update(<FixedSizeGrid {...defaultProps} overscanCount={1} />);

// But it should only warn once.
expect(console.warn).toHaveBeenCalledTimes(1);
});

it('should warn about deprecated overscanRowsCount or overscanColumnsCount prop', () => {
spyOn(console, 'warn');

const renderer = ReactTestRenderer.create(
<FixedSizeGrid
{...defaultProps}
overscanCount={1}
overscanRowsCount={1}
overscanColumnsCount={1}
/>
);
expect(console.warn).toHaveBeenCalledTimes(1);
expect(console.warn).toHaveBeenLastCalledWith(
'The overscanCount, overscanColumnsCount and overscanRowsCount props have been deprecated. ' +
'The overscanColumnsCount and overscanRowsCount props have been deprecated. ' +
'Please use the overscanColumnCount and overscanRowCount props instead.'
);

renderer.update(<FixedSizeGrid {...defaultProps} overscanCount={1} />);
renderer.update(
<FixedSizeGrid
{...defaultProps}
overscanRowsCount={1}
overscanColumnsCount={1}
/>
);

// But it should only warn once.
expect(console.warn).toHaveBeenCalledTimes(1);
Expand Down
24 changes: 20 additions & 4 deletions src/createGridComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,12 @@ const defaultItemKey = ({ columnIndex, data, rowIndex }) =>
// In DEV mode, this Set helps us only log a warning once per component instance.
// This avoids spamming the console every time a render happens.
let devWarningsOverscanCount = null;
let devWarningsOverscanRowsColumnsCount = null;
let devWarningsTagName = null;
if (process.env.NODE_ENV !== 'production') {
if (typeof window !== 'undefined' && typeof window.WeakSet !== 'undefined') {
devWarningsOverscanCount = new WeakSet();
devWarningsOverscanRowsColumnsCount = new WeakSet();
devWarningsTagName = new WeakSet();
}
}
Expand Down Expand Up @@ -772,21 +774,35 @@ const validateSharedProps = (
height,
innerTagName,
outerTagName,
overscanColumnsCount,
overscanCount,
overscanRowsCount,
width,
}: Props<any>,
{ instance }: State
): void => {
if (process.env.NODE_ENV !== 'production') {
if (typeof overscanCount === 'number') {
if (devWarningsOverscanCount && !devWarningsOverscanCount.has(instance)) {
devWarningsOverscanCount.add(instance);
console.warn(
'The overscanCount prop has been deprecated. ' +
'Please use the overscanColumnCount and overscanRowCount props instead.'
);
}
}

if (
typeof overscanCount === 'number' ||
typeof overscanColumnsCount === 'number' ||
typeof overscanRowsCount === 'number'
) {
if (devWarningsOverscanCount && !devWarningsOverscanCount.has(instance)) {
devWarningsOverscanCount.add(instance);
if (
devWarningsOverscanRowsColumnsCount &&
!devWarningsOverscanRowsColumnsCount.has(instance)
) {
devWarningsOverscanRowsColumnsCount.add(instance);
console.warn(
'The overscanCount, overscanColumnsCount and overscanRowsCount props have been deprecated. ' +
'The overscanColumnsCount and overscanRowsCount props have been deprecated. ' +
'Please use the overscanColumnCount and overscanRowCount props instead.'
);
}
Expand Down

0 comments on commit 5d7fb35

Please sign in to comment.