Skip to content

Commit

Permalink
tree: Expose the view schema on TreeView (#22547)
Browse files Browse the repository at this point in the history
## Description

This PR exposes the view schema as a property on TreeView.
  • Loading branch information
taylorsw04 authored Sep 17, 2024
1 parent a74dc57 commit 2aa29d9
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .changeset/dark-circles-whine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@fluidframework/tree": minor
---
---
section: tree
---

Exposes the view schema from the TreeView interface.

Users of TreeView can now access the type-safe view schema directly on the view object via `TreeView.schema`.
This allows users to avoid passing the schema around in addition to the view in scenarios where both are needed.
It also avoids scenarios in which code wants to accept both a view and its schema and thus must constrain both to be of the same schema type.
1 change: 1 addition & 0 deletions packages/dds/tree/api-report/tree.alpha.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ export interface TreeView<TSchema extends ImplicitFieldSchema> extends IDisposab
initialize(content: InsertableTreeFieldFromImplicitField<TSchema>): void;
get root(): TreeFieldFromImplicitField<TSchema>;
set root(newRoot: InsertableTreeFieldFromImplicitField<TSchema>);
readonly schema: TSchema;
upgradeSchema(): void;
}

Expand Down
1 change: 1 addition & 0 deletions packages/dds/tree/api-report/tree.beta.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ export interface TreeView<TSchema extends ImplicitFieldSchema> extends IDisposab
initialize(content: InsertableTreeFieldFromImplicitField<TSchema>): void;
get root(): TreeFieldFromImplicitField<TSchema>;
set root(newRoot: InsertableTreeFieldFromImplicitField<TSchema>);
readonly schema: TSchema;
upgradeSchema(): void;
}

Expand Down
1 change: 1 addition & 0 deletions packages/dds/tree/api-report/tree.legacy.alpha.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ export interface TreeView<TSchema extends ImplicitFieldSchema> extends IDisposab
initialize(content: InsertableTreeFieldFromImplicitField<TSchema>): void;
get root(): TreeFieldFromImplicitField<TSchema>;
set root(newRoot: InsertableTreeFieldFromImplicitField<TSchema>);
readonly schema: TSchema;
upgradeSchema(): void;
}

Expand Down
1 change: 1 addition & 0 deletions packages/dds/tree/api-report/tree.legacy.public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ export interface TreeView<TSchema extends ImplicitFieldSchema> extends IDisposab
initialize(content: InsertableTreeFieldFromImplicitField<TSchema>): void;
get root(): TreeFieldFromImplicitField<TSchema>;
set root(newRoot: InsertableTreeFieldFromImplicitField<TSchema>);
readonly schema: TSchema;
upgradeSchema(): void;
}

Expand Down
1 change: 1 addition & 0 deletions packages/dds/tree/api-report/tree.public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ export interface TreeView<TSchema extends ImplicitFieldSchema> extends IDisposab
initialize(content: InsertableTreeFieldFromImplicitField<TSchema>): void;
get root(): TreeFieldFromImplicitField<TSchema>;
set root(newRoot: InsertableTreeFieldFromImplicitField<TSchema>);
readonly schema: TSchema;
upgradeSchema(): void;
}

Expand Down
4 changes: 4 additions & 0 deletions packages/dds/tree/src/shared-tree/schematizingTreeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ export class SchematizingSimpleTreeView<in out TRootSchema extends ImplicitField
);
}

public get schema(): TRootSchema {
return this.config.schema;
}

public initialize(content: InsertableTreeFieldFromImplicitField<TRootSchema>): void {
this.ensureUndisposed();

Expand Down
5 changes: 5 additions & 0 deletions packages/dds/tree/src/simple-tree/api/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,11 @@ export interface TreeView<TSchema extends ImplicitFieldSchema> extends IDisposab
* Events for the tree.
*/
readonly events: Listenable<TreeViewEvents>;

/**
* The view schema used by this TreeView.
*/
readonly schema: TSchema;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@ export interface TreeView<TSchema extends ImplicitFieldSchema> extends IDisposab
initialize(content: InsertableTreeFieldFromImplicitField<TSchema>): void;
get root(): TreeFieldFromImplicitField<TSchema>;
set root(newRoot: InsertableTreeFieldFromImplicitField<TSchema>);
readonly schema: TSchema;
upgradeSchema(): void;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@ export interface TreeView<TSchema extends ImplicitFieldSchema> extends IDisposab
initialize(content: InsertableTreeFieldFromImplicitField<TSchema>): void;
get root(): TreeFieldFromImplicitField<TSchema>;
set root(newRoot: InsertableTreeFieldFromImplicitField<TSchema>);
readonly schema: TSchema;
upgradeSchema(): void;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,7 @@ export interface TreeView<TSchema extends ImplicitFieldSchema> extends IDisposab
initialize(content: InsertableTreeFieldFromImplicitField<TSchema>): void;
get root(): TreeFieldFromImplicitField<TSchema>;
set root(newRoot: InsertableTreeFieldFromImplicitField<TSchema>);
readonly schema: TSchema;
upgradeSchema(): void;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ export interface TreeView<TSchema extends ImplicitFieldSchema> extends IDisposab
initialize(content: InsertableTreeFieldFromImplicitField<TSchema>): void;
get root(): TreeFieldFromImplicitField<TSchema>;
set root(newRoot: InsertableTreeFieldFromImplicitField<TSchema>);
readonly schema: TSchema;
upgradeSchema(): void;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,7 @@ export interface TreeView<TSchema extends ImplicitFieldSchema> extends IDisposab
initialize(content: InsertableTreeFieldFromImplicitField<TSchema>): void;
get root(): TreeFieldFromImplicitField<TSchema>;
set root(newRoot: InsertableTreeFieldFromImplicitField<TSchema>);
readonly schema: TSchema;
upgradeSchema(): void;
}

Expand Down

0 comments on commit 2aa29d9

Please sign in to comment.