Skip to content

Commit

Permalink
tree: Remove dead code (microsoft#22653)
Browse files Browse the repository at this point in the history
## Description

Delete a bunch of dead code, mostly flex tree schema related.
  • Loading branch information
CraigMacomber authored Sep 27, 2024
1 parent b902d4c commit 6cc8df2
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 2,067 deletions.
917 changes: 2 additions & 915 deletions packages/dds/tree/src/feature-libraries/editableTreeBinder.ts

Large diffs are not rendered by default.

47 changes: 0 additions & 47 deletions packages/dds/tree/src/feature-libraries/fieldGenerator.ts

This file was deleted.

12 changes: 0 additions & 12 deletions packages/dds/tree/src/feature-libraries/flex-tree/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@
import { assert } from "@fluidframework/core-utils/internal";

import {
type FieldKey,
type ForestEvents,
type SchemaPolicy,
type TreeFieldStoredSchema,
type TreeStoredSchema,
anchorSlot,
moveToDetachedField,
} from "../../core/index.js";
import type { Listenable } from "../../events/index.js";
import { type IDisposable, disposeSymbol } from "../../util/index.js";
import type { FieldGenerator } from "../fieldGenerator.js";
import type { NodeKeyManager } from "../node-key/index.js";

import type { FlexTreeField } from "./flexTreeTypes.js";
Expand Down Expand Up @@ -169,15 +166,6 @@ export class Context implements FlexTreeHydratedContext, IDisposable {
): () => void {
return this.checkout.forest.on(eventName, listener);
}

/**
* FieldSource used to get a FieldGenerator to populate required fields during procedural contextual data generation.
*/
// TODO: Use this to automatically provide node keys where required.
public fieldSource?(
key: FieldKey,
schema: TreeFieldStoredSchema,
): undefined | FieldGenerator;
}

/**
Expand Down
55 changes: 0 additions & 55 deletions packages/dds/tree/src/feature-libraries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,11 @@
*/

export {
createDataBinderBuffering,
createDataBinderDirect,
createDataBinderInvalidating,
createBinderOptions,
createFlushableBinderOptions,
type DataBinder,
type BinderOptions,
type Flushable,
type FlushableBinderOptions,
type FlushableDataBinder,
type MatchPolicy,
type SubtreePolicy,
type BindSyntaxTree,
indexSymbol,
type BindPolicy,
type BindTree,
type BindTreeDefault,
type DownPath,
type BindPath,
type PathStep,
BindingType,
type BindingContextType,
type BindingContext,
type VisitorBindingContext,
type RemoveBindingContext,
type InsertBindingContext,
type BatchBindingContext,
type InvalidationBindingContext,
type OperationBinderEvents,
type InvalidationBinderEvents,
type CompareFunction,
type BinderEventsCompare,
type AnchorsCompare,
toDownPath,
comparePipeline,
compileSyntaxTree,
} from "./editableTreeBinder.js";

export { allowsValue, assertAllowedValue, isTreeValue } from "./valueUtilities.js";

export type { FieldGenerator, TreeDataContext } from "./fieldGenerator.js";

export { ForestSummarizer } from "./forest-summary/index.js";
export {
cursorForMapTreeField,
Expand Down Expand Up @@ -117,28 +80,12 @@ export {
} from "./modular-schema/index.js";

export {
type FlexTreeNodeSchema,
type FlexAllowedTypes,
FlexFieldSchema,
type FlexTreeSchema,
type LazyTreeNodeSchema,
LeafNodeSchema,
FlexMapNodeSchema,
FlexObjectNodeSchema,
schemaIsLeaf,
type Unenforced,
type AllowedTypeSet,
markEager,
type FlexMapFieldSchema,
type SchemaCollection,
TreeNodeSchemaBase,
type LazyItem,
type FlexListToUnion,
type ExtractItemType,
isLazy,
intoStoredSchema,
intoStoredSchemaCollection,
type NormalizeLazyItem,
type FlexList,
} from "./typed-schema/index.js";

Expand Down Expand Up @@ -222,8 +169,6 @@ export {
FlexTreeEntityKind,
} from "./flex-tree/index.js";

export { treeSchemaFromStoredSchema } from "./storedToViewSchema.js";

export { TreeCompressionStrategy } from "./treeCompressionUtils.js";

export { valueSchemaAllows } from "./valueUtilities.js";
Expand Down
100 changes: 0 additions & 100 deletions packages/dds/tree/src/feature-libraries/storedToViewSchema.ts

This file was deleted.

87 changes: 3 additions & 84 deletions packages/dds/tree/src/feature-libraries/typed-schema/flexList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,17 @@ export function markEager<T>(t: T): T {
*/
export type FlexList<Item = unknown> = readonly LazyItem<Item>[];

/**
* Given a `FlexList` of eager and lazy items, return an equivalent list where all items are lazy.
*/
export function normalizeFlexListLazy<List extends FlexList>(
t: List,
): FlexListToLazyArray<List> {
return t.map((value: LazyItem) => {
if (isLazy(value)) {
return value;
}
return () => value;
}) as FlexListToLazyArray<List>;
}

/**
* Given a `FlexList` of eager and lazy items, return an equivalent list where all items are eager.
*/
export function normalizeFlexListEager<List extends FlexList>(
t: List,
): FlexListToNonLazyArray<List> {
const data: readonly unknown[] = t.map((value: LazyItem) => {
export function normalizeFlexListEager<T>(t: FlexList<T>): T[] {
const data: T[] = t.map((value: LazyItem<T>) => {
if (isLazy(value)) {
return value();
}
return value;
});
return data as FlexListToNonLazyArray<List>;
return data;
}

/**
Expand All @@ -86,12 +70,6 @@ export function normalizeFlexListEager<List extends FlexList>(
*/
export type LazyItem<Item = unknown> = Item | (() => Item);

/**
*/
export type NormalizedFlexList<Item> = readonly Item[];

export type NormalizedLazyFlexList<Item> = (() => Item)[];

/**
* Get the `Item` type from a `LazyItem<Item>`.
* @system @public
Expand All @@ -100,67 +78,8 @@ export type ExtractItemType<Item extends LazyItem> = Item extends () => infer Re
? Result
: Item;

/**
*/
export type ExtractListItemType<List extends FlexList> = List extends FlexList<infer Item>
? Item
: unknown;

export type NormalizeLazyItem<List extends LazyItem> = List extends () => unknown
? List
: () => List;

/**
* Normalize FlexList type to a non-lazy array.
*/
export type FlexListToNonLazyArray<List extends FlexList> =
ArrayHasFixedLength<List> extends true
? ConstantFlexListToNonLazyArray<List>
: NormalizedFlexList<ExtractListItemType<List>>;

/**
* Normalize FlexList type to a union.
* @system @public
*/
export type FlexListToUnion<TList extends FlexList> = ExtractItemType<TList[number]>;

/**
* Normalize FlexList type to a non-lazy array.
*/
export type ConstantFlexListToNonLazyArray<List extends FlexList> = List extends readonly [
infer Head,
...infer Tail,
]
? [ExtractItemType<Head>, ...ConstantFlexListToNonLazyArray<Tail>]
: [];

/**
* Detect if an array is a Tuple (fixed length) or unknown length.
*
* Types which many have one of multiple fixed lengths (like `[] | [0]`) count as having a fixed length.
*
* @remarks
* Type operations designed to work on tuples can often behave very badly on regular arrays.
* For example recursive patterns for processing them often just return the base case,
* losing all the type information.
*/
// This works by determining if the length is `number` (and not a specific number).
export type ArrayHasFixedLength<List extends readonly unknown[]> =
number extends List["length"] ? false : true;

/**
* Normalize FlexList type to a lazy array.
*/
export type FlexListToLazyArray<List extends FlexList> = ArrayHasFixedLength<List> extends true
? ConstantFlexListToLazyArray<List>
: NormalizedLazyFlexList<ExtractListItemType<List>>;

/**
* Normalize FlexList type to a lazy array.
*/
export type ConstantFlexListToLazyArray<List extends FlexList> = List extends readonly [
infer Head,
...infer Tail,
]
? [NormalizeLazyItem<Head>, ...ConstantFlexListToLazyArray<Tail>]
: [];
Loading

0 comments on commit 6cc8df2

Please sign in to comment.