API Reference

ProxyRegistryclass

Default singleton in-memory implementation of IProxyRegistry.

When to use

register(target, proxy) adds or replaces a mapping. getProxy(target) reads the proxy for a target. getProxyTarget(proxy) finds the original target for a proxy. isProxy(value) checks whether a value is a registered proxy. unregister(target) removes the mapping. This registry is memory-only (not persisted).

Related: IProxyRegistry docs

Quick facts
Kind
class
Implements
IProxyRegistry
Members
5
Package
@rs-x/core

Import

import { ProxyRegistry } from '@rs-x/core';

Example

import {
  InjectionContainer,
  RsXCoreInjectionTokens,
  RsXCoreModule,
  type IProxyRegistry,
} from '@rs-x/core';

await InjectionContainer.load(RsXCoreModule);

const proxyRegistry = InjectionContainer.get<IProxyRegistry>(
  RsXCoreInjectionTokens.IProxyRegistry,
);

const target = { id: 1 };
const proxy = new Proxy(target, {});

proxyRegistry.register(target, proxy);

console.log(proxyRegistry.getProxy(target) === proxy); // true
console.log(proxyRegistry.getProxyTarget(proxy) === target); // true
console.log(proxyRegistry.isProxy(proxy)); // true

Constructor injection example

import { Inject, RsXCoreInjectionTokens, type IProxyRegistry } from '@rs-x/core';

class ProxyAwareService {
  constructor(
    @Inject(RsXCoreInjectionTokens.IProxyRegistry)
    private readonly proxyRegistry: IProxyRegistry,
  ) {}
}

Members

5 members in this class.

getProxy
methodpublic
public getProxy<T>(proxyTarget: unknown): T

Parameters

Name
Type
Required
proxyTarget
unknown
required

Returns

T

getProxyTarget
methodpublic
public getProxyTarget<T>(proxyToFind: unknown): T

Parameters

Name
Type
Required
proxyToFind
unknown
required

Returns

T

isProxy
methodpublic
public isProxy(object: unknown): boolean

Parameters

Name
Type
Required
object
unknown
required

Returns

boolean

register
methodpublic
public register(
  proxyTarget: unknown,
  proxy: unknown
): void

Parameters

Name
Type
Required
proxyTarget
unknown
required
proxy
unknown
required

Returns

void

unregister
methodpublic
public unregister(proxyTarget: unknown): void

Parameters

Name
Type
Required
proxyTarget
unknown
required

Returns

void