Skip to content

Latest commit

 

History

History
281 lines (190 loc) · 15.2 KB

CHANGELOG.md

File metadata and controls

281 lines (190 loc) · 15.2 KB

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

2.0.3 (2023-06-13)

Refactor

2.0.2 (2023-06-02)

Refactor

2.0.1 (2023-06-01)

Changelog

  • Use vue-demi to be compatible with Vue 2 #38

  • Added custom cache getCache, setCache, and clearCache.

  • When caching is enabled, requests with the same cacheKey will be cached and reused.

  • Added runAsync and refreshAsync, which return a Promise.

  • Added definePlugin to extend the functionality of useRequest through plugins.

  • In throttle/debounce mode, runAsync can be used to return a normal Promise.

  • Added useRequestProvider hooks to inject options configuration.

  • Added refreshDepsAction option to customize the behavior after refreshDeps is triggered.

  • refreshDepsAction will also be triggered by changes in refreshDeps when manual=true.

  • Added loadingKeep.

  • Removed the integrated request library and service no longer supports strings or objects. Migration Guide

  • Removed formatResult. Migration Guide

  • Removed queryKey, i.e., parallel mode is removed Migration Guide

  • run no longer returns a Promise Migration Guide

  • When a request fails, data is no longer cleared #82

  • Modified the logic of ready Migration Guide

  • ready now supports passing a function that returns a Boolean value #166

  • data and error changed to shallowRef

  • usePagination removed reload method and reloading. If needed, they can be implemented separately.

  • Removed RequestConfig component Migration Guide

  • Refactored useLoadMore, see details for specific API API Description

  • cacheKey can now be passed a function: cacheKey: (params?: P) => string

    useRequest(getUser, {
      cacheKey: (params?: P): string => {
        // When initialized, `params` will be undefined, so we need to manually check and return an empty string
        if (params) {
          return `user-key-${params[0].name}`;
        }
        return '';
      },
    });
  • Some options support reactivity, as shown below:

    type ReactivityOptions = {
      loadingDelay: number | Ref<number>;
      loadingKeep: number | Ref<number>;
      pollingInterval: number | Ref<number>;
      debounceInterval: number | Ref<number>;
      debounceOptions: DebounceOptions | Reactive<DebounceOptions>;
      throttleInterval: number | Ref<number>;
      throttleOptions: ThrottleOptions | Reactive<ThrottleOptions>;
      refreshOnWindowFocus: boolean | Ref<boolean>;
      refocusTimespan: number | Ref<number>;
      errorRetryCount: number | Ref<number>;
      errorRetryInterval: number | Ref<number>;
    };
  • refreshDeps now supports passing a function that returns a value, a ref, a reactive object, or an array of any of these types. #166

Migration Guide

  1. service no longer supports strings or objects. Users are expected to wrap their requests using other third-party libraries (such as axios) and provide a Promise as the service function.

    const getUser = userName => {
      return axios.get('api/user', {
        params: {
          name: userName,
        },
      });
    };
    useRequest(getUser, options);
  2. formatResult has been removed. Users are expected to format the final data in their service function.

    const getUser = async () => {
      const results = await axios.get('api/user');
      // Format the final data here
      return results.data;
    };
  3. queryKey has been removed, which means parallel mode is no longer supported. Users are expected to encapsulate each request action and UI into a component instead of putting all requests in the parent component.

  4. Changes to the ready logic

    • When manual=false, every time ready changes from false to true, a request will be automatically triggered with the options.defaultParams parameter.
    • When manual=true, a request cannot be made as long as ready is false.
  5. run no longer returns a Promise. Use runAsync instead of the original run function.

  6. Users can wrap useRequest with useRequestProvider themselves.

useLoadMore API

Options

