Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions examples/apps/tree-comparison/src/model/legacyTreeInventoryList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
* Licensed under the MIT License.
*/

import type { BuildNode, TraitLabel, TreeView, TreeViewNode } from "@fluid-experimental/tree";
import type {
BuildNode,
ISharedTree,
TraitLabel,
TreeView,
TreeViewNode,
} from "@fluid-experimental/tree";
import {
Change,
EagerCheckout,
// eslint-disable-next-line import-x/no-deprecated
SharedTree as LegacySharedTree,
StablePlace,
StableRange,
Expand Down Expand Up @@ -69,10 +76,10 @@ export class LegacyTreeInventoryItem
}

export class LegacyTreeInventoryList extends DataObject implements IInventoryList {
private _tree: LegacySharedTree | undefined;
private _tree: ISharedTree | undefined;
private readonly _inventoryItems = new Map<string, LegacyTreeInventoryItem>();

private get tree(): LegacySharedTree {
private get tree(): ISharedTree {
if (this._tree === undefined) {
throw new Error("Not initialized properly");
}
Expand Down Expand Up @@ -120,8 +127,9 @@ export class LegacyTreeInventoryList extends DataObject implements IInventoryLis
protected async initializingFirstTime(): Promise<void> {
const legacySharedTree = this.runtime.createChannel(
undefined,
// eslint-disable-next-line import-x/no-deprecated
LegacySharedTree.getFactory().type,
) as LegacySharedTree;
) as ISharedTree;

const inventoryNode: BuildNode = {
definition: "inventory",
Expand Down Expand Up @@ -185,12 +193,11 @@ export class LegacyTreeInventoryList extends DataObject implements IInventoryLis
*/
protected async hasInitialized(): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this._tree = await this.root
.get<IFluidHandle<LegacySharedTree>>(legacySharedTreeKey)!
.get();
this._tree = await this.root.get<IFluidHandle<ISharedTree>>(legacySharedTreeKey)!.get();

// We must use a checkout in order to get "viewChange" events - it doesn't change any of the rest of our usage though.
const checkout = new EagerCheckout(this._tree);
// eslint-disable-next-line import-x/no-deprecated
const checkout = new EagerCheckout(this._tree as LegacySharedTree);
Comment on lines +199 to +200
// This event handler fires for any change to the tree, so it needs to handle all possibilities (change, add, remove).
checkout.on("viewChange", (before: TreeView, after: TreeView) => {
const { changed, added, removed } = before.delta(after);
Expand Down Expand Up @@ -301,6 +308,7 @@ export class LegacyTreeInventoryList extends DataObject implements IInventoryLis
export const LegacyTreeInventoryListFactory = new DataObjectFactory<LegacyTreeInventoryList>(
"legacy-tree-inventory-list",
LegacyTreeInventoryList,
// eslint-disable-next-line import-x/no-deprecated
[LegacySharedTree.getFactory()],
{},
);
10 changes: 7 additions & 3 deletions examples/benchmarks/bubblebench/experimental-tree/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/

import type { IClient } from "@fluid-example/bubblebench-common";
import type { ISharedTree } from "@fluid-experimental/tree";
// eslint-disable-next-line import-x/no-deprecated
import { SharedTree, WriteFormat } from "@fluid-experimental/tree";
import { DataObject, DataObjectFactory } from "@fluidframework/aqueduct/legacy";
import type { IFluidHandle } from "@fluidframework/core-interfaces";
Expand All @@ -20,10 +22,11 @@ interface IApp {
*/
export class Bubblebench extends DataObject {
public static readonly Name = "@fluid-example/bubblebench-sharedtree";
private maybeTree?: SharedTree = undefined;
private maybeTree?: ISharedTree = undefined;
private maybeAppState?: AppState = undefined;

protected async initializingFirstTime(): Promise<void> {
// eslint-disable-next-line import-x/no-deprecated
const tree = (this.maybeTree = SharedTree.create(this.runtime));

const p = TreeObjectProxy<IApp>(tree, tree.currentView.root, tree.applyEdit.bind(tree));
Expand All @@ -34,7 +37,7 @@ export class Bubblebench extends DataObject {

protected async initializingFromExisting(): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.maybeTree = await this.root.get<IFluidHandle<SharedTree>>("tree")!.get();
this.maybeTree = await this.root.get<IFluidHandle<ISharedTree>>("tree")!.get();
}

protected async hasInitialized(): Promise<void> {
Expand Down Expand Up @@ -64,7 +67,7 @@ export class Bubblebench extends DataObject {
}
}

private get tree(): SharedTree {
private get tree(): ISharedTree {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return this.maybeTree!;
}
Expand All @@ -83,5 +86,6 @@ export class Bubblebench extends DataObject {
export const BubblebenchInstantiationFactory = new DataObjectFactory({
type: Bubblebench.Name,
ctor: Bubblebench,
// eslint-disable-next-line import-x/no-deprecated
sharedObjects: [SharedTree.getFactory(WriteFormat.v0_1_1)],
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Change,
type ChangeNode,
type NodeId,
type SharedTree,
type ISharedTree,
StablePlace,
StableRange,
type TraitLabel,
Expand All @@ -17,7 +17,7 @@ import type { Serializable } from "@fluidframework/datastore-definitions/legacy"
import { NodeKind, fromJson } from "./treeutils.js";

function getChild(
tree: SharedTree,
tree: ISharedTree,
nodeId: NodeId,
update: (...change: Change[]) => void,
): unknown {
Expand All @@ -38,7 +38,7 @@ function getChild(

// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
export const TreeObjectProxy = <T extends Object>(
tree: SharedTree,
tree: ISharedTree,
nodeId: NodeId,
update: (...change: Change[]) => void,
): T =>
Expand Down Expand Up @@ -83,7 +83,7 @@ export const TreeObjectProxy = <T extends Object>(

export class TreeArrayProxy<T> {
constructor(
private readonly tree: SharedTree,
private readonly tree: ISharedTree,
private readonly nodeId: NodeId,
private readonly update: (...change: Change[]) => void,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
type SimpleClient,
type IBubble,
} from "@fluid-example/bubblebench-common";
import type { Change, SharedTree } from "@fluid-experimental/tree";
import type { Change, ISharedTree } from "@fluid-experimental/tree";

import { type TreeArrayProxy, TreeObjectProxy, fromJson } from "./proxy/index.js";

Expand All @@ -30,7 +30,7 @@ export class AppState implements IAppState {
private readonly deferredChanges: Change[] = [];

constructor(
private readonly tree: SharedTree,
private readonly tree: ISharedTree,
private _width: number,
private _height: number,
numBubbles: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under the MIT License.
*/

/* eslint-disable import-x/no-deprecated -- This bundle-size test intentionally uses the deprecated SharedTree value. */
import { SharedTree } from "@fluid-experimental/tree";

export function apisToBundle(): typeof SharedTree {
Expand Down
12 changes: 7 additions & 5 deletions examples/version-migration/tree-shim/src/model/inventoryList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
* Licensed under the MIT License.
*/

import type { ISharedTree } from "@fluid-experimental/tree";
import {
SharedTree as LegacySharedTree,
MigrationShim,
MigrationShimFactory,
SharedTreeFactory as LegacySharedTreeFactory,
SharedTreeShim,
SharedTreeShimFactory,
WriteFormat,
} from "@fluid-experimental/tree";
import { DataObject, DataObjectFactory } from "@fluidframework/aqueduct/legacy";
import { IFluidHandle } from "@fluidframework/core-interfaces";
Expand Down Expand Up @@ -36,7 +38,7 @@ const DEBUG_migrateSlowly = false;

const newTreeFactory = SharedTree.getFactory();

function migrate(legacyTree: LegacySharedTree, newTree: ITree): void {
function migrate(legacyTree: ISharedTree, newTree: ITree): void {
// Revert local edits - otherwise we will be eventually inconsistent
const edits = legacyTree.edits;
const localEdits = [...edits.getLocalEdits()].reverse();
Expand All @@ -61,7 +63,7 @@ function migrate(legacyTree: LegacySharedTree, newTree: ITree): void {
NewTreeInventoryListController.initializeTree(newTree, initialTree);
}

const legacyTreeFactory = LegacySharedTree.getFactory();
const legacyTreeFactory = new LegacySharedTreeFactory(WriteFormat.v0_1_1);
const migrationShimFactory = new MigrationShimFactory(
legacyTreeFactory,
newTreeFactory,
Expand Down Expand Up @@ -116,7 +118,7 @@ export class InventoryList extends DataObject implements IInventoryList, IMigrat
undefined,
migrationShimFactory.type,
) as MigrationShim;
const legacySharedTree = migrationShim.currentTree as LegacySharedTree;
const legacySharedTree = migrationShim.currentTree as ISharedTree;

LegacyTreeInventoryListController.initializeTree(legacySharedTree);

Expand Down Expand Up @@ -151,7 +153,7 @@ export class InventoryList extends DataObject implements IInventoryList, IMigrat
.get<IFluidHandle<MigrationShim | SharedTreeShim>>(treeKey)!
.get();
if (this.shim.attributes.type === legacyTreeFactory.type) {
const tree = this.shim.currentTree as LegacySharedTree;
const tree = this.shim.currentTree as ISharedTree;
this._model = new LegacyTreeInventoryListController(tree);
const migrationShim = this.shim as MigrationShim;
migrationShim.on("migrated", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
*/

import { EventEmitter } from "@fluid-example/example-utils";
import type { ISharedTree } from "@fluid-experimental/tree";
import {
BuildNode,
Change,
EagerCheckout,
// eslint-disable-next-line import-x/no-deprecated
SharedTree as LegacySharedTree,
StablePlace,
StableRange,
Expand Down Expand Up @@ -69,7 +71,7 @@ export class LegacyTreeInventoryItem
}

export class LegacyTreeInventoryListController extends EventEmitter implements IInventoryList {
public static initializeTree(tree: LegacySharedTree): void {
public static initializeTree(tree: ISharedTree): void {
const inventoryNode: BuildNode = {
definition: "inventory",
traits: {
Expand Down Expand Up @@ -126,10 +128,11 @@ export class LegacyTreeInventoryListController extends EventEmitter implements I

private readonly _inventoryItems = new Map<string, LegacyTreeInventoryItem>();

public constructor(private readonly _tree: LegacySharedTree) {
public constructor(private readonly _tree: ISharedTree) {
super();
// We must use a checkout in order to get "viewChange" events - it doesn't change any of the rest of our usage though.
const checkout = new EagerCheckout(this._tree);
// eslint-disable-next-line import-x/no-deprecated
const checkout = new EagerCheckout(this._tree as LegacySharedTree);
Comment on lines +134 to +135
// This event handler fires for any change to the tree, so it needs to handle all possibilities (change, add, remove).
checkout.on("viewChange", (before: TreeView, after: TreeView) => {
const { changed, added, removed } = before.delta(after);
Expand Down
Loading
Loading