-
-
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
[FEATURE ember-views-tagless-jquery] add support for this.$() in tagless components #12500
Conversation
if (lastNode.nodeType !== 8) { range = range.add(lastNode); } | ||
|
||
//Return inner find and topmost elements filter if a selector is provided | ||
return sel ? jQuery(sel, range).add(range.filter(sel)) : range; |
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.
can you explain this? Doesn't 'jQuery(sel, range)' do the work we need? I guess what I'm asking is, what is the result of the '.add(range.filter(sel))' bit?
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.
It's a bit tricky. Example:
Suppose the sollowing HTML
<ul>
<li></li>
<li class="second-li"></li>
<li></li>
</ul>
Suppose var lis
is the result of $('li')
.
If you then to $('.second-li', lis)
, the second li won't be returned. Basically, jquery "finds" if the inner elements match the selector, not if elements themselves match.
.add(range.filter(sel))
will make sure we also consider the topmost elements that match sel
.
Looks pretty good to me. I'll try to play with it a bit more tonight. One thing we have to make sure is that all new features are properly documented. Can you add API docs here and review the guides repo to check if any changes are needed there? |
@rwjblue I've added a note on the API docs. |
Views are back? 👻 |
@btecu Components extend Views, currently: https://github.com/emberjs/ember.js/blob/master/packages%2Fember-views%2Flib%2Fcomponents%2Fcomponent.js#L118 |
In general we need at least two core team members to 👍 to merge a new feature (behind a flag), and then later we vote to enable or not. This looks good to me. @mixonic - Mind merging if this looks good to you also? |
@miguelcobain - Sadly, I just caused a merge conflict for you in |
Done. |
I believe @wycats has some doubts about this, specifically around the selector stability (e.g. what if the first/last nodes are dynamic ( |
@chancancode - Great points @miguelcobain - Can you add a test that has the first and last nodes as invoked components using:
|
There's an "issue". If the template is Is this expected? Don't really know how this text node is coming up. |
I've updated the PR.
The reason for not ignoring empty text nodes in between is basically a "conservative" measure, i.e ignore the least possible. /cc @rwjblue @chancancode |
Please let me know if anything is missing here. |
@chancancode - Tests were added to address the concerns you listed above. Mind reviewing again? I'm game to let this simmer on canary as a feature while we play with the functionality. We can always decide to remove if we have specific issues about go forward compatibility... |
I am 👍. Looks good! |
|
||
QUnit.test('returned jQuery object ignores first and last empty text nodes', function() { | ||
var registry = new Registry(); | ||
var container = registry.container(); |
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.
This needs to be tweaked a bit:
// at the top
import buildOwner from 'container/tests/test-helpers/build-owner';
import { OWNER } from 'container/owner';
var owner = buildOwner();
owner.register(/* stuff here */);
// later after registrations
View.extend({
[OWNER]: owner
})
I'm a little bit concerned about adding such a significant feature that will constrain backwards compatibility at this point. I'm also concerned about the fact that we're changing the meaning of I don't think we need to rush this right now. There are a number of view-layer balls in the air at the moment and we should revisit this once they settle. |
☔ The latest upstream changes (presumably #12673) made this pull request unmergeable. Please resolve the merge conflicts. |
@wycats I kind of like this, I think though it should be clear in the documentation that .$() array like is not maintained, it will be a snapshot. |
LOL, I just noticed how much of a jerk I looked like replying to @homu. |
I'm willing to create a legacy polyfill for this if we land it. @krisselden @wycats As far as subtle difference concerns go, luckily you usually know you are working in a tagless component, since you had to explicitly set it to be so. The alternative could be something like |
@miguelcobain is this PR inactive? Was the another resolution for this issue? |
Any updates on this PR? @miguelcobain |
@crtvhd the core team didn't seem to approve this PR (or at least it looked so to me). With the recent efforts to make ember jquery independent, I don't know if this is the way anymore. |
@miguelcobain Apparently! Which is a bummer as I just ran into this problem: Toggling Ranges sound like they might be in fact a good fit here. Nonetheless I think we should close this PR since it wasn't accepted. In case you or anyone else wants to propose another approach using Ranges you/they can open a new PR. |
@miguelcobain Sorry that we never gave you a clear direction on this. We just discussed how to move forward at the core team meeting and, while we decided against accepting this PR, we agree this is an important use case and want to expose it in a first-class way. There are a few reasons we didn't want to add support for
Glimmer already has an internal, first-class notion of stable "bounds" objects that point to a first and last element. In Ember, these are exposed via the (admittedly still private) Based on today's discussion, we think the best path forward is to work on a design that exposes the notion of a component's bounds as first-class, public API. If that existed, it would hopefully make implementing the jQuery-based functionality of this PR pretty straightforward for an addon. Thank you very much for the PR and for prompting this discussion! |
Tests are green with and without features flags enabled.
This seems to be the most concise way of returning a range of objects in jquery.
Please let me know if something's missing.