All files wrap-menu-list.jsx

96% Statements 24/25
75% Branches 9/12
100% Functions 8/8
96% Lines 24/25
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101      3x                           1x       1x 1x         8x           8x   8x   8x       2x   2x       2x         1x   1x 1x           7x     7x 2x             5x     5x 2x             3x   3x       12x                 3x    
import React, { Component } from 'react';
import PropTypes from 'prop-types';
 
export const CHECK_TIMEOUT = 300;
 
export default function wrapMenuList(MenuList) {
  class WrappedMenuList extends Component {
    static propTypes = {
      innerRef: PropTypes.func.isRequired,
 
      selectProps: PropTypes.shape({
        handleScrolledToBottom: PropTypes.func.isRequired,
        shouldLoadMore: PropTypes.func.isRequired,
      }).isRequired,
    }
 
    componentDidMount() {
      this.setCheckAndHandleTimeount();
    }
 
    componentWillUnmount() {
      Eif (this.checkTimeout) {
        clearTimeout(this.checkTimeout);
      }
    }
 
    innerRef = (ref) => {
      Iif (ref === this.menuListRef) {
        return;
      }
 
      const {
        innerRef,
      } = this.props;
 
      this.menuListRef = ref;
 
      innerRef(ref);
    }
 
    setCheckAndHandleTimeount = () => {
      this.checkAndHandle();
 
      this.checkTimeout = setTimeout(this.setCheckAndHandleTimeount, CHECK_TIMEOUT);
    }
 
    checkAndHandle() {
      if (this.shouldHandle()) {
        const {
          selectProps: {
            handleScrolledToBottom,
          },
        } = this.props;
 
        Eif (handleScrolledToBottom) {
          handleScrolledToBottom();
        }
      }
    }
 
    shouldHandle() {
      const el = this.menuListRef;
 
      // menu not rendered
      if (!el) {
        return false;
      }
 
      const {
        scrollTop,
        scrollHeight,
        clientHeight,
      } = el;
 
      // menu hasn't scroll
      if (scrollHeight <= clientHeight) {
        return true;
      }
 
      const {
        selectProps: {
          shouldLoadMore,
        },
      } = this.props;
 
      return shouldLoadMore(scrollHeight, clientHeight, scrollTop);
    }
 
    render() {
      return (
        <MenuList
          {...this.props}
          innerRef={this.innerRef}
        />
      );
    }
  }
 
  return WrappedMenuList;
}