diff --git a/packages/core/src/clone.ts b/packages/core/src/clone.ts index 315b9ca88f..a03da61e41 100644 --- a/packages/core/src/clone.ts +++ b/packages/core/src/clone.ts @@ -54,9 +54,8 @@ export function clone (obj: any, as?: (doc: any, m: any) => any, needAs?: (value if (type === 'Array') { result[key] = clone(value, as, needAs) } else if (type === 'Object') { - const m = needAs?.(value) const valClone = clone(value, as, needAs) - result[key] = m !== undefined && as !== undefined ? as(valClone, m) : valClone + result[key] = valClone } else if (type === 'Date') { result[key] = new Date(value.getTime()) } else { diff --git a/packages/core/src/hierarchy.ts b/packages/core/src/hierarchy.ts index 9397c5fa92..836491ca69 100644 --- a/packages/core/src/hierarchy.ts +++ b/packages/core/src/hierarchy.ts @@ -18,7 +18,7 @@ import type { AnyAttribute, Class, Classifier, Doc, Domain, Interface, Mixin, Ob import { ClassifierKind } from './classes' import { clone as deepClone } from './clone' import core from './component' -import { _createMixinProxy, _mixinClass, _toDoc } from './proxy' +import { _createMixinProxy, _mixinClass, _toDoc, PROXY_MIXIN_CLASS_KEY } from './proxy' import type { Tx, TxCreateDoc, TxMixin, TxRemoveDoc, TxUpdateDoc } from './tx' import { TxProcessor } from './tx' @@ -53,7 +53,9 @@ export class Hierarchy { } as<D extends Doc, M extends D>(doc: D, mixin: Ref<Mixin<M>>): M { - return new Proxy(doc, this.getMixinProxyHandler(mixin)) as M + if ((doc as any)[PROXY_MIXIN_CLASS_KEY] === mixin) return doc as M + + return new Proxy(Hierarchy.toDoc(doc), this.getMixinProxyHandler(mixin)) as M } asIf<D extends Doc, M extends D>(doc: D | undefined, mixin: Ref<Mixin<M>>): M | undefined { diff --git a/packages/core/src/proxy.ts b/packages/core/src/proxy.ts index fb4dc07b08..517c8414dd 100644 --- a/packages/core/src/proxy.ts +++ b/packages/core/src/proxy.ts @@ -3,7 +3,7 @@ import { Ref } from '.' import type { Doc, Mixin } from './classes' const PROXY_TARGET_KEY = '$___proxy_target' -const PROXY_MIXIN_CLASS_KEY = '$__mixin' +export const PROXY_MIXIN_CLASS_KEY = '$__mixin' /** * @internal