Module

AtomMachine

View source

Atom bridge for running machines.

Since v0.4.0 22 declarations ./unstable/reactivity/AtomMachine

Combinators

7
#

can

variable
Source
declare const can: {
  <Input>(event: Atom<Input>): CanProjection<Input>;
  <Input>(event: Input): CanProjection<Input>;
}

Reactively tests whether a concrete event would be accepted by a running machine.

Declare the returned projection once, then apply it to compatible machine bridges. Repeated applications to the same bridge return the same atom. An event atom is read reactively when acceptance depends on a changing payload.

Startup remains in the source AsyncResult. Active snapshots use Machine.can; done and stopped snapshots produce false, while runtime and schema failures remain in the typed failure channel.

Example typescript
const submitAllowed = AtomMachine.can(AuthEvents.Submitted())
const canSubmitAtom = submitAllowed(authMachineAtom)

const submitEvent = Atom.map(draftAtom, (draft) =>
  AuthEvents.Submitted({ draft }))
const reactiveSubmitAllowed = AtomMachine.can(submitEvent)
Since v0.31.0
#

matches

variable
Source
declare const matches: {
  <State extends AtomicSnapshot<string, unknown> = never, Event = never, Error = never, Output = never, StartError = never, Emitted = never, Path extends never = Path<State>>(path: Path): SelectorProjection<"matches", Path> & (self: MachineAtom<State, Event, Error, Output, StartError, Emitted>) => Atom<AsyncResult<boolean, Error | StartError>>;
  <Path extends string>(path: Path): SelectorProjection<"matches", Path> & <State extends AtomicSnapshot<string, unknown>, Event, Error, Output, StartError, Emitted>(self: MachineAtom<State, Event, Error, Output, StartError, Emitted> & EnsureSelectorPath<State, Path>) => Atom<AsyncResult<boolean, Error | StartError>>;
  <State extends AtomicSnapshot<string, unknown>, Event, Error, Output, StartError, Emitted, Path extends never>(self: MachineAtom<State, Event, Error, Output, StartError, Emitted>, path: Path): Atom<AsyncResult<boolean, Error | StartError>>;
}

Returns whether a state path is active.

Valid paths are inferred from the bridge snapshot. The derived atom suppresses equal updates. Repeated calls with the same bridge and path return the same atom. Runtime failures remain in the typed failure channel.

Example typescript
import { Machine } from "@typeonce/effect-machine"
import { AtomMachine } from "@typeonce/effect-machine/reactivity"
import { Schema } from "effect"
class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
}
const States = Machine.state({ states: { Idle } })
const machine = Machine.make({
  root: States,
  events: Machine.eventsFromSchemas()
}).handle({
  initial: {
    target: "Idle"
  },
  states: {
    Idle: {}
  }
})
const machineAtom = AtomMachine.make(machine)
const isIdleAtom = AtomMachine.matches(machineAtom, "Idle")
Since v0.4.0
#

matchesChild

variable
Source
declare const matchesChild: {
  <Child extends Any = never, StartError = never, Path extends never = Path<ChildState<Child>>>(path: Path): SelectorProjection<"matchesChild", Path> & (self: ChildMachineAtom<Child, StartError>) => Atom<AsyncResult<boolean, StartError | RefError<Ref<Child>>>>;
  <Path extends string>(path: Path): SelectorProjection<"matchesChild", Path> & <Child extends Any, StartError>(self: ChildMachineAtom<Child, StartError> & EnsureSelectorPath<ChildState<Child>, Path>) => Atom<AsyncResult<boolean, StartError | RefError<Ref<Child>>>>;
  <Child extends Any, StartError, Path extends never>(self: ChildMachineAtom<Child, StartError>, path: Path): Atom<AsyncResult<boolean, StartError | RefError<Ref<Child>>>>;
}

Returns whether a state path is active in a directly owned child.

Valid paths are inferred from the child bridge snapshot. An inactive child produces false. Repeated calls with the same child bridge and path return the same atom.

Since v0.4.0
#

select

