// eslint-disable-next-line import/prefer-default-export
export const onLoadMore = ctx => {
  let disabled = false;

  const resetState = () => {
    disabled = false;
  };

  return fn => {
    const {
      onReachBottom
    } = ctx.$page;

    ctx.$page.onReachBottom = () => {
      onReachBottom.call(ctx.$page);
      if (disabled) return;
      disabled = true;
      fn && fn(resetState);
    };
  };
};