UNPKG

@oobleck/fluid-backend

Version:

Fluid Framework backend for nteract RTC

92 lines (77 loc) 2.99 kB
import { DataObject, DataObjectFactory, // IValueChanged } from "@fluid-experimental/fluid-framework"; import { IFluidHandle } from "@fluidframework/core-interfaces"; import { SharedCell } from "@fluidframework/cell"; import { UpsertNotebookInput } from "../schema"; import { NotebookDDS } from "./notebook"; enum PropertyKey { Model = "model", DocumentUsers = "documentUsers" } export class ShellDDS extends DataObject { // private readonly debug: debug.Debugger = namespaceDebug.extend("shell", "|"); public static DataObjectName = "solid-shell"; private notebook: NotebookDDS | undefined; // documentUsers!: ISharedMap; private notebookSlot!: SharedCell; /** * The factory defines how to create an instance of the DataObject as well as the * dependencies of the DataObject. */ static readonly factory = new DataObjectFactory( ShellDDS.DataObjectName, ShellDDS, [SharedCell.getFactory()], {}, [NotebookDDS.Factory.registryEntry] ); get model(): NotebookDDS | undefined { return this.notebook; } async upsertModel(input: UpsertNotebookInput): Promise<NotebookDDS> { this.notebook = await NotebookDDS.Factory.createChildInstance(this.context, input.content); this.notebookSlot.set(this.notebook.handle); return this.notebook; } //#region DataObject protected async initializingFirstTime(): Promise<void> { this.root.set(PropertyKey.Model, SharedCell.create(this.runtime).handle); // this.root // .set(PropertyKey.DocumentUsers, SharedMap.create(this.runtime).handle); } protected async initializingFromExisting() { } protected async hasInitialized(): Promise<void> { this.notebookSlot = await this.root.get(PropertyKey.Model).get(); const componentHandle: IFluidHandle<NotebookDDS> = this.notebookSlot.get(); if (componentHandle) { this.notebook = await componentHandle.get(); } this.notebookSlot.on("op", (op, local) => { if (!local && op.contents.type === "setCell" && op.contents.value.value) { console.log(op.contents.value); } }); // this.documentUsers = await this.root.get(PropertyKey.DocumentUsers)?.get(); // this.root.on("valueChanged", async (changed: IValueChanged, local: boolean) => { // if (!local && changed.key === PropertyKey.Model) { // const componentHandle = this.root.get(PropertyKey.Model); // console.log("Gotcha!", componentHandle); // this.notebook = await componentHandle?.get(); // } // }); // record myself in the registry of document users // const { id: userId, displayName } = this.context.options.user as IAugmentedUser; // const docUser: IDocumentUserInfo = { displayName }; // this.documentUsers.set(userId, docUser); } // public dispose(): void { // super.dispose(); // } //#endregion //#region private //#endregion }