/*! * Copyright (c) Microsoft Corporation and contributors. All rights reserved. * Licensed under the MIT License. */ import type { FluidObject } from "@fluidframework/core-interfaces"; import type { IFluidHandleContext } from "@fluidframework/core-interfaces/internal"; import { generateHandleContextPath, FluidHandleBase, } from "@fluidframework/runtime-utils/internal"; /** * Handle for a shared {@link @fluidframework/core-interfaces#FluidObject}. * @legacy @beta */ export class FluidObjectHandle< T extends FluidObject = FluidObject, > extends FluidHandleBase { public readonly absolutePath: string; public get isAttached(): boolean { return this.routeContext.isAttached; } /** * Creates a new `FluidObjectHandle`. * * @param value - The {@link @fluidframework/core-interfaces#FluidObject} object this handle is for. * @param path - The path to this handle relative to the `routeContext`. * @param routeContext - The parent {@link @fluidframework/core-interfaces#IFluidHandleContext} that has a route * to this handle. */ constructor( protected readonly value: T | Promise, public readonly path: string, public readonly routeContext: IFluidHandleContext, ) { super(); this.absolutePath = generateHandleContextPath(path, this.routeContext); } /** * {@inheritDoc @fluidframework/core-interfaces#IFluidHandle.get} */ // TODO: Return `Promise` instead of `Promise`. // This was clearly the intended typing of this API, but fixing it would be a breaking change. // eslint-disable-next-line @typescript-eslint/no-explicit-any public async get(): Promise { // Note that this return works whether we received a T or a Promise for this.value in the constructor. return this.value; } public attachGraph(): void { this.routeContext.attachGraph(); } }