variable / @typed/fx/RefSubject

proxy

Extract all values from an object using a Proxy. Allows accessing nested properties of a Computed or Filtered object/array as individual computed values.

Package version
2.0.0-beta.13
Category
Derived queries
Since
2.0.0

Import

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

Signatures

export declare const proxy: {
    <A extends ReadonlyArray<any> | Readonly<Record<PropertyKey, any>>, E, R>(source: Computed<A, E, R>): {
        readonly [K in keyof A]: Computed<A[K], E, R>;
    };
    <A extends ReadonlyArray<any> | Readonly<Record<PropertyKey, any>>, E, R>(source: Filtered<A, E, R>): {
        readonly [K in keyof A]: Filtered<A[K], E, R>;
    };
};

Why

Lazily creates one property projection per accessed key and memoizes that projection on the JavaScript Proxy. A Computed or RefSubject source produces Computed properties; only a Filtered source produces Filtered properties and preserves conditional absence.

Ownership and lifetime

The Proxy caches derived view objects, not property values. Computed property reads expose only the source’s E; Filtered property reads can additionally fail with NoSuchElementError while their source is absent. Each observed property follows the source and uses the observing Scope.

Examples

import { Effect } from "effect"
import * as RefSubject from "@typed/fx/RefSubject"

const program = Effect.gen(function* () {
  const user = yield* RefSubject.make({ name: "Alice", age: 30 })

  // Create a proxy to access nested properties
  const proxied = RefSubject.proxy(user)

  // Access individual properties as Computed values
  const name = yield* proxied.name
  console.log(name) // "Alice"

  const age = yield* proxied.age
  console.log(age) // 30

  // Update the source
  yield* RefSubject.set(user, { name: "Bob", age: 25 })

  // Proxied values automatically update
  const newName = yield* proxied.name
  console.log(newName) // "Bob"
})

Other public imports

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

Source