Skip to content
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

Convert HighlightOverlay to TypeScript #1375

Closed
jessegreenberg opened this issue Mar 13, 2022 · 3 comments
Closed

Convert HighlightOverlay to TypeScript #1375

jessegreenberg opened this issue Mar 13, 2022 · 3 comments
Assignees

Comments

@jessegreenberg
Copy link
Contributor

It would be nice to have types for highlights in #1372 so I took a stab at converting HighlightOverlay to TypeScript. But I would like to review a portion of the conversion with someone that is familiar with the TypeScript mixin/trait pattern.

Most notably I needed typing for "A node that mixes ReadingBlock/InteractiveHighlighting". I looked at Poolable and I think I did it in a similar way. It seems to work but duplicates much of the interface of ReadingBlock and InteractiveHighlighting to define a type.

Also, I had to use IProperty<boolean> instead of BooleanProperty for the HIghlightOverlayOptions so that those Properties work well when they are set from the Properties of FocusManager in Display.ts. Is there a reason to use IProperty<boolean> instead of BooleanProperty?

Commits coming.

@jessegreenberg
Copy link
Contributor Author

Conversion is done, I did some fuzz testing and basic spot checking and all seems well. The part I want to review in particular is

interface InteractiveHighlightingInterface {
interactiveHighlightChangedEmitter: TinyEmitter;
readonly interactiveHighlightLayerable: boolean;
readonly interactiveHighlightActivated: boolean;
readonly isInteractiveHighlighting: boolean;
interactiveHighlight: Highlight;
setInteractiveHighlight( highlight: Highlight ): void;
getInteractiveHighlight(): Highlight;
setInteractiveHighlightLayerable( layerable: boolean ): void
getInteractiveHighlightLayerable(): boolean
isInteractiveHighlightActivated(): boolean;
dispose(): boolean;
}
// For type checking when you need to verify that a Type is composed with InteractiveHighlighting
type InteractiveHighlightingVersion<Type extends Constructor> = InstanceType<Type> & InteractiveHighlightingInterface;
and the similar one in ReadingBlock.ts.

@zepumph or @jonathanolson does this seem right to you or is there a way to reduce the duplication of InteractiveHighlightingInterface?

@jessegreenberg
Copy link
Contributor Author

jessegreenberg commented Mar 14, 2022

Discussed with @jonathanolson , he recommended looking at the WidthSizableNode example to avoid the duplication.

// Some typescript gymnastics to provide a user-defined type guard that treats something as widthSizable
const wrapper = () => WidthSizable( Node );
type WidthSizableNode = InstanceType<ReturnType<typeof wrapper>>;
const isWidthSizable = ( node: Node ): node is WidthSizableNode => {
  return node.widthSizable;
};

@jessegreenberg
Copy link
Contributor Author

#1375 (comment) is working great for both InteractiveHighlighting and ReadingBlock. That is it for the TS conversion of HighlightOverlay. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants