lodash#isFinite JavaScript Examples

The following examples show how to use lodash#isFinite. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.js    From hzero-front with Apache License 2.0 6 votes vote down vote up
/**
   * 列信息-新建打开模态框初始化滑窗数据
   */
  @Bind()
  getInitMetaColumn() {
    const {
      dispatch,
      reportDefinition: { header },
    } = this.props;
    const { metaColumns = [] } = header;
    const ordinalList = metaColumns && metaColumns.map((item) => item.ordinal);
    const ordinalMax = Math.max(...ordinalList);
    dispatch({
      type: 'reportDefinition/getInitMetaColumn',
    }).then((res) => {
      if (res) {
        const anotherRes = { ...res, ordinal: isFinite(ordinalMax) ? ordinalMax + 1 : 0 };
        this.setState({
          metaColumnsItem: { ...anotherRes },
          metaColumnsDrawerVisible: true,
          isCreateMetaColumn: true,
        });
      }
    });
  }
Example #2
Source File: useQueryString.jsx    From ResoBin with MIT License 5 votes vote down vote up
useQueryString = () => {
  const location = useLocation()
  const navigate = useNavigate()

  const setQueryString = (key, value) => {
    const queryString = new URLSearchParams(location.search)

    // ? No change
    if (value === undefined || value === queryString.get(key)) return

    // ? update query string (or clear query string if query is empty)
    if (isEmpty(value) && !isFinite(value)) queryString.delete(key)
    else queryString.set(key, value)

    location.search = queryString.toString()
    navigate(location, { replace: true })
  }

  // ? Debouncing is necessary to avoid unnecessary API calls
  const setQueryStringDebounced = useCallback(
    memoize((key) => debounce(setQueryString, 500)),
    [location.search]
  )

  const getQueryString = useCallback(
    (key) => {
      const queryString = new URLSearchParams(location.search)
      if (key) return queryString.get(key)

      return Object.fromEntries(queryString)
    },
    [location.search]
  )

  // ? If keys are passed, removes keys from qs. Else clears qs
  const deleteQueryString = useCallback(
    (...keys) => {
      const queryString = new URLSearchParams(location.search)

      if (isEmpty(keys)) {
        location.search = ''
      } else {
        keys.forEach((key) => {
          queryString.delete(key)
        })
        location.search = queryString.toString()
      }

      navigate(location, { replace: true })
    },
    [location.search]
  )

  return {
    deleteQueryString,
    getQueryString,
    setQueryString: (key, value) => setQueryStringDebounced(key)(key, value),
  }
}