Options
All
  • Public
  • Public/Protected
  • All
Menu

A simple event framework used throughout Foundry Virtual Tabletop. When key actions or events occur, a "hook" is defined where user-defined callback functions can execute. This class manages the registration and execution of hooked callback functions.

Hierarchy

  • Hooks

Index

Constructors

Accessors

Methods

Properties

Constructors

Accessors

  • get events(): any
  • A mapping of hook events which have functions registered to them.

    Returns any

Methods

  • on(hook: string, fn: Function, options?: { once: boolean }): number
  • Register a callback handler which should be triggered when a hook is triggered.

    Parameters

    • hook: string

      The unique name of the hooked event

    • fn: Function

      The callback function which should be triggered when the hook event occurs

    • options: { once: boolean } = {}

      Options which customize hook registration

      • once: boolean

        Only trigger the hooked function once

    Returns number

    An ID number of the hooked function which can be used to turn off the hook later

  • once(hook: string, fn: Function): number
  • Register a callback handler for an event which is only triggered once the first time the event occurs. An alias for Hooks.on with {once: true}

    Parameters

    • hook: string

      The unique name of the hooked event

    • fn: Function

      The callback function which should be triggered when the hook event occurs

    Returns number

    An ID number of the hooked function which can be used to turn off the hook later

  • off(hook: string, fn: number | Function): void
  • Unregister a callback handler for a particular hook event

    Parameters

    • hook: string

      The unique name of the hooked event

    • fn: number | Function

      The function, or ID number for the function, that should be turned off

    Returns void

  • callAll(hook: string, ...args: any[]): boolean
  • Call all hook listeners in the order in which they were registered Hooks called this way can not be handled by returning false and will always trigger every hook callback.

    Parameters

    • hook: string

      The hook being triggered

    • Rest ...args: any[]

      Arguments passed to the hook callback functions

    Returns boolean

    Were all hooks called without execution being prevented?

  • call(hook: string, ...args: any[]): boolean
  • Call hook listeners in the order in which they were registered. Continue calling hooks until either all have been called or one returns false.

    Hook listeners which return false denote that the original event has been adequately handled and no further hooks should be called.

    Parameters

    • hook: string

      The hook being triggered

    • Rest ...args: any[]

      Arguments passed to the hook callback functions

    Returns boolean

    Were all hooks called without execution being prevented?

  • onError(location: string, error: Error, [options={}]?: { msg: string; log: string; notify: string; data: any }): void
  • Notify subscribers that an error has occurred within foundry.

    Parameters

    • location: string

      The method where the error was caught.

    • error: Error

      The error.

    • [options={}]: { msg: string; log: string; notify: string; data: any } = {}

      Additional options to configure behaviour.

      • msg: string
      • log: string
      • notify: string
      • data: any

    Returns void

  • Call a hooked function using provided arguments and perhaps unregister it.

    Parameters

    • entry: HookedFunction

      The hooked function entry

    • args: any[]

      Arguments to be passed

    Returns any

Properties

#ids: Map<number, HookedFunction> = ...

A mapping of hooked functions by their assigned ID

#id: number = 1

An incrementing counter for assigned hooked function IDs