Fix extra proxies (#7483)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2024-12-16 19:16:34 +05:00 committed by GitHub
parent 766eb53d10
commit c496829576
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 5 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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