-
Notifications
You must be signed in to change notification settings - Fork 567
Expand file tree
/
Copy pathfluidHandle.ts
More file actions
66 lines (60 loc) · 2.04 KB
/
fluidHandle.ts
File metadata and controls
66 lines (60 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*!
* 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<T> {
/**
* {@inheritDoc @fluidframework/core-interfaces#IFluidHandle.absolutePath}
*/
public readonly absolutePath: string;
/**
* {@inheritDoc @fluidframework/core-interfaces#IFluidHandle.isAttached}
*/
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<T>,
public readonly path: string,
public readonly routeContext: IFluidHandleContext,
) {
super();
this.absolutePath = generateHandleContextPath(path, this.routeContext);
}
/**
* {@inheritDoc @fluidframework/core-interfaces#IFluidHandle.get}
*/
// TODO: Return `Promise<T>` instead of `Promise<any>`.
// 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<any> {
// Note that this return works whether we received a T or a Promise<T> for this.value in the constructor.
return this.value;
}
/**
* {@inheritDoc @fluidframework/core-interfaces#IFluidHandle.attachGraph }
*/
public attachGraph(): void {
this.routeContext.attachGraph();
}
}