-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[Bug] The on
modifier does not work with the modifier
helper
#19869
Comments
I did some testing and it's not only the The error is thrown from the The built-in modifiers and helpers don't seem to be registered in the container which is why the For example: import { getOwner } from '@ember/application';
import { on } from '@ember/modifier';
export default class ApplicationRoute extends Route {
constructor() {
super(...arguments);
getOwner(this).register('modifier:on', on);
}
} ember-source contains the |
I found the following in the RFC:
So it seems like these are not supported by design and it isn't actually a bug? In that case a more clear error message would still be nice though. Does that mean we need an RFC for this? |
@Windvis I think that sections are referring to cases that are really "keywords" that aren't really helpers, But I am pretty sure |
Presumably |
Yes, this should work. In addition to fixing this bug we should also do a pass on all the other helpers/modifiers/keywords/RFCs we have to see if there is anything else missing, but they don't have to block each other. |
A use case for this is to conditionally add a click handler to an element e.g.
Currently my workaround is to have a modifier that adds an event listener conditionally
|
partially fixes emberjs#19869 Due to [GlimmerVM's assertion][1], this still does not fix the issue in strict mode. We also can't work around the strict mode limitation with an AST transform since Glimmer's transforms run first. [1]: https://github.com/glimmerjs/glimmer-vm/blob/2ddbbc4a9b97db4f326c4d92021f089c464ab093/packages/%40glimmer/compiler/lib/passes/1-normalization/keywords/utils/curry.ts#L53
partially fixes emberjs#19869 Due to [GlimmerVM's assertion][1], this still does not fix the issue in strict mode. We also can't work around the strict mode limitation with an AST transform since Glimmer's transforms run first. [1]: https://github.com/glimmerjs/glimmer-vm/blob/2ddbbc4a9b97db4f326c4d92021f089c464ab093/packages/%40glimmer/compiler/lib/passes/1-normalization/keywords/utils/curry.ts#L53
For future travelers: As a workaround, here's what I ended up doing (thank you @NullVoxPopuli for helping me find the import): // app/components/my-component.js
import Component from '@glimmer/component';
import { on } from '@ember/modifier';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
export default class MyComponent extends Component {
on = on;
@tracked bindClickHandler = true;
@action handleClick() {
this.
}
} then my template looks like <button
{{(if this.bindClickHandler (modifier this.on "click" this.handleClick))}}
>Click me
</button> |
🐞 Describe the Bug
This works:
🔬 Minimal Reproduction
This doesn't:
Can't create a Twiddle because Twiddle is severely outdated, sorry.
😕 Actual Behavior
🤔 Expected Behavior
Should apply the
on
modifier to the element.🌍 Environment
CC @simonihmig
The text was updated successfully, but these errors were encountered: