import { IFluidObject , IFluidHandle , IFluidHandleContext , FluidObject , } from "@fluidframework/core-interfaces" ; import { AttachState } from "@fluidframework/container-definitions" ; import { generateHandleContextPath } from "@fluidframework/runtime-utils" ; export class FluidObjectHandle < T extends FluidObject = IFluidObject > implements IFluidHandle { private graphAttachState : AttachState = AttachState . Detached ; private bound : Set < IFluidHandle > | undefined ; public readonly absolutePath : string ; public get IFluidHandle ( ) : IFluidHandle { return this ; } public get isAttached ( ) : boolean { return this . routeContext . isAttached ; } param value param path param routeContext constructor ( protected readonly value , public readonly path , public readonly routeContext ) { this . absolutePath = generateHandleContextPath ( path , this . routeContext ) ; } public async get ( ) { return this . value ; } public attachGraph ( ) { if ( this . graphAttachState !== AttachState . Detached ) { return ; } this . graphAttachState = AttachState . Attaching ; if ( this . bound !== undefined ) { for ( const handle of this . bound ) { handle . attachGraph ( ) ; } this . bound = undefined ; } this . routeContext . attachGraph ( ) ; this . graphAttachState = AttachState . Attached ; } public bind ( handle ) { if ( this . isAttached || this . graphAttachState !== AttachState . Detached ) { handle . attachGraph ( ) ; return ; } if ( this . bound === undefined ) { this . bound = new Set < IFluidHandle > ( ) ; } this . bound . add ( handle ) ; } }