interface / @typed/fx

RefSubject.RefSubject.Service

Defines the service state contract.

Package version
2.0.0-beta.7
Category
Services
Since
1.18.0
Member of
RefSubject.RefSubject

Import

import { RefSubject } from "@typed/fx";

Access RefSubject.RefSubject.Service through the imported RefSubject export. Its declaration below describes the member.

This public exposure is a re-export. Its import path is supported; declaration documentation is shared with the other public exposures below.

Signatures

interface Service<Self, Id extends string, A, E> extends RefSubject<A, E, Self> {
    readonly id: Id;
    readonly service: Context.Service<Self, RefSubject<A, E>>;
    readonly make: <R = never>(value: A | Effect.Effect<A, E, R> | Fx<A, E, R>, options?: RefSubjectOptions<A> & {
        readonly skip?: number;
        readonly take?: number;
    }) => Layer.Layer<Self, never, Exclude<R, Scope.Scope>>;
    readonly layer: <E2, R2>(make: Effect.Effect<RefSubject<A, E>, E2, R2 | Scope.Scope>) => Layer.Layer<Self, E2, Exclude<R2, Scope.Scope>>;
}

Why

Describes the class-like facade returned by RefSubject.Service: it is a Context tag whose static members also implement current reads, Fx observation, and serialized writes.

Ownership and lifetime

The contract itself acquires nothing. A matching Layer owns the underlying RefSubject; using the facade requires Self, exposes the underlying E on reads and pushes, and forwards Scope ownership to that installed subject.

Property: id

Exposes id on the ref subject contract.

Property: id: Why

Preserves the literal Context identifier used to construct and diagnose the service tag.

Property: id: Ownership and lifetime

This declaration performs no acquisition and retains no resources. Implementations preserve source errors, services, and lifetime.

Property: layer

Exposes layer on the ref subject contract.

Property: layer: Why

Converts a scoped Effect that produces a RefSubject into the exact Layer required by the facade, preserving construction failures and non-Scope requirements.

Property: layer: Ownership and lifetime

Layer acquisition runs make once per Layer instance. Its Scope owns the installed subject; E2 is a Layer-construction failure, while the subject’s E remains on later state access.

Property: make

Exposes make on the ref subject contract.

Property: make: Why

Accepts values, Effects, Streams, and Fx through one renderer-independent state constructor while retaining their typed failures and services.

Property: make: Ownership and lifetime

The creation Effect requires Scope. It owns initializer acquisition, live source subscriptions, and cleanup; source failures and services stay on reads and pushes.

Property: service

Exposes service on the ref subject contract.

Property: service: Why

Exposes the exact Effect Context tag used by layer, make, and every static operation on the facade, so custom Layers can install an existing RefSubject without another wrapper.

Property: service: Ownership and lifetime

The tag is pure metadata and owns no state. The Layer that provides it owns the installed RefSubject and its scoped initializer; operations retrieving it require Self.

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source