Skip to content

⬅️ Back to Table of Contents

πŸ“„ watchTriggerable

πŸ“Š Analysis Summary

Metric Count
πŸ”§ Functions 7
πŸ“¦ Imports 9
πŸ“ Interfaces 1
πŸ“‘ Type Aliases 2

πŸ“š Table of Contents

πŸ› οΈ File Location:

πŸ“‚ packages/shared/watchTriggerable/index.ts

πŸ“¦ Imports

Name Source
MultiWatchSources vue
WatchSource vue
MapOldSources ../utils
MapSources ../utils
WatchIgnorableReturn ../watchIgnorable
WatchWithFilterOptions ../watchWithFilter
isReactive vue
toValue vue
watchIgnorable ../watchIgnorable

Functions

watchTriggerable(source: WatchSource<T>, cb: WatchTriggerableCallback<T, T | undefin…, options: WatchWithFilterOptions<boolean>): WatchTriggerableReturn<FnReturnT>

Parameters:

  • source WatchSource<T>
  • cb WatchTriggerableCallback<T, T | undefined, FnReturnT>
  • options WatchWithFilterOptions<boolean>

Returns: WatchTriggerableReturn<FnReturnT>

Code
export function watchTriggerable<T, FnReturnT>(
  source: WatchSource<T>,
  cb: WatchTriggerableCallback<T, T | undefined, FnReturnT>,
  options?: WatchWithFilterOptions<boolean>,
): WatchTriggerableReturn<FnReturnT>

getWatchSources(sources: any): any

Parameters:

  • sources any

Returns: any

Calls:

  • isReactive (from vue)
  • Array.isArray
  • sources.map
  • toValue (from vue)
Code
function getWatchSources(sources: any) {
  if (isReactive(sources))
    return sources
  if (Array.isArray(sources))
    return sources.map(item => toValue(item))
  return toValue(sources)
}

getOldValue(source: any): any[]

Parameters:

  • source any

Returns: any[]

Calls:

  • Array.isArray
  • source.map
Code
function getOldValue(source: any) {
  return Array.isArray(source)
    ? source.map(() => undefined)
    : undefined
}

Internal helpers

Declared inside another function in this file.

onEffect(): void

Returns: void

Calls:

  • fn
Code
function onEffect() {
    if (!cleanupFn)
      return

    const fn = cleanupFn
    cleanupFn = undefined
    fn()
  }

onCleanup(callback: () => void): void

Register the function cleanupFn

Raw JSDoc
/** Register the function `cleanupFn` */
Code
function onCleanup(callback: () => void) {
    cleanupFn = callback
  }

_cb(value: any, oldValue: any): any

Parameters:

  • value any
  • oldValue any

Returns: any

Calls:

  • onEffect
  • cb

Internal Comments:

// When a new side effect occurs, clean up the previous side effect (x3)

Code
(
    value: any,
    oldValue: any,
  ) => {
    // When a new side effect occurs, clean up the previous side effect
    onEffect()

    return cb(value, oldValue, onCleanup)
  }

trigger(): any

Returns: any

Calls:

  • ignoreUpdates
  • _cb
  • getWatchSources
  • getOldValue
Code
() => {
    let res: any
    ignoreUpdates(() => {
      res = _cb(getWatchSources(source), getOldValue(source))
    })
    return res
  }

Interfaces

WatchTriggerableReturn<FnReturnT = void>

Interface Code
export interface WatchTriggerableReturn<FnReturnT = void> extends WatchIgnorableReturn {
  /** Execute `WatchCallback` immediately */
  trigger: () => FnReturnT
}

Properties

Name Type Optional Description
trigger () => FnReturnT βœ— not shown

Type Aliases

OnCleanup

type OnCleanup = (cleanupFn: () => void) => void;

WatchTriggerableCallback<V = any, OV = any, R = void>

type WatchTriggerableCallback<V = any, OV = any, R = void> = (value: V, oldValue: OV, onCleanup: OnCleanup) => R;

Generated by Syntax Scribe