Skip to content

Commit

Permalink
feat(useImage): use computed ref (#1776)
Browse files Browse the repository at this point in the history
  • Loading branch information
guangzan committed Jul 7, 2022
1 parent 0284aac commit 07aa510
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions packages/core/useImage/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { MaybeRef } from '@vueuse/shared'

import { unref, watch } from 'vue-demi'

import { watch } from 'vue-demi'
import type { MaybeComputedRef } from '@vueuse/shared'
import { resolveUnref } from '@vueuse/shared'
import type { AsyncStateOptions } from '../useAsyncState'
import { useAsyncState } from '../useAsyncState'

Expand Down Expand Up @@ -38,11 +37,11 @@ async function loadImage(options: UseImageOptions): Promise<HTMLImageElement> {
* @param asyncStateOptions
*/
export const useImage = <Shallow extends true>(
options: MaybeRef<UseImageOptions>,
options: MaybeComputedRef<UseImageOptions>,
asyncStateOptions: AsyncStateOptions<Shallow> = {},
) => {
const state = useAsyncState<HTMLImageElement | undefined>(
() => loadImage(unref(options)),
() => loadImage(resolveUnref(options)),
undefined,
{
resetOnExecute: true,
Expand All @@ -51,7 +50,7 @@ export const useImage = <Shallow extends true>(
)

watch(
() => unref(options),
() => resolveUnref(options),
() => state.execute(asyncStateOptions.delay),
{ deep: true },
)
Expand Down

0 comments on commit 07aa510

Please sign in to comment.