-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Conversation
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.
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. |
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.
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.
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.
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.
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.
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.
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.
Approved mod some deletion of logs.
This feels solid.
The basics
The details
Proposed Changes
This PR gets rid of the
INavigable
interface, since it was reduced to justgetClass()
, and there was significant objection to that. Instead, we now act directly onIFocusableNode
instances. As a side effect, this also makes navigation policies Just Work forField
subclasses, and opens up the possibility of removing the cursor'scurNode
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 theNavigator
.