variable
Source
declare const select: {
  <State extends AtomicSnapshot<string, unknown> = never, Event = never, Error = never, Output = never, StartError = never, Emitted = never, Path extends never = ValuedSnapshotIdentifier<State>>(path: Path): SelectorProjection<"select", Path> & (self: MachineAtom<State, Event, Error, Output, StartError, Emitted>) => Atom<AsyncResult<Option<SnapshotValueByIdentifier<State, Path>>, Error | StartError>>;
  <Path extends string>(path: Path): SelectorProjection<"select", Path> & <State extends AtomicSnapshot<string, unknown>, Event, Error, Output, StartError, Emitted>(self: MachineAtom<State, Event, Error, Output, StartError, Emitted> & EnsureValuedSelectorPath<State, Path>) => Atom<AsyncResult<Option<SnapshotValueByIdentifier<State, Extract<Path, ValuedSnapshotIdentifier<State>>>>, Error | StartError>>;
  <State extends AtomicSnapshot<string, unknown>, Event, Error, Output, StartError, Emitted, Path extends never>(self: MachineAtom<State, Event, Error, Output, StartError, Emitted>, path: Path): Atom<AsyncResult<Option<SnapshotValueByIdentifier<State, Path>>, Error | StartError>>;
}

Selects the typed value for an active state path.

Valid paths and their selected value types are inferred from the bridge. The derived atom suppresses structurally equal updates. Repeated calls with the same bridge and path return the same atom.

Example typescript
import { Machine } from "@typeonce/effect-machine"
import { AtomMachine } from "@typeonce/effect-machine/reactivity"
import { Schema } from "effect"
class Count extends Schema.TaggedClass<Count>("Count")("Count", {
  value: Schema.Number
}) {
}
const States = Machine.state({ states: { Count } })
const machine = Machine.make({
  root: States,
  events: Machine.eventsFromSchemas()
}).handle({
  initial: {
    target: "Count",
    decoded: true,
    data: new Count({ value: 0 })
  },
  states: {
    Count: {}
  }
})
const machineAtom = AtomMachine.make(machine)
const countAtom = AtomMachine.select(machineAtom, "Count")
Since v0.4.0
#

selectChild

variable
Source
declare const selectChild: {
  <Path extends string = never>(path: NoInfer<Path>): SelectorProjection<"selectChild", Path> & <Child extends Any, StartError>(self: ChildMachineAtom<Child, StartError> & EnsureValuedSelectorPath<ChildState<Child>, Path>) => Atom<AsyncResult<Option<SnapshotValueByIdentifier<ChildState<Child>, Extract<Path, ValuedSnapshotIdentifier<ChildState<Child>>>>>, StartError | RefError<Ref<Child>>>>;
  <Path extends string>(path: Path): SelectorProjection<"selectChild", Path> & <Child extends Any, StartError>(self: ChildMachineAtom<Child, StartError> & EnsureValuedSelectorPath<ChildState<Child>, Path>) => Atom<AsyncResult<Option<SnapshotValueByIdentifier<ChildState<Child>, Extract<Path, ValuedSnapshotIdentifier<ChildState<Child>>>>>, StartError | RefError<Ref<Child>>>>;
  <Child extends Any, StartError, Path extends never>(self: ChildMachineAtom<Child, StartError>, path: Path): Atom<AsyncResult<Option<SnapshotValueByIdentifier<ChildState<Child>, Path>>, StartError | RefError<Ref<Child>>>>;
}

Selects the typed value for an active state path in a directly owned child.

Valid paths and their selected value types are inferred from the child bridge. An inactive child produces Option.none(). Repeated calls with the same child bridge and path return the same atom.

Example typescript
const editingAtom = AtomMachine.selectChild(editorAtom, "Editing")
// Atom<AsyncResult<Option<Editing>, StartError | ChildRuntimeError>>
Since v0.4.0
#

selectSnapshot

