Overview
Used to deep clone values safely, including proxy-aware cloning and async-value normalization.
API Reference
Selects and runs deep-clone strategies in priority order.
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.
import { DefaultDeepClone } from '@rs-x/core';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);import { Inject, RsXCoreInjectionTokens, type IDeepClone } from '@rs-x/core';
class CloneConsumer {
constructor(
@Inject(RsXCoreInjectionTokens.IDeepClone)
private readonly deepCloneByDi: IDeepClone,
) {}
}2 members in this class.
constructor(
@MultiInject(RsXCoreInjectionTokens.IDeepCloneList) private readonly _deepCloneList: readonly IDeepClone[]
)Parameters
public clone(source: unknown): unknownParameters
Returns
unknown