Skip to content
On this page

watchAtMost

watch有触发次数。

用法

类似于watch,带有一个额外的选项count,用于设置触发回调函数的次数。达到计数后,watch将自动停止。

ts
import { watchAtMost } from '@mpxjs/mpxuse-core'

watchAtMost(
  source,
  () => { console.log('trigger!') }, // triggered it at most 3 times
  {
    count: 3, // the number of times triggered
  },
)
import { watchAtMost } from '@mpxjs/mpxuse-core'

watchAtMost(
  source,
  () => { console.log('trigger!') }, // triggered it at most 3 times
  {
    count: 3, // the number of times triggered
  },
)

类型声明

typescript
export interface WatchAtMostOptions extends WatchWithFilterOptions {
  count: MaybeComputedRef<number>
}
export interface WatchAtMostReturn {
  stop: WatchStopHandle
  count: Ref<number>
}
export declare function watchAtMost<
  T extends Readonly<WatchSource<unknown>[]>,
  Immediate extends Readonly<boolean> = false
>(
  sources: [...T],
  cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>,
  options: WatchAtMostOptions
): WatchAtMostReturn
export declare function watchAtMost<
  T,
  Immediate extends Readonly<boolean> = false
>(
  sources: WatchSource<T>,
  cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
  options: WatchAtMostOptions
): WatchAtMostReturn
export interface WatchAtMostOptions extends WatchWithFilterOptions {
  count: MaybeComputedRef<number>
}
export interface WatchAtMostReturn {
  stop: WatchStopHandle
  count: Ref<number>
}
export declare function watchAtMost<
  T extends Readonly<WatchSource<unknown>[]>,
  Immediate extends Readonly<boolean> = false
>(
  sources: [...T],
  cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>,
  options: WatchAtMostOptions
): WatchAtMostReturn
export declare function watchAtMost<
  T,
  Immediate extends Readonly<boolean> = false
>(
  sources: WatchSource<T>,
  cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
  options: WatchAtMostOptions
): WatchAtMostReturn

源码

源码文档

贡献者

pagnkelly

更新日志

No recent changes

根据MIT许可证发布。