vue-wait icon indicating copy to clipboard operation
vue-wait copied to clipboard

add delay option

Open coun7zero opened this issue 8 years ago • 0 comments

Sometimes the response is too fast (e.g. cache) so delay is good solution to avoid loading spinner if that's shows only for few milliseconds.

Here is my util fot that:

import { createActionHelpers } from 'vuex-loading'

import { delay } from 'lodash/function'

export function createDelayedLoading (options, wait = 1) {
  let actionHelpers = createActionHelpers(options)
  let { startLoading: startLoadingFn, endLoading: endLoadingFn } = actionHelpers
  if (wait) {
    let delayed = null
    actionHelpers = {
      startLoading: (dispatcher, loader, callback) => {
        delayed = delay(() => {
          startLoadingFn(dispatcher, loader, callback)
        }, wait)
      },
      endLoading: (dispatcher, loader) => {
        clearTimeout(delayed)
        endLoadingFn(dispatcher, loader)
      }
    }
  }
  return actionHelpers
}

What do you think about adding something similar to the project?

coun7zero avatar Feb 01 '18 13:02 coun7zero