effex-monorepo
    Preparing search index...

    Variable Signal

    Signal: {
        Array: {
            make: <T>(
                initial?: readonly T[],
            ) => Effect<SignalArray<T>, never, Scope>;
        };
        equals: {
            <A>(
                f: (a: A, b: A) => boolean,
            ): (
                self: Effect<Signal<A>, never, Scope>,
            ) => Effect<Signal<A>, never, Scope>;
            <A>(
                self: Effect<Signal<A>, never, Scope>,
                f: (a: A, b: A) => boolean,
            ): Effect<Signal<A>, never, Scope>;
        };
        fromNullable: <A>(
            existing: Signal<A> | undefined,
            defaultValue: A,
        ) => Effect<Signal<A>, never, Scope>;
        fromReactive: <A>(
            value: A | Signal<A> | Readable.Readable<A> | undefined,
            defaultValue: A,
        ) => Effect<Signal<A>, never, Scope>;
        isSignal: (value: unknown) => value is Signal<unknown>;
        make: <A>(initial: A) => Effect<Signal<A>, never, Scope>;
        Map: {
            isSignalMap: (value: unknown) => value is SignalMap<unknown, unknown>;
            make: <K, V>(
                initial?: ReadonlyMap<K, V> | Iterable<readonly [K, V], any, any>,
            ) => Effect<SignalMap<K, V>, never, Scope>;
            SignalMapTypeId: symbol;
        };
        Set: {
            isSignalSet: (value: unknown) => value is SignalSet<unknown>;
            make: <T>(
                initial?: ReadonlySet<T> | Iterable<T, any, any>,
            ) => Effect<SignalSet<T>, never, Scope>;
            SignalSetTypeId: symbol;
        };
        SignalRegistry: typeof SignalRegistry;
        SignalTypeId: symbol;
        Struct: {
            isSignalStruct: (
                value: unknown,
            ) => value is SignalStruct<Record<string, unknown>>;
            make: <T extends Record<string, unknown>>(
                initial: T,
            ) => Effect<SignalStruct<T>, never, Scope>;
            SignalStructTypeId: symbol;
        };
    }

    Type Declaration

    • Array: { make: <T>(initial?: readonly T[]) => Effect<SignalArray<T>, never, Scope> }

      Create a reactive array with in-place mutation methods.

      SignalArray

      • make: <T>(initial?: readonly T[]) => Effect<SignalArray<T>, never, Scope>

        Create a new SignalArray with an optional initial value.

    • equals: {
          <A>(
              f: (a: A, b: A) => boolean,
          ): (
              self: Effect<Signal<A>, never, Scope>,
          ) => Effect<Signal<A>, never, Scope>;
          <A>(
              self: Effect<Signal<A>, never, Scope>,
              f: (a: A, b: A) => boolean,
          ): Effect<Signal<A>, never, Scope>;
      }

      Configure a custom equality function for a Signal. The equality function determines when updates are skipped (if values are "equal").

      // Compare users by id only
      const user = yield* Signal.make({ id: 1, name: "John" }).pipe(
      Signal.equals((a, b) => a.id === b.id)
      );

      // This won't trigger an update (same id)
      yield* user.set({ id: 1, name: "Johnny" });
    • fromNullable: <A>(
          existing: Signal<A> | undefined,
          defaultValue: A,
      ) => Effect<Signal<A>, never, Scope>

      Use an existing Signal if provided, otherwise create a new one with the default value. This enables the controlled/uncontrolled component pattern.

      // In a component that supports both controlled and uncontrolled modes:
      const value = yield* Signal.fromNullable(props.value, props.defaultValue ?? "");

      // If props.value is a Signal, it will be used directly
      // If props.value is undefined, a new Signal is created with defaultValue

      // With custom equality:
      const value = yield* Signal.fromNullable(props.value, defaultUser).pipe(
      Signal.equals((a, b) => a.id === b.id)
      );
    • fromReactive: <A>(
          value: A | Signal<A> | Readable.Readable<A> | undefined,
          defaultValue: A,
      ) => Effect<Signal<A>, never, Scope>

      Create a Signal from a reactive value (Signal, Readable, or plain value).

      • If input is already a Signal, returns it as-is
      • If input is a Readable, creates a new Signal initialized with the Readable's current value
      • If input is a plain value, creates a new Signal with that value

      This is useful for controlled/uncontrolled component patterns where a prop can be either a Signal (controlled), a Readable, or a plain value (uncontrolled).

      // In a component that accepts flexible input:
      interface CheckboxProps {
      checked?: Signal<boolean> | Readable<boolean> | boolean;
      defaultChecked?: boolean;
      }

      const Checkbox = (props: CheckboxProps) =>
      Effect.gen(function* () {
      // Works with Signal (controlled), Readable, or boolean (uncontrolled)
      const checked = yield* Signal.fromReactive(
      props.checked,
      props.defaultChecked ?? false
      );

      // With custom equality:
      const user = yield* Signal.fromReactive(props.user, defaultUser).pipe(
      Signal.equals((a, b) => a.id === b.id)
      );
      });
    • isSignal: (value: unknown) => value is Signal<unknown>

      Check if a value is a Signal.

    • make: <A>(initial: A) => Effect<Signal<A>, never, Scope>

      Create a new Signal with an initial value.

      // Basic usage
      const counter = yield* Signal.make(0);

      // With custom equality (pipeable)
      const user = yield* Signal.make({ id: 1, name: "John" }).pipe(
      Signal.equals((a, b) => a.id === b.id)
      );
    • Map: {
          isSignalMap: (value: unknown) => value is SignalMap<unknown, unknown>;
          make: <K, V>(
              initial?: ReadonlyMap<K, V> | Iterable<readonly [K, V], any, any>,
          ) => Effect<SignalMap<K, V>, never, Scope>;
          SignalMapTypeId: symbol;
      }

      Create a reactive Map with in-place mutation methods.

      SignalMap

      • isSignalMap: (value: unknown) => value is SignalMap<unknown, unknown>

        Check if a value is a SignalMap.

      • make: <K, V>(
            initial?: ReadonlyMap<K, V> | Iterable<readonly [K, V], any, any>,
        ) => Effect<SignalMap<K, V>, never, Scope>

        Create a new SignalMap with optional initial entries.

      • SignalMapTypeId: symbol
    • Set: {
          isSignalSet: (value: unknown) => value is SignalSet<unknown>;
          make: <T>(
              initial?: ReadonlySet<T> | Iterable<T, any, any>,
          ) => Effect<SignalSet<T>, never, Scope>;
          SignalSetTypeId: symbol;
      }

      Create a reactive Set with in-place mutation methods.

      SignalSet

      • isSignalSet: (value: unknown) => value is SignalSet<unknown>

        Check if a value is a SignalSet.

      • make: <T>(
            initial?: ReadonlySet<T> | Iterable<T, any, any>,
        ) => Effect<SignalSet<T>, never, Scope>

        Create a new SignalSet with optional initial values.

      • SignalSetTypeId: symbol
    • SignalRegistry: typeof SignalRegistry
    • SignalTypeId: symbol
    • Struct: {
          isSignalStruct: (
              value: unknown,
          ) => value is SignalStruct<Record<string, unknown>>;
          make: <T extends Record<string, unknown>>(
              initial: T,
          ) => Effect<SignalStruct<T>, never, Scope>;
          SignalStructTypeId: symbol;
      }

      Create a reactive struct with fixed keys, where each key is accessible as a Signal.

      SignalStruct

      • isSignalStruct: (value: unknown) => value is SignalStruct<Record<string, unknown>>

        Check if a value is a SignalStruct.

      • make: <T extends Record<string, unknown>>(
            initial: T,
        ) => Effect<SignalStruct<T>, never, Scope>

        Create a new SignalStruct with an initial value.

      • SignalStructTypeId: symbol