-
Notifications
You must be signed in to change notification settings - Fork 558
FieldKind cleanup #25869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
FieldKind cleanup #25869
Changes from all commits
dc27e2a
99c8c89
f5a7bfd
996ac36
07db7b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,43 +36,34 @@ export class FlexFieldKind< | |
| // TODO: stronger typing | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| TEditor extends FieldEditor<any> = FieldEditor<any>, | ||
| TName extends string = string, | ||
| TName extends FieldKindIdentifier = FieldKindIdentifier, | ||
| TMultiplicity extends Multiplicity = Multiplicity, | ||
| > implements FieldKindData | ||
| { | ||
| protected _typeCheck!: MakeNominal; | ||
|
|
||
| /** | ||
| * @param identifier - Globally scoped identifier. | ||
| * @param multiplicity - bound on the number of children that fields of this kind may have. | ||
| * TODO: replace with numeric upper and lower bounds. | ||
|
Comment on lines
-46
to
-48
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These docs were moved to FieldKindData, and still apply here (and show up in IntelliSense) due to |
||
| * @param changeHandler - Change handling policy. | ||
| * @param allowsTreeSupersetOf - returns true iff `superset` supports all that this does | ||
| * and `superset` is an allowed upgrade. Does not have to handle the `never` cases. | ||
| * See {@link isNeverField}. | ||
| * TODO: when used as a method (instead of a free function like the other superset related functions), | ||
| * this name is/signature is confusing and seems backwards. | ||
| * @param handlesEditsFrom - Kinds (in addition to this) whose edits can be processed by changeHandler. | ||
| * If the kind of a field changes, and edits are rebased across that kind change, | ||
| * listing the other old kind here can prevent those edits from being conflicted and | ||
| * provide a chance to handle them. | ||
|
Comment on lines
-49
to
-58
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These docs moved to the members of FieldKindOptions |
||
| * Change handling policy. | ||
| */ | ||
| // TODO: stronger typing | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| public readonly changeHandler: FieldChangeHandler<any, TEditor>; | ||
|
|
||
| public constructor( | ||
| public readonly identifier: TName & FieldKindIdentifier, | ||
| public readonly identifier: TName, | ||
| public readonly multiplicity: TMultiplicity, | ||
| // TODO: stronger typing | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| public readonly changeHandler: FieldChangeHandler<any, TEditor>, | ||
| private readonly allowsTreeSupersetOf: ( | ||
| originalTypes: TreeTypeSet, | ||
| superset: TreeFieldStoredSchema, | ||
| ) => boolean, | ||
| public readonly handlesEditsFrom: ReadonlySet<FieldKindIdentifier>, | ||
| ) {} | ||
| private readonly options: FieldKindOptions<FieldChangeHandler<any, TEditor>>, | ||
| ) { | ||
| this.changeHandler = options.changeHandler; | ||
| } | ||
|
|
||
| /** | ||
| * Returns true if and only if `superset` permits a (non-strict) superset of the subtrees | ||
| * allowed by field made from `this` and `originalTypes`. | ||
| * | ||
| * TODO: clarify the relationship between this and FieldKindData, and issues with cyclic schema upgrades. | ||
| */ | ||
| public allowsFieldSuperset( | ||
| policy: SchemaPolicy, | ||
|
|
@@ -93,10 +84,43 @@ export class FlexFieldKind< | |
| if (isNeverField(policy, originalData, superset)) { | ||
| return false; | ||
| } | ||
| return this.allowsTreeSupersetOf(originalTypes, superset); | ||
| return this.options.allowsTreeSupersetOf(originalTypes, superset); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Additional options for {@link FlexFieldKind}. | ||
| * | ||
| * @remarks | ||
| * Puts the more confusing parameters into this object so they get explicit names to help with clarity. | ||
| */ | ||
| export interface FieldKindOptions<TFieldChangeHandler> { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was made force some of the less obvious from context parameters to the constructor into named members of an object for improved readability. |
||
| /** | ||
| * Change handling policy. | ||
| */ | ||
| readonly changeHandler: TFieldChangeHandler; | ||
|
|
||
| /** | ||
| * Returns true if and only if `superset` permits a (non-strict) superset of the subtrees | ||
| * allowed by field made from `this` and `originalTypes`. | ||
| * @remarks | ||
| * Used by {@link FlexFieldKind.allowsFieldSuperset}, which handles the `never` cases before calling this. | ||
| */ | ||
| readonly allowsTreeSupersetOf: ( | ||
| originalTypes: TreeTypeSet, | ||
| superset: TreeFieldStoredSchema, | ||
| ) => boolean; | ||
|
|
||
| /** | ||
| * Kinds (in addition to this) whose edits can be processed by changeHandler. | ||
| * If the kind of a field changes, and edits are rebased across that kind change, | ||
| * listing the other old kind here can prevent those edits from being conflicted and | ||
| * provide a chance to handle them. | ||
| */ | ||
| // TODO: provide this and use it for improved support for rebasing changes across schema upgrades. | ||
| // readonly handlesEditsFrom: ReadonlySet<FieldKindIdentifier>; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We never implemented the ability to preserve edits across schema changes, so this option which only exists to allow preserving edits to a field whose schema has changed never has had an opportunity to do anything, and has also never been provided as anything but empty. Someday we will likely want this back, but for now it does not need to exist. |
||
| } | ||
|
|
||
| /** | ||
| * Policy from the app for interpreting the stored schema. | ||
| * The app must ensure consistency for all users of the document. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename from "value" to "required" was done long ago, but not everything was renamed. The field kind identifier has to stay, but these kinds of things can be updated to make things more consistant.