-
-
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
Element Modifiers #112
Element Modifiers #112
Conversation
This looks good, thanks for taking the time to put it together. I have a few thoughts/questions:
Again, great job on this, and thank you for pushing this forward! |
We should also detail how this interacts with angle bracket components.
|
I'm wondering if there is value in giving well defined and dependent hooks. My worry is around the higher potential of memory leaks being introduced into a project. If you had hooks like let hasListener = !!element.setupListeners;
let hasRemoveListener = !!element.teardownListeners;
assert(`You setup an event listener on ${element.toString()}, but did not tear it down in `teardownListeners`. If you are not setting up a listener please use another hook.`, component.setupListeners && !hasRemoveListener) |
Totally an aside, but I hope if we ever have a helper like |
Mixing existing ideas (the global dispatcher) with this approach, this would solve the problem that Something like
could use Ember's global dispatcher and avoid adding/removing loads of event handlers if the collection changes? |
In pre 2.0 lots of confusion was coming from the fact that Ember had way too much "primitives". I was hoping we were on the right path with components only in 2.0. But we introduced state full helpers and now this. This is not a complaint out of nowhere - I already found myself in situations where I had to explain to some people how a state full helper is different from a component... Feels like explaining how a view is different form a component in 1.0... I understand that there is a problem to be solved here, but I feel that this will extend api surface in the area where it is already pretty large. |
To some extent I feel the same way than @tchak about this, and I wonder if there is any way of unify helpers with this. I understand that there is a API gap that has to be filled. Some sort of helpers with access to the DOM of the element they are invoked in. Perhaps just a stateful helper that happens to have lifecycle hooks other than I don't know if can be considered having less primitives, because it's basically adding more capabilities to one existing primitive. Something that I like is the fact that this would remove the dicotomy of
It would formalize an existing magic in ember. |
Thanks @mixonic, this is excellent. From an addon-author’s point of view, I would love to move the API for ember-sortable towards something like: {{! my-cool-template.hbs}}
<ul>
{{#sortable-group as |group|}}
{{#each items as |item|}}
<li {{group.sortable-item model=item}}>{{item.name}}</li>
{{/each}}
{{/sortable-group}}
</ul> {{! sortable-group.hbs}}
{{yield (hash
sortable-item=(element-modifier "sortable-item" group=this)
)}} Note the assumed availability of yielding contextual-element-modifiers. Did you see that as being a possibility? |
During rendering and teardown of a target element, any attached element | ||
modifiers will execute a series of hooks. These hooks are: | ||
|
||
* `willInsertElement` (only upon initial render) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the use case for this with an element modifier? I was thinking these would be scope to didInsertElement and willDestroyElement
Am I correct in assuming these are isomorphic to decorators, maybe a class decorator if one assumes each element is a class (for this discussion) |
Should this have a |
Thanks for the early feedback all. I'm still digesting but will take a pass at improvements soon. From @rwjblue:
To me, this is the most concerning comment. The proposal as it stands leans heavily on the API of components, with the goal not introducing a new set of hook names when they already largely match components. Using |
@taras I'm still very much in favor of completing an RFC for this feature, though the implementation is indeed very likely blocked on Glimmer 2. The API design is somewhat intertwined with that of Glimmer components, since I would like the way attrs are passed to match the Glimmer component API. For example this seems plausible: <div
class="red button"
{{on-event 'click' (action 'save' model) bubble=false}}
>Save</div> Roughly:
Again some of this is directly related to what APIs we design for Glimmer components, so I'll need to coordinate w/ @wycats and others to get consensus. I'm eager to take another pass :-) |
Looking forward to some of this picking up now that Glimmer2 has basically landed. |
Fix noodle example
This is also something I find interesting and it's a shame it has been staled for a year. Was it abandoned for specific reasons? |
Probably the priorities have been diverted, but this seems like an important topic, especially for glimmer.js and it's custom elements story. It should work its way upstream I think. |
I think progress on this is again tractable. The biggest blocker is the API for how to access positional and named arguments inside the modifier. The hooks should be normalized to match those on Glimmer components. I'm wary of trying to push it forward before closing up the namespaces/addon support for module unification, re: my own time management 😬 |
Long belated: Closing this in favor of #353 |
Rendered