API Reference

DefaultDeepCloneclass

Selects and runs deep-clone strategies in priority order.

Overview

Used to deep clone values safely, including proxy-aware cloning and async-value normalization.

When to use

This is the default implementation behind the IDeepClone service. By default, it tries StructuredDeepClone first and then LodashDeepClone as fallback. For each input value, it executes the configured IDeepClone strategy list in descending priority order and calls clone(source) on each strategy. The first successful strategy result is returned; if one throws or cannot handle the value, the next strategy is tried. Resolve the default clone service via RsXCoreInjectionTokens.IDeepClone. There is no dedicated RsXCoreInjectionTokens.DefaultDeepClone token.

Quick facts
Kind
class
Implements
IDeepClone
Members
2
Package
@rs-x/core

Import

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

Example

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

// Resolve via container.
const deepClone = InjectionContainer.get<IDeepClone>(
  RsXCoreInjectionTokens.IDeepClone,
);

const cloned = deepClone.clone({ a: 1, b: { c: 2 } });
console.log(cloned);

Constructor injection example

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

class CloneConsumer {
  constructor(
    @Inject(RsXCoreInjectionTokens.IDeepClone)
    private readonly deepCloneByDi: IDeepClone,
  ) {}
}

Members

2 members in this class.

constructor
constructorpublic
constructor(
  @MultiInject(RsXCoreInjectionTokens.IDeepCloneList) private readonly _deepCloneList: readonly IDeepClone[]
)

Parameters

Name
Type
Required
_deepCloneList
readonly IDeepClone[]
required
clone
methodpublic
public clone(source: unknown): unknown

Parameters

Name
Type
Required
source
unknown
required

Returns

unknown