-
Notifications
You must be signed in to change notification settings - Fork 10
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
Support event handlers #42
Comments
it might be possible to do this, yes. but it does raise the complexity of this codemod significantly. It also still does not solve the second issue in https://github.com/ember-codemods/tagless-ember-components-codemod#known-caveats, so it still has similar caveats. |
But these are two different concerns in my opinions. Being able to automatically convert components to outerHTML is one thing, handling breaking changes that these may introduce is another one. There are a lot of changes that may be considered breaking depending on what is considered part of the public API if converting a component to outerHTML... |
I agree. For one thing IMHO this is pretty much an anti-pattern, to set/override an event handler from outside. But more importantly, you will always have to fix that "API" usage when refactoring to tag-less components (and eventually later to Glimmer, as I see this codemod mainly as a stepping stone for, right?), irregardless of how you manage the transformation (with the codemod, or manually). So this is a general "problem" with tag-less components, and not a particular concern of the codemod. |
@simonihmig @jelhan @Turbo87 I've been mulling on this one as I put together out guidance internally for the app I work on, and as @lbdm44 and I dug into it, we concluded it's probably best not to do it, for one specific reason: the built-in component event handlers fire Ember events, while |
I think the difference only matters in a very few cases. This codemod has already proven it's value when migrating the huge code base of Ember Bootstrap. It's way better to have a codemod that migrates 95% of the cases correctly and fixing the other 5% by hand than needing to do everything manually in my opinion. But I get the argument that codemods should only do safe transforms by default. Not everyone has a good test coverage. Adding the ones which might break stuff in edge cases behind a feature flag is a good compromise in my opinion. Splitting it over several different repos doesn't help as you might need a combination of risky features to migrate a single component (e.g. event handlers and class name bindings). |
I tend to agree. I think the safest option would be to use a CLI flag that is off by default and explained in the README. |
Thanks for your views folks, with which I strongly disagree! 😜 I am probably opening a can of worms here, and what follows is not very specific to the problem at hand here, but more of a general nature. But I am asking myself what kind of role a codemod should play. Possibility A: a codemod should strive for correctness, i.e. do transformations of code that result in another form of code that is equivalent to the input. Or in other words that does not break things. That sounds good at first, but without going into CS-y terms like NP-completeness it is still fair to say that correctness is a noble goal at best here. I have yet to see a codemod that comes even close (unless it is doing just micro-syntax like transformations). E.g. the native class codemod run on a larger codebase of ours broke so many things in so many ways (admittedly quite some time ago). On the other hand there is possibility B: a codemod should just provide value to its user, by doing the kind of code transformations that it can reasonably do and are useful, while leaving those that require a human brain to the user. I am obviously in this camp. To back this up: when I ran this codemod on ember-bootstrap's codebase, it skipped over ~95% of the components. Those that it did transform were so trivial, that I could have done those probably in only slightly more time as running So to get value out of it, this one and a couple of other PRs were required, and I had to comment out this line locally to not skip when Further on the point of correctness: as said above this codemod skips over components that call
You could probably consider this a bug. But what about this:
Would you want to write this? Hopefully not. Is it valid JS? Certainly. Would a codemod not detecting this and thereby breaking your code be considered incorrect in a strict sense? I think so! My point is, to prioritize bringing value to the user than to strive for correctness. I am not saying the latter is unimportant, but that the former is more important, IMO! @chriskrycho to your point of Ember events: yes, I understand, and I believe I am pretty much aware of the differences. But as you also know there is no other way than to deal with those native events with
I am ok with that in general. In this case I would probably prefer a general flag like strict mode vs. loose mode, to allow for more optional transformations. But tbh, as I tried to explain above, I don't expect that strict mode (the default) will provide a lot of practical value.
Exactly. You cannot transform the class without migrating event handlers, and you also cannot migrate event handlers without moving the component's "root" element into the template. So all of that has to happen in one transformation. I cannot see how separate codemods could do this. Sorry for the long ramblings here! 😝 Have a nice weekend, and stay safe! 😀 |
In the current form, it seems to me the codemod will skip over a lot of components, as many will have at least one event handler like
click()
.I believe it should be possible to transform these:
will be migrated to:
Or do I miss something that would make that more complicated?
Btw, this is assuming we have #3, don't know how useful this is for classic classes. 🤔
The text was updated successfully, but these errors were encountered: