Skip to content

Move defaultEventNames into Schema#662

Open
grncdr wants to merge 7 commits into
hotwired:mainfrom
grncdr:schema-event-names
Open

Move defaultEventNames into Schema#662
grncdr wants to merge 7 commits into
hotwired:mainfrom
grncdr:schema-event-names

Conversation

@grncdr

@grncdr grncdr commented Feb 17, 2023

Copy link
Copy Markdown

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

@lb- lb- left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread src/core/schema.ts Outdated
Comment thread src/core/schema.ts Outdated
Comment thread src/core/schema.ts
// [0-9]
...objectFromEntries("0123456789".split("").map((n) => [n, n])),
},
defaultEventNames: {

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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-

lb- commented Feb 17, 2023

Copy link
Copy Markdown
Contributor

This probably needs docs also

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

grncdr commented Feb 18, 2023

Copy link
Copy Markdown
Author

This probably needs docs also

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

@lb-

lb- commented Feb 18, 2023

Copy link
Copy Markdown
Contributor

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

@marcoroth marcoroth left a comment

Copy link
Copy Markdown
Member

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.

Comment thread src/core/schema.ts Outdated
Comment thread src/tests/modules/core/action_custom_default_event_tests.ts Outdated
@grncdr grncdr force-pushed the schema-event-names branch from 2ddac5f to 0af60e5 Compare June 22, 2023 22:55
@grncdr grncdr force-pushed the schema-event-names branch from 0af60e5 to 4ecb43d Compare June 23, 2023 00:01
@grncdr

grncdr commented Jun 23, 2023

Copy link
Copy Markdown
Author

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