Name Description Type
manual When set to true, you need to manually trigger loadMore or loadMoreAsync to make a request. The default value is false. boolean
ready When manual=false, every time ready changes from false to true, refresh will be automatically triggered. When manual=true, a request cannot be made as long as ready is false. Ref<boolean> | () => boolean
refreshDeps Automatically trigger refresh when changed. If refreshDepsAction is set, refreshDepsAction will be triggered. WatchSource<any> | WatchSource<any>[]
refreshDepsAction Triggered when refreshDeps changes. () => void
debounceInterval Process the request with a debounce strategy. number | Ref<number>
debounceOptions Debounce parameters. {leading: false, maxWait: undefined, trailing: true}
throttleInterval Process the request with a throttle strategy. number | Ref<number>
throttleOptions Throttle parameters. {leading: false, trailing: true}
errorRetryCount The number of error retries when an error occurs. number | Ref<number>
errorRetryInterval The interval between error retries when an error occurs. number | Ref<number>
isNoMore Determines whether there is more data. (data?: R) => boolean
onBefore Triggered before service is executed. () => void
onAfter Triggered when service is completed. () => void
onSuccess Triggered when service is resolved. (data: R) => void
onError Triggered when service is rejected. (error: Error) => void

Result

Name Description Type
data The data returned by service, which must include an array list, of type { list: any[], ...other }. Ref<R>
dataList The list array of data. Ref<R['list']>
loading Whether a request is in progress. Ref<boolean>
loadingMore Whether more data is being loaded. Ref<boolean>
noMore Whether there is more data, which needs to be used with options.isNoMore. Ref<boolean>
error The error returned by service. Error
loadMore Load more data, automatically capture exceptions, and handle them through options.onError. () => void
loadMoreAsync Load more data, return Promise, and handle errors on your own. () => Promise<R>
refresh Refresh and load the first page of data, automatically capture exceptions, and handle them through options.onError. () => void
refreshAsync Refresh and load the first page of data, return Promise, and handle errors on your own. () => Promise<R>
mutate Directly modify the result of data. (arg: (oldData: R) => R) => void | (newData: R) => void
cancel Cancel the request. () => void

1.2.4 (2022-01-21)

Refactor

  • replacing IIFE with UMD modules (2f05be8)

1.2.3 (2021-10-12)

Bug Fixes

1.2.2 (2021-10-06)

Bug Fixes

  • Fix nullish operator is not transform

1.2.1 (2021-10-06)

Features

  • core: add throttle and debounce options #63 (decbbd3)

1.2.0 (2021-05-22)

Features

  • usePagination: add changePagination() to modify both current and pageSize #43 (c3822f0)
  • add onBefore() and onAfter() hooks #42 (135e76f)
  • add reloading to record the loading status of reload() #41 (5034f2c)

Performance Improvements

⚠ BREAKING CHANGES

1.1.1 (2021-04-28)

Bug Fixes

  • usePagination: defaultParams.current and defaultParams.pageSize should work if manual: true (3ca5fd7), closes #40

1.1.0 (2021-04-19)

Features

  • useLoadMore: refactor refresh and cancel of useLoadMore, add refreshing #36 (7c34351)

Bug Fixes

  • root level refresh, mutate, cancel not work with queryKey #37 (66b3198)

⚠ BREAKING CHANGES

  • useLoadMore: remove mutate of useLoadMore (b935bcd)

1.0.5 (2021-03-22)

Bug Fixes

1.0.4 (2021-03-08)

Bug Fixes

1.0.3 (2021-03-06)

Bug Fixes

  • concurrent request should have independent events (7511720)

Features

  • usePagination and useLoadMore support global config (8cceb1e)
  • usePagination: add reload function to reset paging info (def45e3)
  • useRequest: add reload function to clear the queries list (b64216b)

1.0.0-beta.11 (2021-03-03)

Features

1.0.0-beta.10 (2021-03-02)

⚠ BREAKING CHANGES

  • queries changed from shallowReactive to reactive (8f940a4)

1.0.0-beta.9 (2021-02-26)

⚠ BREAKING CHANGES

  • usePagination: does not support concurrent request (2c083ef)

Refactor

  • usePagination: current and pageSize can modify and can trigger request, means you can directly use v-model to bind them (ea5a238)

1.0.0-beta.8 (2021-02-24)

Features

1.0.0-beta.7 (2021-01-11)

Feature

  • add back off algorithm to errorRetryInterval (#19) 13ce153

1.0.0-beta.6 (2020-12-31)

Refactor

  • add isServer to be compatible with node env 4f1c797
  • modify the default value of cacheTime to 10 minutes a56ecb0

1.0.0-beta.5 (2020-12-14)

Bug Fixes

1.0.0-beta.4 (2020-12-07)