Function map

  • Creates a ComputedKey to provide a resource based on other dependencies.

    Type Parameters

    Parameters

    • src: K

      The dependency to which transform will be applied

    • transform: ((deps) => T)

      A function that will be called when the ComputedKey is requested. src will resolved first to provide the input to the function

        • (deps): T
        • Parameters

          Returns T

    Returns Map<T, K, G>

    A ComputedKey that resolves to the result of applying src to transform

    Example

    Providing a default injection for a class:

    class User {
    name: string; id: number
    constructor(name: string, id: number) {
    this.name = name; this.id = id
    }

    static inject = Inject.map({
    name: NameKey,
    id: IdKey,
    }, ({ name, id }) => new User(name, id))
    }

    See

    TypeKey.Map, ComputedKey.Map, Injectable.Map

Generated using TypeDoc