{
  "id": "@typed/fx/RefSubject#RefSubject",
  "canonicalId": "@typed/fx/RefSubject#RefSubject",
  "symbol": {
    "id": "@typed/fx/RefSubject#RefSubject",
    "packageName": "@typed/fx",
    "moduleName": "RefSubject",
    "exportName": "RefSubject",
    "kind": "interface",
    "signatures": [
      "export interface RefSubject<A, E = never, R = never> extends Computed<A, E, R>, Subject.Subject<A, E, R> {\n    readonly [RefSubjectTypeId]: RefSubjectTypeId;\n    readonly updates: <B, E2, R2>(f: (ref: GetSetDelete<A, E, R>) => Effect.Effect<B, E2, R2>) => Effect.Effect<B, E | E2, R | R2>;\n    readonly interrupt: Effect.Effect<void, never, R>;\n}",
      "export declare namespace RefSubject {\n    type Any = RefSubject<any, any, any> | RefSubject<any, any> | RefSubject<any, never, any> | RefSubject<any>;\n    interface Service<Self, Id extends string, A, E> extends RefSubject<A, E, Self> {\n        readonly id: Id;\n        readonly service: Context.Service<Self, RefSubject<A, E>>;\n        readonly make: <R = never>(value: A | Effect.Effect<A, E, R> | Fx<A, E, R>, options?: RefSubjectOptions<A> & {\n            readonly skip?: number;\n            readonly take?: number;\n        }) => Layer.Layer<Self, never, Exclude<R, Scope.Scope>>;\n        readonly layer: <E2, R2>(make: Effect.Effect<RefSubject<A, E>, E2, R2 | Scope.Scope>) => Layer.Layer<Self, E2, Exclude<R2, Scope.Scope>>;\n    }\n    interface Class<Self, Id extends string, A, E> extends RefSubject.Service<Self, Id, A, E> {\n        new (): RefSubject.Service<Self, Id, A, E>;\n    }\n}"
    ],
    "summary": "A `RefSubject` is a mutable reference that can be observed as an Fx.\nIt combines the capabilities of a `Ref` (get/set/update) with a `Subject` (subscribe).",
    "sections": {
      "Why": "Unifies synchronized mutable state, Effectful current reads, and Fx pushes so the same state can\nbe tested and consumed without a renderer.",
      "Ownership and lifetime": "RefSubject is a contract and performs no acquisition. Implementations retain the errors,\nservices, interruption, and Scope requirements expressed by its members.",
      "Property: [[computed:[RefSubjectTypeId]]]": "Carries the runtime marker recognized by `isRefSubject`.",
      "Property: [[computed:[RefSubjectTypeId]]]: Why": "Marks the value as a writable RefSubject for runtime guards while retaining its Computed and\nSubject capabilities.",
      "Property: [[computed:[RefSubjectTypeId]]]: Ownership and lifetime": "This declaration performs no acquisition and retains no resources. Implementations preserve\nsource errors, services, and lifetime.",
      "Property: interrupt": "Interrupts the RefSubject, stopping all subscriptions and cleaning up resources.",
      "Property: interrupt: Why": "Interrupts the RefSubject, stopping all subscriptions and cleaning up resources.",
      "Property: interrupt: Ownership and lifetime": "Running this Effect returns `void`: it resets pending initialization, closes the RefSubject's\nprivate Scope, interrupts its initializer fiber, and interrupts its Subject. It cannot fail;\n`R` supplies services captured by the RefSubject's internal lifetime.",
      "Property: updates": "Runs an effect that can modify the RefSubject transactionally.\nAll operations within the transaction are atomic and serialized.",
      "Property: updates: Why": "Runs an effect that can modify the RefSubject transactionally. All operations within the\ntransaction are atomic and serialized. The transition is serialized at the RefSubject rather\nthan coordinated by callers or UI components.",
      "Property: updates: Ownership and lifetime": "Running updates performs one serialized subject transition and returns the committed value.\nIt acquires no resource and preserves source failures and services."
    },
    "examples": [
      {
        "language": "ts",
        "code": "import { Effect } from \"effect\"\nimport { Fx, RefSubject } from \"@typed/fx\"\n\n// Create a RefSubject with an initial value\nconst program = Effect.scoped(Effect.gen(function* () {\n  const count = yield* RefSubject.make(0)\n\n  // Get the current value\n  const current = yield* count\n  console.log(current) // 0\n\n  // Update the value\n  yield* RefSubject.set(count, 5)\n  const updated = yield* count\n  console.log(updated) // 5\n\n  // Use as an Fx to observe changes\n  yield* Effect.forkScoped(Fx.observe(\n    count,\n    (value) => Effect.sync(() => console.log(\"Count changed:\", value))\n  ))\n\n  // Increment\n  yield* RefSubject.increment(count)\n  // Output: \"Count changed: 6\"\n}))"
      },
      {
        "language": "ts",
        "code": "import { Effect } from \"effect\"\nimport * as RefSubject from \"@typed/fx/RefSubject\"\n\nconst program = Effect.gen(function* () {\n  const ref = yield* RefSubject.make(0)\n\n  // Later, clean up\n  yield* ref.interrupt\n})"
      },
      {
        "language": "ts",
        "code": "import { Effect } from \"effect\"\nimport * as RefSubject from \"@typed/fx/RefSubject\"\n\nconst program = Effect.gen(function* () {\n  const balance = yield* RefSubject.make(100)\n\n  // Transfer money atomically\n  yield* balance.updates((ref) =>\n    Effect.gen(function* () {\n      const current = yield* ref.get\n      if (current >= 50) {\n        yield* ref.set(current - 50)\n        return \"Transfer successful\"\n      }\n      return \"Insufficient funds\"\n    })\n  )\n})"
      }
    ],
    "relations": [],
    "source": {
      "file": "packages/fx/src/RefSubject/RefSubject.ts",
      "line": 536
    },
    "since": "1.0.0",
    "category": "Writable state"
  },
  "exposure": {
    "recordKind": "declaration",
    "id": "@typed/fx/RefSubject#RefSubject",
    "packageName": "@typed/fx",
    "packageVersion": "2.0.0-beta.13",
    "moduleName": "RefSubject",
    "consumerSpecifier": "@typed/fx/RefSubject",
    "exportName": "RefSubject",
    "qualifiedName": "RefSubject",
    "declarationKey": "declaration:4d8351e1d28a2e63aed175cf",
    "family": "interface",
    "signatures": [
      "export interface RefSubject<A, E = never, R = never> extends Computed<A, E, R>, Subject.Subject<A, E, R> {\n    readonly [RefSubjectTypeId]: RefSubjectTypeId;\n    readonly updates: <B, E2, R2>(f: (ref: GetSetDelete<A, E, R>) => Effect.Effect<B, E2, R2>) => Effect.Effect<B, E | E2, R | R2>;\n    readonly interrupt: Effect.Effect<void, never, R>;\n}",
      "export declare namespace RefSubject {\n    type Any = RefSubject<any, any, any> | RefSubject<any, any> | RefSubject<any, never, any> | RefSubject<any>;\n    interface Service<Self, Id extends string, A, E> extends RefSubject<A, E, Self> {\n        readonly id: Id;\n        readonly service: Context.Service<Self, RefSubject<A, E>>;\n        readonly make: <R = never>(value: A | Effect.Effect<A, E, R> | Fx<A, E, R>, options?: RefSubjectOptions<A> & {\n            readonly skip?: number;\n            readonly take?: number;\n        }) => Layer.Layer<Self, never, Exclude<R, Scope.Scope>>;\n        readonly layer: <E2, R2>(make: Effect.Effect<RefSubject<A, E>, E2, R2 | Scope.Scope>) => Layer.Layer<Self, E2, Exclude<R2, Scope.Scope>>;\n    }\n    interface Class<Self, Id extends string, A, E> extends RefSubject.Service<Self, Id, A, E> {\n        new (): RefSubject.Service<Self, Id, A, E>;\n    }\n}"
    ],
    "sourceSpans": [
      {
        "file": "packages/fx/src/RefSubject/RefSubject.ts",
        "start": {
          "line": 536,
          "column": 1
        },
        "end": {
          "line": 631,
          "column": 2
        }
      },
      {
        "file": "packages/fx/src/RefSubject/RefSubject.ts",
        "start": {
          "line": 651,
          "column": 1
        },
        "end": {
          "line": 811,
          "column": 2
        }
      },
      {
        "file": "packages/fx/src/RefSubject/RefSubject.ts",
        "start": {
          "line": 555,
          "column": 3
        },
        "end": {
          "line": 555,
          "column": 49
        }
      },
      {
        "file": "packages/fx/src/RefSubject/RefSubject.ts",
        "start": {
          "line": 630,
          "column": 3
        },
        "end": {
          "line": 630,
          "column": 53
        }
      },
      {
        "file": "packages/fx/src/RefSubject/RefSubject.ts",
        "start": {
          "line": 597,
          "column": 3
        },
        "end": {
          "line": 599,
          "column": 41
        }
      }
    ],
    "aliases": [
      "@typed/fx#RefSubject.RefSubject"
    ],
    "isAlias": false,
    "static": false
  },
  "declaration": {
    "declarationKey": "declaration:4d8351e1d28a2e63aed175cf",
    "name": "RefSubject",
    "family": "interface",
    "facets": [
      {
        "family": "interface",
        "syntaxKind": "InterfaceDeclaration",
        "signatures": [
          "export interface RefSubject<A, E = never, R = never> extends Computed<A, E, R>, Subject.Subject<A, E, R> {\n    readonly [RefSubjectTypeId]: RefSubjectTypeId;\n    readonly updates: <B, E2, R2>(f: (ref: GetSetDelete<A, E, R>) => Effect.Effect<B, E2, R2>) => Effect.Effect<B, E | E2, R | R2>;\n    readonly interrupt: Effect.Effect<void, never, R>;\n}"
        ],
        "typeParameters": [
          "A",
          "E = never",
          "R = never"
        ],
        "sourceSpans": [
          {
            "file": "packages/fx/src/RefSubject/RefSubject.ts",
            "start": {
              "line": 536,
              "column": 1
            },
            "end": {
              "line": 631,
              "column": 2
            }
          }
        ],
        "static": false,
        "readonly": false,
        "optional": false
      },
      {
        "family": "namespace",
        "syntaxKind": "ModuleDeclaration",
        "signatures": [
          "export declare namespace RefSubject {\n    type Any = RefSubject<any, any, any> | RefSubject<any, any> | RefSubject<any, never, any> | RefSubject<any>;\n    interface Service<Self, Id extends string, A, E> extends RefSubject<A, E, Self> {\n        readonly id: Id;\n        readonly service: Context.Service<Self, RefSubject<A, E>>;\n        readonly make: <R = never>(value: A | Effect.Effect<A, E, R> | Fx<A, E, R>, options?: RefSubjectOptions<A> & {\n            readonly skip?: number;\n            readonly take?: number;\n        }) => Layer.Layer<Self, never, Exclude<R, Scope.Scope>>;\n        readonly layer: <E2, R2>(make: Effect.Effect<RefSubject<A, E>, E2, R2 | Scope.Scope>) => Layer.Layer<Self, E2, Exclude<R2, Scope.Scope>>;\n    }\n    interface Class<Self, Id extends string, A, E> extends RefSubject.Service<Self, Id, A, E> {\n        new (): RefSubject.Service<Self, Id, A, E>;\n    }\n}"
        ],
        "typeParameters": [],
        "sourceSpans": [
          {
            "file": "packages/fx/src/RefSubject/RefSubject.ts",
            "start": {
              "line": 651,
              "column": 1
            },
            "end": {
              "line": 811,
              "column": 2
            }
          }
        ],
        "static": false,
        "readonly": false,
        "optional": false
      },
      {
        "family": "property",
        "syntaxKind": "PropertySignature",
        "signatures": [
          "readonly [RefSubjectTypeId]: RefSubjectTypeId;"
        ],
        "typeParameters": [],
        "sourceSpans": [
          {
            "file": "packages/fx/src/RefSubject/RefSubject.ts",
            "start": {
              "line": 555,
              "column": 3
            },
            "end": {
              "line": 555,
              "column": 49
            }
          }
        ],
        "static": false,
        "readonly": true,
        "optional": false
      },
      {
        "family": "property",
        "syntaxKind": "PropertySignature",
        "signatures": [
          "readonly interrupt: Effect.Effect<void, never, R>;"
        ],
        "typeParameters": [],
        "sourceSpans": [
          {
            "file": "packages/fx/src/RefSubject/RefSubject.ts",
            "start": {
              "line": 630,
              "column": 3
            },
            "end": {
              "line": 630,
              "column": 53
            }
          }
        ],
        "static": false,
        "readonly": true,
        "optional": false
      },
      {
        "family": "property",
        "syntaxKind": "PropertySignature",
        "signatures": [
          "readonly updates: <B, E2, R2>(f: (ref: GetSetDelete<A, E, R>) => Effect.Effect<B, E2, R2>) => Effect.Effect<B, E | E2, R | R2>;"
        ],
        "typeParameters": [],
        "sourceSpans": [
          {
            "file": "packages/fx/src/RefSubject/RefSubject.ts",
            "start": {
              "line": 597,
              "column": 3
            },
            "end": {
              "line": 599,
              "column": 41
            }
          }
        ],
        "static": false,
        "readonly": true,
        "optional": false
      }
    ],
    "signatures": [
      "export interface RefSubject<A, E = never, R = never> extends Computed<A, E, R>, Subject.Subject<A, E, R> {\n    readonly [RefSubjectTypeId]: RefSubjectTypeId;\n    readonly updates: <B, E2, R2>(f: (ref: GetSetDelete<A, E, R>) => Effect.Effect<B, E2, R2>) => Effect.Effect<B, E | E2, R | R2>;\n    readonly interrupt: Effect.Effect<void, never, R>;\n}",
      "export declare namespace RefSubject {\n    type Any = RefSubject<any, any, any> | RefSubject<any, any> | RefSubject<any, never, any> | RefSubject<any>;\n    interface Service<Self, Id extends string, A, E> extends RefSubject<A, E, Self> {\n        readonly id: Id;\n        readonly service: Context.Service<Self, RefSubject<A, E>>;\n        readonly make: <R = never>(value: A | Effect.Effect<A, E, R> | Fx<A, E, R>, options?: RefSubjectOptions<A> & {\n            readonly skip?: number;\n            readonly take?: number;\n        }) => Layer.Layer<Self, never, Exclude<R, Scope.Scope>>;\n        readonly layer: <E2, R2>(make: Effect.Effect<RefSubject<A, E>, E2, R2 | Scope.Scope>) => Layer.Layer<Self, E2, Exclude<R2, Scope.Scope>>;\n    }\n    interface Class<Self, Id extends string, A, E> extends RefSubject.Service<Self, Id, A, E> {\n        new (): RefSubject.Service<Self, Id, A, E>;\n    }\n}"
    ],
    "typeParameters": [
      "A",
      "E = never",
      "R = never"
    ],
    "summary": "A `RefSubject` is a mutable reference that can be observed as an Fx.\nIt combines the capabilities of a `Ref` (get/set/update) with a `Subject` (subscribe).",
    "sections": {
      "Why": "Unifies synchronized mutable state, Effectful current reads, and Fx pushes so the same state can\nbe tested and consumed without a renderer.",
      "Ownership and lifetime": "RefSubject is a contract and performs no acquisition. Implementations retain the errors,\nservices, interruption, and Scope requirements expressed by its members.",
      "Property: [[computed:[RefSubjectTypeId]]]": "Carries the runtime marker recognized by `isRefSubject`.",
      "Property: [[computed:[RefSubjectTypeId]]]: Why": "Marks the value as a writable RefSubject for runtime guards while retaining its Computed and\nSubject capabilities.",
      "Property: [[computed:[RefSubjectTypeId]]]: Ownership and lifetime": "This declaration performs no acquisition and retains no resources. Implementations preserve\nsource errors, services, and lifetime.",
      "Property: interrupt": "Interrupts the RefSubject, stopping all subscriptions and cleaning up resources.",
      "Property: interrupt: Why": "Interrupts the RefSubject, stopping all subscriptions and cleaning up resources.",
      "Property: interrupt: Ownership and lifetime": "Running this Effect returns `void`: it resets pending initialization, closes the RefSubject's\nprivate Scope, interrupts its initializer fiber, and interrupts its Subject. It cannot fail;\n`R` supplies services captured by the RefSubject's internal lifetime.",
      "Property: updates": "Runs an effect that can modify the RefSubject transactionally.\nAll operations within the transaction are atomic and serialized.",
      "Property: updates: Why": "Runs an effect that can modify the RefSubject transactionally. All operations within the\ntransaction are atomic and serialized. The transition is serialized at the RefSubject rather\nthan coordinated by callers or UI components.",
      "Property: updates: Ownership and lifetime": "Running updates performs one serialized subject transition and returns the committed value.\nIt acquires no resource and preserves source failures and services."
    },
    "examples": [
      {
        "language": "ts",
        "code": "import { Effect } from \"effect\"\nimport { Fx, RefSubject } from \"@typed/fx\"\n\n// Create a RefSubject with an initial value\nconst program = Effect.scoped(Effect.gen(function* () {\n  const count = yield* RefSubject.make(0)\n\n  // Get the current value\n  const current = yield* count\n  console.log(current) // 0\n\n  // Update the value\n  yield* RefSubject.set(count, 5)\n  const updated = yield* count\n  console.log(updated) // 5\n\n  // Use as an Fx to observe changes\n  yield* Effect.forkScoped(Fx.observe(\n    count,\n    (value) => Effect.sync(() => console.log(\"Count changed:\", value))\n  ))\n\n  // Increment\n  yield* RefSubject.increment(count)\n  // Output: \"Count changed: 6\"\n}))"
      },
      {
        "language": "ts",
        "code": "import { Effect } from \"effect\"\nimport * as RefSubject from \"@typed/fx/RefSubject\"\n\nconst program = Effect.gen(function* () {\n  const ref = yield* RefSubject.make(0)\n\n  // Later, clean up\n  yield* ref.interrupt\n})"
      },
      {
        "language": "ts",
        "code": "import { Effect } from \"effect\"\nimport * as RefSubject from \"@typed/fx/RefSubject\"\n\nconst program = Effect.gen(function* () {\n  const balance = yield* RefSubject.make(100)\n\n  // Transfer money atomically\n  yield* balance.updates((ref) =>\n    Effect.gen(function* () {\n      const current = yield* ref.get\n      if (current >= 50) {\n        yield* ref.set(current - 50)\n        return \"Transfer successful\"\n      }\n      return \"Insufficient funds\"\n    })\n  )\n})"
      }
    ],
    "sourceSpans": [
      {
        "file": "packages/fx/src/RefSubject/RefSubject.ts",
        "start": {
          "line": 536,
          "column": 1
        },
        "end": {
          "line": 631,
          "column": 2
        }
      },
      {
        "file": "packages/fx/src/RefSubject/RefSubject.ts",
        "start": {
          "line": 651,
          "column": 1
        },
        "end": {
          "line": 811,
          "column": 2
        }
      },
      {
        "file": "packages/fx/src/RefSubject/RefSubject.ts",
        "start": {
          "line": 555,
          "column": 3
        },
        "end": {
          "line": 555,
          "column": 49
        }
      },
      {
        "file": "packages/fx/src/RefSubject/RefSubject.ts",
        "start": {
          "line": 630,
          "column": 3
        },
        "end": {
          "line": 630,
          "column": 53
        }
      },
      {
        "file": "packages/fx/src/RefSubject/RefSubject.ts",
        "start": {
          "line": 597,
          "column": 3
        },
        "end": {
          "line": 599,
          "column": 41
        }
      }
    ],
    "since": "1.0.0",
    "category": "Writable state"
  }
}
