Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat ngRepeat: add $even and $odd properties to iterator #3282

Closed
wants to merge 1 commit into from

Conversation

npup
Copy link
Contributor

@npup npup commented Jul 19, 2013

When iterating, odd/even status is often nice to to have readily available in a
highly readable way.
These properties are not coupled to using CSS classes in the way of ngClassEven
and ngClassOdd directives.

@npup
Copy link
Contributor Author

npup commented Jul 19, 2013

There is something strange going on with the Travis build on Chrome:
Chrome 30.0.1568 (Mac OS X 10.7.5) ngMock angular.mock.dump should be published on window FAILED

This does not fail for Firefox. Saw someone else's pull req (#3280) also had a Travis build fail like this one. Looks like neither of us touched anything that would upset Chrome, so we should look upstream probably?

@pkozlowski-opensource
Copy link
Member

  • Contributor signed CLA now or in the past (if you just signed, leave a comment here with your real name for cross reference)
  • Feature improves existing core functionality
  • API is compatible with existing Angular apis and relevant standards (if applicable)
  • PR doesn't contain a breaking change
  • PR contains unit tests
  • PR contains e2e tests (if suitable)
  • PR contains documentation update
  • PR passes all tests on Travis (sanity)
  • PR passes all tests on ci.angularjs.org (cross-browser compatibility)
  • PR is rebased against recent master
  • PR is squashed into one commit per logical change
  • PR's commit messages are descriptive and allows us to autogenerate release notes (required [commit message

@pkozlowski-opensource
Copy link
Member

@npup Interesting.... What is your primary use-case for this change? What are the shortcommings of the existing directives (ng-class-odd / ng-class-even)?

In any case this PR will need more work, I've included a checklist for you (see above).

@richardjohn
Copy link
Contributor

I've had the same test fail on a very simple change (#3297).

@npup
Copy link
Contributor Author

npup commented Jul 22, 2013

@pkozlowski-opensource Hi, thanks for your answer!

CLA was signed a few days ago, RL name: Petter Envall

I think that not everything one could have valid reasons to alternate in an even/odd pattern is related to the class attribute.
ngRepeat's iterator helpers $first, $last and $middle, which obviously weren't moved out to directives ngClass(First|Last|Middle) (and thus being explicitly tied to use with CSS classes) are useful for such things. Actually, I was a bit surprised by the treatment of even/odd here.

The existing ngClass(Even|Odd) directives seem to me like a sugar basically for zebra striping. That, of course, is a terrific use case, but it is a bit like hiding the base functionality and only exposing the sugar. Ok, I admit that $even and $odd in reality would be sugar too ;) But avoiding expressions like
($index%2!=0) is a significant readability boost to me.

So my use cases for $evenand $odd pretty are much like any use case for $first, $middle and $last, I guess.

Some detail that popped up in my mind:

  1. Sometimes one could benefit from alternating some inline style instead of doing it via classes.
    I am thinking of the classic scenario of having a generic hide-/showElem function that switches an inline style between "none" and "". If one wants to be able to successfully manipulate an element that should be initially hidden, it must be hidden via an inline style since the "reset" ("") won't make it appear.

  2. One might want to alternate values for various attributes that aren't the class attribute (or even CSS related).
    One example would be a flag in a data-* attribute. I for one have (in HTML5) stopped using entries in class for such purposes, though in HTML4 the "loophole" formulation "For general purpose processing by user agents" had me somewhat covered earlier.

Not sure if there are idiomatic angularisms to avoid every situation that resembles what I touched on above. But having $first, $middle and $last, and missing $even and $odd feels lacking to me. ngClassEven and ngClassOdd is the sugar.

Regarding the PR checklist - as I said: not sure what was going on in Chrome (the newly checked out tree behaved like that in Chrome when building even without any modifications). And the commit message I thought would be ok.
Suggestions? I'd like to help out if I can.

Cheers
/@npup

@petebacondarwin
Copy link
Contributor

The travis error has been fixed in master. Try ammending the commit and forcing a new push. It will probably pass.

@petebacondarwin
Copy link
Contributor

This seems like a reasonable idea to me.

@npup
Copy link
Contributor Author

npup commented Jul 24, 2013

Cool, build was fixed. Let's go ;)

@ksheedlo
Copy link
Contributor

landed in 52b8211. Cheers! 🍺

@ksheedlo ksheedlo closed this Jul 24, 2013
@npup npup deleted the ngrepeat-add-odd-even branch August 17, 2013 20:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants