-
-
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
Add index as an optional parameter to #each blocks #10160
Conversation
Can you add something for changing indexes? run(function() {
view.controller.unshiftObject({ name: "Bob" });
});
equal(view.$().text(), "0. Bob1. Adam2. Steve"); |
Totally agree that this test belongs in ember-views, but it's fine to leave it in ember-htmlbars for now. Historically the view tests have been in the templating packages because its easier to setup the view hierarchy. I do plan on moving the more unit-y tests to ember-views one day. |
Yes! I'll do that now |
Should I push with that test failing? I don't really know how to fix that |
@tim-evans Ah, turns out contentIndex doesn't update currently. It will be a bit more complicated. |
@tim-evans I got it working. See if you can incorporate this: https://github.com/mmun/ember.js/tree/each-index |
Merged! |
Can you add a feature flag (It adds new API) and squash all the commits? Otherwise its good to merge. |
👍 great work guys |
@mmun done |
@@ -357,13 +357,35 @@ var CollectionView = ContainerView.extend({ | |||
item = content.objectAt(idx); | |||
|
|||
itemViewProps.content = item; | |||
itemViewProps._blockArguments = [item]; | |||
if (!Ember.FEATURES.isEnabled('ember-each-with-index')) { |
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.
Due to a limitation of defeatureify
we cannot use !Ember.FEATUREs.isEnabled
, you have to use:
if (Ember.FEATURES.isEnabled('blah')) {
} else {
/* your stuff here */
}
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.
So I need a blank if for this one?
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.
Sadly yes, I am sorry. :(
@rwjblue done. |
} else if (this.blockParams === 1) { | ||
view._blockArguments = [item]; | ||
} | ||
} |
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.
...move it down here.
if (Ember.FEATURES.isEnabled('ember-htmlbars-each-with-index')) {
if (this.blockParams > 1) {
view._blockArguments = [item, view.getStream('_view.contentIndex')];
} else if (this.blockParams === 1) {
view._blockArguments = [item];
}
} else {
if (this.blockParams > 0) {
view._blockArguments = [item];
}
}
this adds index as an optional second parameter to #each blocks fixes #10158
Oh goodness. Lots of tweaks. I hope this is the last one! |
Add index as an optional parameter to #each blocks
Thanks! 👍 (especially @mmun !) |
@tim-evans - thank you! |
As of #10193 this is enabled by default on canary (and slated for 1.11 barring any issues). |
This is the work for #10158.