variable
Source
declare const selectSnapshot: {
  <State extends AtomicSnapshot<string, unknown> = never, Event = never, Error = never, Output = never, StartError = never, Emitted = never, Path extends never = Path<State>>(path: Path): SelectorProjection<"selectSnapshot", Path> & (self: MachineAtom<State, Event, Error, Output, StartError, Emitted>) => Atom<AsyncResult<Option<SnapshotByIdentifier<State, Path>>, Error | StartError>>;
  <Path extends string>(path: Path): SelectorProjection<"selectSnapshot", Path> & <State extends AtomicSnapshot<string, unknown>, Event, Error, Output, StartError, Emitted>(self: MachineAtom<State, Event, Error, Output, StartError, Emitted> & EnsureSelectorPath<State, Path>) => Atom<AsyncResult<Option<SnapshotByIdentifier<State, Extract<Path, Path<State>>>>, Error | StartError>>;
  <State extends AtomicSnapshot<string, unknown>, Event, Error, Output, StartError, Emitted, Path extends never>(self: MachineAtom<State, Event, Error, Output, StartError, Emitted>, path: Path): Atom<AsyncResult<Option<SnapshotByIdentifier<State, Path>>, Error | StartError>>;
}

Selects the typed logical snapshot for an active state path.

Unlike select, the selected value retains its child snapshot topology. The derived atom suppresses structurally equal updates. Repeated calls with the same bridge and path return the same atom.

Since v0.7.0
#

selectSnapshotChild

variable
Source
declare const selectSnapshotChild: {
  <Child extends Any = never, StartError = never, Path extends never = Path<ChildState<Child>>>(path: Path): SelectorProjection<"selectSnapshotChild", Path> & (self: ChildMachineAtom<Child, StartError>) => Atom<AsyncResult<Option<SnapshotByIdentifier<ChildState<Child>, Path>>, StartError | RefError<Ref<Child>>>>;
  <Path extends string>(path: Path): SelectorProjection<"selectSnapshotChild", Path> & <Child extends Any, StartError>(self: ChildMachineAtom<Child, StartError> & EnsureSelectorPath<ChildState<Child>, Path>) => Atom<AsyncResult<Option<SnapshotByIdentifier<ChildState<Child>, Extract<Path, Path<ChildState<Child>>>>>, StartError | RefError<Ref<Child>>>>;
  <Child extends Any, StartError, Path extends never>(self: ChildMachineAtom<Child, StartError>, path: Path): Atom<AsyncResult<Option<SnapshotByIdentifier<ChildState<Child>, Path>>, StartError | RefError<Ref<Child>>>>;
}

Selects the typed logical snapshot for an active state path in an invoked child.

An inactive child or state path produces Option.none(). Unlike selectChild, the selected value retains its child snapshot topology. The derived atom suppresses structurally equal updates. Repeated calls with the same child bridge and path return the same atom.

Since v0.7.0

Constructors

6
#

bind

variable
Source
declare const bind: <Services, RuntimeError>(runtime: Atom.AtomRuntime<Services, RuntimeError>) => Bound<Services, RuntimeError>

Binds AtomMachine constructors to a shared Effect runtime.

Use this when an application runs many machines from the same service layer. The returned interface keeps runtime provisioning at the composition seam, while every call to make or a specialized factory still creates an independent machine bridge.

Since v0.4.0
#

factory

variable
Source
declare const factory: <M extends Machine.Machine.Any>(machine: M & EnsureNoExternalRequirements<MachineRequirementsOf<NoInfer<M>>> & EnsureMachineExecutable<NoInfer<M>> & Machine.Machine.RootCompatible<Machine.Machine.ParentEvents<NoInfer<M>>>) => (...args: MachineInputArgsOf<M>) => MachineAtomOf<M, never>

Specializes a machine definition into a reusable bridge constructor.

The returned function preserves the machine's startup input arity and exact bridge type. Every call creates a fresh MachineAtom; it does not cache by input or start the machine before an AtomRegistry reads or mounts it.

Example typescript
const makeSearchMachine = AtomMachine.factory(searchMachine)
const search = makeSearchMachine({ query: "effect" })

