-
Notifications
You must be signed in to change notification settings - Fork 5
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
Small tweaks from ongoing backwards compatibility struggle in plugins #1139
Conversation
56e25ad
to
298bda9
Compare
298bda9
to
32147a2
Compare
addon/components/toolbar/mark.ts
Outdated
@@ -8,25 +9,38 @@ type Args = { | |||
mark: string; | |||
}; | |||
export default class MarkComponent extends Component<Args> { | |||
constructor(owner: unknown, args: Args) { | |||
if (!args.controller?.schema.marks[args.mark]) { |
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.
if (!args.controller?.schema.marks[args.mark]) { | |
if (!args.controller.schema.marks[args.mark]) { |
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.
This suggestion would just cause it to fail to start as args.controller
will be undefined. I'll tweak this to not log on startup. I don't really want to change the way this is used just for this convenience log to work correctly.
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.
True, but then we should also adjust the argument types to mark the controller
argument as optional.
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.
Hmm, this is tricky. In this kind of context, TS assumes that your code is obeying the types, which in a pure TS codebase should (but won't always) be true. At the very least, there should be an error when you misuse something. With a mixture of TS and JS or TS and handlebars, this is no longer true.
I don't think we should change the arguments as while it no longer should crash if controller
is not supplied, the class is useless if it isn't. I can't think of a good way to, within this class body, treat Args
as partial, but keep the members of Args
as required. Just marking get controller()
as returning SayController | undefined
for example does not seem to work.
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.
why would controller be undefined?
that would mean the parent component is passing in an incorrect value, so crashing is totally fine.
Sure, you'd like a build-time warning which we lose because we pass through unchecked templates (we'll get it back when we can enable glint), but that doesn't change how we should design the component imo.
Either you support the flexibility, and type it as optional, and nullcheck yourself, or you don't, and require the calling component to make sure its not passing in undefined.
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.
Looks good to me overall! It just seems that the console log shows up a lot, because the controller
argument is not passed yet (is still undefined) when constructing the mark-buttons.
Two possible solutions to this:
- Make the
controller
argument of the buttons non-optional and only instantiate the buttons when the controller is defined - Move the schema check out of the
controller
into themark
getter and only check the existance of the mark/node-spec in the schema once the controller is defined.
32147a2
to
35fca9d
Compare
35fca9d
to
6606d47
Compare
Overview
Don't crash if we use a toolbar button for a mark that isn't in the schema and give some more fine-grained output when blackbox tests fail.
connected issues and PRs:
N/A
Setup
N/A
How to test/reproduce
Remove a mark (such as
redacted
from the schema but leave the corresponding toolbar button in place, you should get a nice console log telling you what's wrong and the button should just be disabled (it used to crash).Enable one of the failing blackbox tests and see the slightly improved failure message.
Challenges/uncertainties
N/A
Checks PR readiness