import { privateAPI , setPrivateAPI } from '@theatre/core/privateAPIs' ; import type { IProject } from '@theatre/core/projects/TheatreProject' ; import coreTicker from '@theatre/core/coreTicker' ; import type { ISheet } from '@theatre/core/sheets/TheatreSheet' ; import type { SheetObjectAddress } from '@theatre/shared/utils/addresses' ; import SimpleCache from '@theatre/shared/utils/SimpleCache' ; import type { $FixMe , DeepPartialOfSerializableValue , VoidFn , } from '@theatre/shared/utils/types' ; import type { IDerivation , Pointer } from '@theatre/dataverse' ; import { prism , val } from '@theatre/dataverse' ; import type SheetObject from './SheetObject' ; import type { IShorthandCompoundProps , ShorthandPropToLonghandProp , } from '@theatre/core/propTypes/internals' ; export interface ISheetObject < Props extends IShorthandCompoundProps = { } > { /**
     * All Objects will have `object.type === 'Theatre_SheetObject_PublicAPI'`
     */ readonly type : 'Theatre_SheetObject_PublicAPI' ; example readonly value : ShorthandPropToLonghandProp < Props > [ 'valueType' ] ; /**
     * A Pointer to the props of the object.
     *
     * More documentation soon.
     */ readonly props : Pointer < this [ 'value' ] > ; /**
     * The instance of Sheet the Object belongs to
     */ readonly sheet : ISheet ; /**
     * The Project the project belongs to
     */ readonly project : IProject ; /**
     * An object representing the address of the Object
     */ readonly address : SheetObjectAddress ; returns example onValuesChange ( fn ) : VoidFn ; example set initialValue ( value ) ; } export default class TheatreSheetObject < Props extends IShorthandCompoundProps = { } > implements ISheetObject < Props > { get type ( ) : 'Theatre_SheetObject_PublicAPI' { return 'Theatre_SheetObject_PublicAPI' ; } private readonly _cache = new SimpleCache ( ) ; internal constructor ( internals ) { setPrivateAPI ( this , internals ) ; } get props ( ) : Pointer < this [ 'value' ] > { return privateAPI ( this ) . propsP as $FixMe ; } get sheet ( ) : ISheet { return privateAPI ( this ) . sheet . publicApi ; } get project ( ) : IProject { return privateAPI ( this ) . sheet . project . publicApi ; } get address ( ) : SheetObjectAddress { return { ... privateAPI ( this ) . address } ; } private _valuesDerivation ( ) { return this . _cache . get ( 'onValuesChangeDerivation' , ( ) => { const sheetObject = privateAPI ( this ) ; const d = prism ( ( ) => { return val ( sheetObject . getValues ( ) . getValue ( ) ) as $FixMe ; } ) ; return d ; } ) ; } onValuesChange ( fn ) { return this . _valuesDerivation ( ) . tapImmediate ( coreTicker , fn ) ; } get value ( ) : ShorthandPropToLonghandProp < Props > [ 'valueType' ] { return this . _valuesDerivation ( ) . getValue ( ) ; } set initialValue ( val ) { privateAPI ( this ) . setInitialValue ( val ) ; } }