type SearchMachineAtom = ReturnType<typeof makeSearchMachine>
Since v0.30.0
#

family

variable
Source
declare const family: <M extends Machine.Machine.Any, Projections extends FamilyProjectionRecord<MachineAtomOf<NoInfer<M>, never>, RootFamilySelectorProjection<Machine.Machine.Snapshot<Machine.Machine.States<NoInfer<M>>>>>>(machine: M & EnsureNoExternalRequirements<MachineRequirementsOf<NoInfer<M>>> & EnsureMachineExecutable<NoInfer<M>> & Machine.Machine.RootCompatible<Machine.Machine.ParentEvents<NoInfer<M>>> & EnsureFamilyInput<NoInfer<M>>, options: FamilyOptions<Machine.Machine.Input<NoInfer<M>>, MachineAtomOf<NoInfer<M>, never>, Projections>) => FamilyAtoms<Machine.Machine.Input<M>, MachineAtomOf<M, never>, Projections>

Creates retained atom families for independent machine inputs.

The machine input is both startup input and family identity. Each property in atoms projects one public atom family from a private machine bridge. Retaining any projected atom retains that bridge without keeping its registry runtime mounted. Keys follow Effect Equal and Hash semantics. The optional label function labels each public projected atom.

Example typescript
const processAtoms = AtomMachine.family(processMachine, {
  atoms: {
    ready: AtomMachine.matches("Ready"),
    state: (machine) => machine.result,
    send: (machine) => machine.send
  }
})

const readyAtom = processAtoms.ready("effect")
const sendAtom = processAtoms.send("effect")
Since v0.28.0
#

familyChild

variable
Source
declare const familyChild: <Key, Parent extends MachineAtom<any, never, any, any, any, any> | ChildMachineAtom<any, any>, Child extends Machine.ChildMachine.Any, Projections extends FamilyProjectionRecord<ChildOf<Parent, NoInfer<Child>>, ChildFamilySelectorProjection<NoInfer<Child>>>>(parent: Parent, options: {
  readonly atoms: Projections;
  readonly child: (key: Key) => Child;
  readonly label?: (key: Key, atomName: keyof Projections & string) => string | undefined;
}) => FamilyAtoms<Key, ChildOf<Parent, Child>, Projections>

Creates retained atom families for keyed direct-child lookup.

The child function maps each family key to one direct child descriptor. Every projected atom retains the resulting child bridge while the projected atom remains reachable. Keys follow Effect Equal and Hash semantics.

Example typescript
const Plant = Machine.childFamily(plantMachine)

const plantAtoms = AtomMachine.familyChild(parentMachineAtom, {
  child: (plantId: string) => Plant(plantId),
  atoms: {
    broken: AtomMachine.matchesChild("Broken"),
    state: (child) => child.result,
    send: (child) => child.send
  }
})
Since v0.28.0
#

make

variable
Source
declare const make: <States extends Readonly<Record<string, TaggedSchema | StateNodeConfig>>, Events extends readonly Array<TaggedSchema>, Emits extends readonly Array<TaggedSchema> = any, Input extends Top = Void, UnhandledStates extends string = StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends string = never, Output = never, OutputStates extends string = never, InputEvents extends readonly Array<TaggedSchema> = Events, ParentEvents extends readonly Array<TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents> & EnsureNoExternalRequirements<MachineRequirements<InitialR, R, EventOf<Events>, EmittedEventOf<Emits>>> & EnsureOutputImplementations<States, OutputStates> & EnsureHistoryImplementations<States, UnhandledStates> & EnsureInitialImplementations<States, UnhandledStates> & RootCompatible<ParentEvents>, ...args: [...Array<InputArgs<Input>>]) => MachineAtom<Snapshot<States>, EventInputOf<InputEvents>, MachineRuntimeError<E, R>, Output, MachineStartError<InitialE, E, InitialR, R, never>, EmittedEventOf<Emits>>

Creates atoms backed by a running machine.

Use bind(runtime).make(machine) when the machine requires external services.

