Overview
Used to deep clone values safely, including proxy-aware cloning and async-value normalization.
API Reference
Clones values with Lodash and rs-x clone-exception handling.
This implementation uses Lodash to clone values and calls the clone-exception service when a value needs runtime-specific handling. That allows rs-x to replace values such as Promise or Observable nodes during the clone process. Use RsXCoreInjectionTokens.ILodashDeepClone when you explicitly want this implementation. Use RsXCoreInjectionTokens.IDeepClone when you want the currently configured default clone service.
import { LodashDeepClone } from '@rs-x/core';import {
InjectionContainer,
RsXCoreInjectionTokens,
type IDeepClone,
} from '@rs-x/core';
// Resolve via container.
const lodashDeepClone = InjectionContainer.get<IDeepClone>(
RsXCoreInjectionTokens.ILodashDeepClone,
);
const cloned = lodashDeepClone.clone({ a: 1, nested: { b: 2 } });
console.log(cloned);import { Inject, RsXCoreInjectionTokens, type IDeepClone } from '@rs-x/core';
class CloneConsumer {
constructor(
@Inject(RsXCoreInjectionTokens.ILodashDeepClone)
private readonly lodashDeepCloneByDi: IDeepClone,
) {}
}2 members in this class.
constructor(
@Inject(RsXCoreInjectionTokens.DefaultDeepCloneExcept) private readonly _deepCloneExcept: IDeepCloneExcept,
@Inject(RsXCoreInjectionTokens.IProxyRegistry) private readonly _proxyRegistry: IProxyRegistry
)Parameters
public clone(source: unknown): unknownParameters
Returns
unknown