-
-
Notifications
You must be signed in to change notification settings - Fork 408
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
rendering events #365
Comments
Thanks for putting this together. I'm realizing that I might need to add some more examples on what you could use modifiers for in my original RFC. That being said I have some questions and observations.
|
Thank you very much for your feedback!
same behaviour then with actions. Of course you need some place to implement the hooks. But you could even pass the action into the component:
When passing it in:
and if you do
Absolutely, thats the idea:
So you can do this:
with this action:
This is a good point. I'm not sure about this, since AFAIK actually not everything is allowed to be an HTML attribute by the HTML spec. But if we consider it a breaking change we can introduce it only to the new glimmer components and to classic components only with a optional feature. I think its save to assume that not many feature have HTML attributes with
Well, it would save us from the breaking change. I'm also not sure about this. The current model for the Well, this is only a mental model, and not how it needs to be implemented. |
I've tried to adapt your examples from the RFC: Performance Marking<section id="about-us" DidInsertElement={{performance 'mark' 'about-page'}}>
<h1>About Us</h1>
{{!-- snip --}}
</section> And import Ember from 'ember';
export function performance([type, marker]/*, hash*/) {
return () => performance[type](marker);;
}
export default Ember.Helper.helper(performance); jQuery Widget <Datepicker @changeMonth=true @changeYear=true />
<input type="date" DidInsertElement={{action 'didInsert'}} WillDestroyElement={{action 'willDestroy'}} /> import Component from '@ember/component';
export default Component.extend({
_normalizeOptions(options) {
return Object.assign(options, { minDate: 20, maxDate: '+1M +10D' });
},
actions: {
didInsert(event) {
$(event.target).datepicker(this._normalizeOptions(this.args)); // we dont have this.args yet, but this.attrs.
},
willDestroy(event) {
$(event.target).datepicker('destroy');
},
}
}) Page View TrackingThis is actually easiert with a <TrackImpressionSection @eventCategory="Post">
<header>Chad liked a post</header>
<img src="cat.jpg">
{{!-- Snip --}}
</TrackImpressionSection> and the component <section DidInsertElement={{action 'didInsert'}} WillDestroyElement={{action 'willDestroy'}}>
{{yield}}
</section> import { inject as service } from '@ember/service';
import Component from '@ember/component';
export default Component.extend({
ga: service('google-analytics'),
init() {
this._super(...arguments);
this.eventCategory = undefined;
this.interSectionObserver = new IntersectionObserver(entries => {
entries.forEach(entry => {
this.ga.send('event', 'impression', this.eventCategory);
});
});
},
didInsert(event) {
this.interSectionObserver.observe(event.target);
},
willDestroyElement(event) {
this.interSectionObserver.unobserve(event.target);
}
}); |
I'm doing some issue gardening 🌱🌿 🌷 and came upon this issue. Since it's quite old I just wanted to ask if this is still relevant? If it isn't, maybe we can close this issue? Element modifiers is out now, do they solve your problem? There is also https://github.com/pzuraq/ember-could-get-used-to-this which you could take a look at. By closing some old issues we reduce the list of open issues to a more manageable set. |
I'm closing this due to inactivity. This doesn't mean that the idea presented here is invalid, but that, unfortunately, nobody has taken the effort to spearhead it and bring it to completion. Please feel free to advocate for it if you believe that this is still worth pursuing. Thanks! |
This is meant to be an alternative to modifiers (#353). Also this is a bit a vague idea I just had, and I would love some feedback. If some people like it I will try my best and try to write an RFC for this.
Basically why don't we just introduce rendering events like normal DOM events?
This would be very straightforward to teach to everyone who understands closure actions!
The
didInsertButton
andwillDestroyButton
actions would receive a synthesizedevent
property as single argument with atarget
property pointing to the DOM node.For this example I've used uppercase event names to distinguish from normal events:
However maybe we should use the
@
sign, because in some ways its simmilar to the difference between arguments and attributes:The text was updated successfully, but these errors were encountered: