8000 refactor: Remove INavigable in favor of IFocusableNode. by gonfunko · Pull Request #9037 · google/blockly · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

refactor: Remove INavigable in favor of IFocusableNode. #9037

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

Merged
merged 3 commits into from
May 13, 2025

Conversation

gonfunko
Copy link
Contributor

The basics

The details

Proposed Changes

This PR gets rid of the INavigable interface, since it was reduced to just getClass(), and there was significant objection to that. Instead, we now act directly on IFocusableNode instances. As a side effect, this also makes navigation policies Just Work for Field subclasses, and opens up the possibility of removing the cursor's curNode in favor of asking the focus manager for the currently focused thing, although I'll address that in a followup change. Registering navigation policies has been moved out of the cursor and into the Navigator.

Copy link
Contributor
@BenHenning BenHenning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @gonfunko! Had some thoughts.

Approving to unblock, but I'm happy to take another pass. Didn't look at the flyout navigation policy super closely since it appeared to have a bunch of unfinished code int.

* the given object.
*
* @param current An instance to check whether this policy applies to.
* @returns True if the given object is of a type handled by this policy.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nit but I don't think this actually returns a boolean, I think it returns current coerced to type T or undefined if coercion fails per the predicate.

I'm not 100% certain on this and I find the TypeScript documentation unclear, but I recall debugging guards like this before and being surprised that their return values weren't actually booleans.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree the docs are unclear on this, but I think boolean is more useful to both folks reading and implementing than the perhaps technically correct value; ultimately the method needs to return a boolean (if you're implementing it) and you can rely on it being a truthy value if you call it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the language 'whether' in this case which I suppose is slightly more ambiguous (perhaps beneficially):

/**
 * Determines whether the provided object fulfills the contract of
 * IFocusableNode.
 *
 * @param object The object to test.
 * @returns Whether the provided object can be used as an IFocusableNode.
 */
export function isFocusableNode(object: any | null): object is IFocusableNode {
  return (
    object &&
    'getFocusableElement' in object &&
    'getFocusableTree' in object &&
    'onNodeFocus' in object &&
    'onNodeBlur' in object &&
    'canBeFocused' in object
  );
}

Not sure that's actually better. Note I don't have strong opinions here, so if you prefer the explicit 'True' that seems reasonable to me.

@BenHenning BenHenning assigned gonfunko and unassigned BenHenning May 13, 2025
Copy link
Collaborator
@rachel-fenichel rachel-fenichel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved mod some deletion of logs.

This feels solid.

@gonfunko gonfunko merged commit ae22165 into google:rc/v12.0.0 May 13, 2025
7 checks passed
@gonfunko gonfunko deleted the inavigable-refactor branch May 13, 2025 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0