Example typescript
import { Machine } from "@typeonce/effect-machine"
import { AtomMachine } from "@typeonce/effect-machine/reactivity"
import { Schema } from "effect"
class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
}
const States = Machine.state({ states: { Idle } })
const machine = Machine.make({
  root: States,
  events: Machine.eventsFromSchemas()
}).handle({
  initial: {
    target: "Idle"
  },
  states: {
    Idle: {}
  }
})
const machineAtom = AtomMachine.make(machine)
Since v0.4.0
#

resume

variable
Source
declare const resume: <M extends Any>(machine: M & EnsureNoExternalRequirements<MachineResumeRequirementsOf<NoInfer<M>>> & EnsureMachineExecutable<NoInfer<M>> & RootCompatible<ParentEvents<NoInfer<M>>>, snapshot: Snapshot<States<M>>) => ResumedMachineAtomOf<M, never>

Creates a lazy atom bridge from a decoded logical snapshot.

The bridge owns one freshly resumed runtime per AtomRegistry, with the same lazy start and disposal semantics as make. The machine initial function and its input, errors, and services are not involved.

Since v0.4.0

Errors

2
#

ChildNotActiveError

class
Source
declare class ChildNotActiveError extends YieldableError<this> & {
  readonly _tag: "ChildNotActiveError";
} & Readonly<{
  readonly id: string;
}> {
  constructor(args: {
    readonly id: string;
  });
  readonly _tag: "ChildNotActiveError";
  readonly ~effect/Effect: Variance<never, ChildNotActiveError, never>;
  readonly ~effect/ErrorReporter/attributes?: ReadonlyRecord<string, unknown>;
  readonly ~effect/ErrorReporter/ignore?: boolean;
  readonly ~effect/ErrorReporter/severity?: Severity;
  cause?: unknown;
  readonly id: string;
  message: string;
  name: string;
  stack?: string;
  [iterator](): EffectIterator<Effect<never, ChildNotActiveError, never>>;
  [NodeInspectSymbol](): unknown;
  pipe<A>(this: A): A;
  pipe<A, B = never>(this: A, ab: (_: A) => B): B;
  pipe<A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C;
  pipe<A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D;
  pipe<A, B = never, C = never, D = never, E = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E): E;
  pipe<A, B = never, C = never, D = never, E = never, F = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F): F;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G): G;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H): H;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I): I;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J): J;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K): K;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L): L;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M): M;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N): N;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O): O;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never, P = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O, op: (_: O) => P): P;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never, P = never, Q = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O, op: (_: O) => P, pq: (_: P) => Q): Q;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never, P = never, Q = never, R = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O, op: (_: O) => P, pq: (_: P) => Q, qr: (_: Q) => R): R;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never, P = never, Q = never, R = never, S = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O, op: (_: O) => P, pq: (_: P) => Q, qr: (_: Q) => R, rs: (_: R) => S): S;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never, P = never, Q = never, R = never, S = never, T = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O, op: (_: O) => P, pq: (_: P) => Q, qr: (_: Q) => R, rs: (_: R) => S, st: (_: S) => T): T;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never, P = never, Q = never, R = never, S = never, T = never, U = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O, op: (_: O) => P, pq: (_: P) => Q, qr: (_: Q) => R, rs: (_: R) => S, st: (_: S) => T, tu: (_: T) => U): U;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never, P = never, Q = never, R = never, S = never, T = never, U = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O, op: (_: O) => P, pq: (_: P) => Q, qr: (_: Q) => R, rs: (_: R) => S, st: (_: S) => T, tu: (_: T) => U): U;
  toJSON(): unknown;
  toString(): string;
}

Error returned when a command targets a child machine that is not active.

Since v0.4.0
#

NotReadyError

class
Source
declare class NotReadyError extends YieldableError<this> & {
  readonly _tag: "NotReadyError";
} & Readonly<{}> {
  constructor(args: void);
  readonly _tag: "NotReadyError";
  readonly ~effect/Effect: Variance<never, NotReadyError, never>;
  readonly ~effect/ErrorReporter/attributes?: ReadonlyRecord<string, unknown>;
  readonly ~effect/ErrorReporter/ignore?: boolean;
  readonly ~effect/ErrorReporter/severity?: Severity;
  cause?: unknown;
  message: string;
  name: string;
  stack?: string;
  [iterator](): EffectIterator<Effect<never, NotReadyError, never>>;
  [NodeInspectSymbol](): unknown;
  pipe<A>(this: A): A;
  pipe<A, B = never>(this: A, ab: (_: A) => B): B;
  pipe<A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C;
  pipe<A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D;
  pipe<A, B = never, C = never, D = never, E = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E): E;
  pipe<A, B = never, C = never, D = never, E = never, F = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F): F;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G): G;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H): H;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I): I;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J): J;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K): K;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L): L;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M): M;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N): N;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O): O;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never, P = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O, op: (_: O) => P): P;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never, P = never, Q = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O, op: (_: O) => P, pq: (_: P) => Q): Q;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never, P = never, Q = never, R = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O, op: (_: O) => P, pq: (_: P) => Q, qr: (_: Q) => R): R;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never, P = never, Q = never, R = never, S = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O, op: (_: O) => P, pq: (_: P) => Q, qr: (_: Q) => R, rs: (_: R) => S): S;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never, P = never, Q = never, R = never, S = never, T = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O, op: (_: O) => P, pq: (_: P) => Q, qr: (_: Q) => R, rs: (_: R) => S, st: (_: S) => T): T;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never, P = never, Q = never, R = never, S = never, T = never, U = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O, op: (_: O) => P, pq: (_: P) => Q, qr: (_: Q) => R, rs: (_: R) => S, st: (_: S) => T, tu: (_: T) => U): U;
  pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never, P = never, Q = never, R = never, S = never, T = never, U = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O, op: (_: O) => P, pq: (_: P) => Q, qr: (_: Q) => R, rs: (_: R) => S, st: (_: S) => T, tu: (_: T) => U): U;
  toJSON(): unknown;
  toString(): string;
}

Error returned when a machine command is issued before startup completes.

Since v0.4.0

Getters

3
#

childEmissions

variable
Source
declare const childEmissions: <Child extends Machine.ChildMachine.Any, StartError>(self: ChildMachineAtom<Child, StartError>) => Stream.Stream<RefEmitted<Machine.ChildMachine.Ref<Child>>, StartError, AtomRegistry.AtomRegistry>

Observes emissions from each active instance selected by a child bridge.

Since v0.10.0
#

emissions

variable
Source
declare const emissions: <State, Event, Error, Output, StartError, Emitted>(self: MachineAtom<State, Event, Error, Output, StartError, Emitted>) => Stream.Stream<Emitted, StartError, AtomRegistry.AtomRegistry>

Observes ephemeral notifications from the running machine owned by a machine atom. When this stream activates a fresh bridge, it subscribes before machine initialization and observes initial-entry emissions. It never replays emissions from a machine that was already running.

Since v0.10.0
#

inspection

variable
Source
declare const inspection: <State, Event, Error, Output, StartError, Emitted>(self: MachineAtom<State, Event, Error, Output, StartError, Emitted>) => Stream.Stream<Machine.Inspection.Event, StartError, AtomRegistry.AtomRegistry>

Observes the ordered local inspection records for the machine atom's root ownership tree. The stream starts before machine initialization, is hot and non-replayed, and completes with the root machine.

Since v0.13.0

Models

3
#

Bound

interface
Source
interface Bound<Services, RuntimeError = never> {
  readonly factory: <M extends Any>(machine: M & EnsureBoundRequirements<Services, NoInfer<M>> & EnsureMachineExecutable<NoInfer<M>> & RootCompatible<ParentEvents<NoInfer<M>>>) => (...args: [...Array<InputArgs<InputSchema<M>>>]) => MachineAtomOf<M, RuntimeError>;
  readonly family: <M extends Any, Projections extends Readonly<Record<string, RootFamilySelectorProjection<Snapshot<States<NoInfer<M>>>> | (bridge: MachineAtomOf) => Atom<any>>>>(machine: M & EnsureBoundRequirements<Services, NoInfer<M>> & EnsureMachineExecutable<NoInfer<M>> & RootCompatible<ParentEvents<NoInfer<M>>> & EnsureFamilyInput<NoInfer<M>>, options: FamilyOptions<Input<NoInfer<M>>, MachineAtomOf<NoInfer<M>, RuntimeError>, Projections>) => FamilyAtoms<Machine.Machine.Input<M>, MachineAtomOf<M, RuntimeError>, Projections>;
  readonly make: <M extends Any>(machine: M & EnsureBoundRequirements<Services, NoInfer<M>> & EnsureMachineExecutable<NoInfer<M>> & RootCompatible<ParentEvents<NoInfer<M>>>, ...args: [...Array<InputArgs<InputSchema<M>>>]) => MachineAtomOf<M, RuntimeError>;
  readonly resume: <M extends Any>(machine: M & EnsureBoundResumeRequirements<Services, NoInfer<M>> & EnsureMachineExecutable<NoInfer<M>> & RootCompatible<ParentEvents<NoInfer<M>>>, snapshot: Snapshot<States<M>>) => ResumedMachineAtomOf<M, RuntimeError>;
}

AtomMachine constructors bound to one owned Effect runtime.

Since v0.4.0
#

ChildMachineAtom

interface
Source
interface ChildMachineAtom<Child extends Machine.ChildMachine.Any, StartError = unknown> {
  readonly child: <Nested extends Any>(child: Nested) => ChildMachineAtom<Nested, StartError>;
  readonly ref: Atom<AsyncResult<Option<Ref<Child>>, StartError>>;
  readonly result: Atom<AsyncResult<Option<RefState<Ref<Child>>>, StartError | RefError<Ref<Child>>>>;
  readonly send: Writable<AsyncResult<void, StoppedError | NotReadyError | StartError | ChildNotActiveError>, Event<Child>>;
  readonly snapshot: Atom<AsyncResult<Option<RuntimeSnapshot<RefState<Ref<Child>>, RefError<Ref<Child>>, RefOutput<Ref<Child>>>>, StartError>>;
  readonly stop: Writable<AsyncResult<void, NotReadyError | StartError | ChildNotActiveError>, void>;
}

Reactive access to one directly owned child machine selected by its descriptor.

Details

Each atom contains Option.none() while the state that owns the invocation is inactive or while the child is starting. It contains Option.some(...) for the current child instance and follows replacements after re-entry.

Gotchas

Lookup is direct-child scoped. Use child again on this bridge to reach a machine invoked by the selected child.

Since v0.4.0
#

MachineAtom

interface
Source
interface MachineAtom<State, Event, Error = never, Output = never, StartError = never, Emitted = never> {
  readonly child: <Child extends Any>(child: Child) => ChildMachineAtom<Child, StartError>;
  readonly ref: Atom<AsyncResult<MachineRef<State, Event, Error, Output, Emitted>, StartError>>;
  readonly result: Atom<AsyncResult<State, Error | StartError>>;
  readonly send: Writable<AsyncResult<void, StoppedError | StartError | NotReadyError>, Event>;
  readonly snapshot: Atom<AsyncResult<RuntimeSnapshot<State, Error, Output>, StartError>>;
  readonly stop: Writable<AsyncResult<void, StartError | NotReadyError>, void>;
}

Atoms backed by one running machine instance in an AtomRegistry.

Details

The machine starts when one of the returned atoms is mounted or read in a registry, and it is stopped when the registry disposes the ref atom. The same atom values share one running machine per registry.

Since v0.4.0

Utility Types

1
#

ChildOf

type
Source
type ChildOf<Parent extends MachineAtom<any, never, any, any, any, any> | ChildMachineAtom<any, any>, Child extends Machine.ChildMachine.Any> = ChildMachineAtom<Child, BridgeStartError<Parent>>

Derives the exact child bridge type from a parent bridge and child descriptor.

Since v0.4.0
Type at least two characters to search.