-
Notifications
You must be signed in to change notification settings - Fork 34
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
How to resolve "Use vDOM listener instead" #10
Comments
Running into this as well... Can someone point us in the right direction on how to fix that problem/example? The docs use this example too, so something might need fixing there as well? I'm willing to open a PR there if needed. |
Ok, according to the StencilJS docs example, using
Should the Stencil docs be updated to reflect this updated guideline? |
@VincentN -- So, couple questions...
I think adding event listeners is so ubiquitous, the docs should definitely have an example of the preferred method... and if that's not using the |
Hi @chris-dura, legitimate questions.
I'm hoping someone with more intimate knowledge of this linting rule can clear up this confusion... |
I just ran into this as well, and am wondering if this rule is actually correct. Looks like it was added in #2 by @d0whc3r and merged by @manucorporat. There is no discussion on the PR. Could one of you chime in on the thinking behind this rule? |
Well, this rule is originally from the stencil-eslint package my pr only updates code style, and there is a documentation for this rule, https://github.com/ionic-team/stencil-eslint/blob/master/docs/prefer-vdom-listener.md this rule refers that you better define "vdom-events" in tsx code instead of using You always can disable the rule in you eslint config |
@d0whc3r -- Yes, of course. But, I think there's still a couple points that haven't really been addressed by someone "in-the-know"... In particular, the reasoning for the rule (ie, why is using (Maybe that's where I'm mistaken -- perhaps it is just a code style preference, but that seems like a weird default since But, also, imo, having examples in the docs that break the rules potentially can (and in my case has 😅) caused some confusion for new users. Especially when there's no direction on the recommended way to listen to "vDOM events", if we're not supposed to use |
Documentation was written before stencil-eslint and maybe it needs to be reviewed otherwise when you use events in "html" code it will be checked by typescript and maybe in some components you will see that event is wrong this could help to catch some issues |
Have hit the lint error and this issue is the top google result, and I am still unsure why this rule exists and what sorts of issues it is intended to catch. I would love some extra docs on this as well if anyone knowledgeable can contribute. |
This is just a guess, but have
As far as I can find, it was originally added here: f72d472#diff-1c48f86a4f47de44e085c3d33a0106e365eae17ee5e81b2b648a463551d0dfab The description at that time was "This rule catches Stencil Props marked as private or protected.", but that seems to just be a copy-paste mistake from this file: https://github.com/ionic-team/stencil-eslint/blob/f72d4728157cc68928e4afe8caf9b97c6d143438/src/rules/methods-must-be-public.ts |
This guess makes totally sense to me. I'm now "silencing" the error message by providing the passive argument to the decorator: @Listen('keydown', {
passive: true,
})
handleKeyDown(ev: KeyboardEvent) {
// ...
} Note that you can also pass I also learnt that I need to specify a target in the options in order for the event to be triggered outside my component: I would sleep better though if there was someone who could clarify the error message intent. |
Thanks for the issue! This issue is being closed due to inactivity. If this is still an issue with the latest version of Stencil, please create a new issue and ensure the template is fully filled out. Thank you for using Stencil! |
Ah, some of these issues are so old that they're getting cleared automatically. Sorry about that! |
Noobie question — I’m using an example straight from the Stencil docs…
I get an error
Use vDOM listener instead
, and I don’t exactly know how to resolve that… 😬In other words, I don't exactly know how to "use a vDOM listener instead".
Also, according to the rule docs, this rule is meant to "Ensures that no vdom events are used in
@Listen
decorator." Why is it bad to listen to vDOM events using the@Listen
decorator?The text was updated successfully, but these errors were encountered: