@metreeca/core - v0.9.17
    Preparing search index...

    Interface Relay<O>

    Relay.

    Accepts handlers for each option and returns the result from the matched handler. Four usage patterns are supported:

    • Some options without fallback: provide handlers for some options only, returns R | undefined
    • Some options with fallback: provide handlers for some options plus a fallback, returns R
    • All options handled: provide a handler for every option, returns R
    • All options with fallback: provide all handlers plus a fallback for delegation, returns R

    When a fallback is provided, handlers receive a delegate function to invoke it.

    Type Parameters

    • O extends Options

      The options type defining all possible option variants

    • Handles some options without a fallback.

      Type Parameters

      • R

        The return type of all handlers

      Parameters

      • handlers: Partial<Handlers<O, R>>

        Partial mapping of option keys to handlers

      Returns R | undefined

      The result from the matched handler, or undefined if no handler matched

    • Handles some options with a fallback handler for unmatched options.

      Handlers receive a delegate function that can be called to invoke the fallback.

      Type Parameters

      • R

        The return type of all handlers

      Parameters

      • handlers: Partial<Handlers<O, R, () => R>>

        Partial mapping of option keys to delegating handlers

      • fallback: Handler<O[keyof O], R>

        Fallback handler receiving union of option values

      Returns R

      The result from the matched handler or fallback

    • Handles all options with complete handlers.

      Type Parameters

      • R

        The return type of all handlers

      Parameters

      • handlers: Handlers<O, R>

        Mapping of all option keys to their handlers

      Returns R

      The result from the matched handler

    • Handles all options with complete handlers and a fallback for delegation.

      Handlers receive a delegate function that can be called to invoke the fallback, enabling factored common logic across multiple option handlers.

      Type Parameters

      • R

        The return type of all handlers

      Parameters

      • handlers: Handlers<O, R, () => R>

        Mapping of all option keys to delegating handlers

      • fallback: Handler<O[keyof O], R>

        Fallback handler for delegated calls

      Returns R

      The result from the matched handler or fallback