mini-effect
    Preparing search index...

    Function dependency

    • Creates a typed dependency tag that represents a value your effects need at runtime.

      Type Parameters

      • D extends string

        A string literal type used as the dependency's unique tag

      Parameters

      • tag: D

        A unique string identifier for this dependency

      Returns <T>() => Dependency<D, T>

      A function that, when called with a type parameter <T>(), returns a Dependency<D, T> instance

      dependency is a curried factory: the first call accepts the tag string, and the second call (with a type parameter) produces a Dependency instance. Use yield* inside gen to read the dependency's value, and call Dependency.provide to supply it before execution.

      If a dependency is not provided before the effect is run, the effect will fail with Error("Missing dependency: <tag>").

      import { dependency, gen, run } from "mini-effect";

      const UserName = dependency("UserName")<string>();

      const sayHello = gen(function* () {
      const name = yield* UserName;
      return `Hello, ${name}`;
      });

      const result = await run(sayHello.pipe(UserName.provide("Alice")));
      // => "Hello, Alice"