import { MetaContext, MetaObject, $NAME } from '../../MetaContext'; import { $DUMP } from './$dump'; export const $SERIALIZE = '$serialize'; export type Serialize = (obj: T) => any; export type $Serialize = { [$SERIALIZE]: Serialize }; export const withSerialize = MetaContext>(MetaContextBase: TMetaContextBase) => class extends MetaContextBase { [$DUMP](value: T) { return this.resolveValue(value)[$SERIALIZE](value, this) as any; } [$SERIALIZE](value: T) { return this[$DUMP](value); } }; export function primitiveSerialize(this: MetaObject, value: T, context: any) { return this[$DUMP](value, context) as any; } export function genericSerialize(this: MetaObject, value: T, context: any) { return serializeWrapper(this, value, context); } export function serializeWrapper(metaObject: MetaObject, value: T, context: any) { return { [metaObject[$NAME]]: metaObject[$DUMP](value, context) }; }