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

Move defaultEventNames into Schema #662

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

grncdr
Copy link

@grncdr grncdr commented Feb 17, 2023

This allows applications to extend the mapping with support for custom elements.

Closes #660

See also: this comment #661 (comment)

This allows applications to extend the mapping with support for custom
elements.

Closes hotwired#660
Copy link
Contributor

@lb- lb- left a comment

Choose a reason for hiding this comment

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

Just a few thoughts, I think this would be an awesome feature and helps for mixed adoption of Web Components.

src/core/schema.ts Outdated Show resolved Hide resolved
src/core/schema.ts Outdated Show resolved Hide resolved
@@ -29,6 +30,22 @@ export const defaultSchema: Schema = {
// [0-9]
...objectFromEntries("0123456789".split("").map((n) => [n, n])),
},
defaultEventNames: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
defaultEventNames: {
defaultEventMappings: {

Since we use the term mappings already, might be nice to align with that naming?

Copy link
Author

Choose a reason for hiding this comment

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

Obsoleted by 2ddac5f

Copy link
Author

Choose a reason for hiding this comment

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

I ended up dropping 2ddac5f so this is relevant again. I'm open to renaming it.

@lb-
Copy link
Contributor

lb- commented Feb 17, 2023

This probably needs docs also

Co-authored-by: LB (Ben Johnston) <mail@lb.ee>
@grncdr
Copy link
Author

grncdr commented Feb 18, 2023

This probably needs docs also

Definitely up for adding docs. Can I interpret your review as tacit support for this implementation vs. #661?

@lb-
Copy link
Contributor

lb- commented Feb 18, 2023

I'm not on the core team - but I love the idea of this feature so it gets my vote 👍

Copy link
Member

@marcoroth marcoroth left a comment

Choose a reason for hiding this comment

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

Thanks for proposing two solutions for issue #660, @grncdr!

In case we are going to combine this and #661 I left some small remarks in this pull request. Otherwise this looks good to me. Thanks for working on this.

src/core/schema.ts Outdated Show resolved Hide resolved
@grncdr
Copy link
Author

grncdr commented Jun 23, 2023

This now takes into account the feedback on #661 as well, setting on an Application#registerDefaultEventNames method.

I opted for the plural form of the name and passing an object because it felt nicer to write this:

app.registerDefaultEventNames({
  'sl-button': 'click',
  'sl-select': 'change',
  'sl-input': 'input',
  // etc.
})

vs this:

app.registerDefaultEventName('sl-button', 'click')
app.registerDefaultEventName('sl-select', 'change')
app.registerdDefaultEventName('sl-input', 'click')
// etc.

... but I'm open to changing it back to registerDefaultEventName.


Other concerns

There's a limitation (also covered in the docs) where this API won't work when calling Application.start() as a static method. You need to register default event names before the application starts or it won't properly bind listeners. If somebody really wants to use the static method, overriding the Schema passed to start is still possible:

Application.start(document.body, {
  ...defaultSchema,
  defaultEventNames: {
    ...defaultSchema.defaultEventNames,
    'sl-button': 'click',
    // etc.
  }
})

@dhh dhh requested a review from marcoroth June 24, 2023 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: allow extending defaultEventNames mapping
3 participants