-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat(ngPluralize): add support for bind-once in count
#10022
Conversation
d601008
to
a3218a3
Compare
a3218a3
to
a469b46
Compare
tmpMatch = IS_WHEN.exec(attributeName); | ||
if (tmpMatch) { | ||
var whenKey = lowercase((tmpMatch[1] ? '-' : '') + tmpMatch[2]); | ||
whens[whenKey] = element.attr(attr.$attr[attributeName]); | ||
} | ||
}); | ||
forEach(whens, function(expression, key) { |
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.
if whens
was created with createMap()
then forEach()
will break :(
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.
maybe default to []
instead?
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.
or {}
I guess
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.
alternatively, you could remove the forEach()
and just do it Object.keys()-for-loop
style.
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.
True !
But shouldn't we rather be fixing forEach()
?
(I.e. replacing obj.hasOwnProperty(...)
with hasOwnProperty.call(obj, ...)
at https://github.com/angular/angular.js/blob/master/src/Angular.js#L265)
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.
i don't care a whole lot about that --- @petebacondarwin would you be pro-refactoring forEach?
2908731
to
ff6f155
Compare
I was about to say that this solution looks way too confusing - but it looks like you fixed it up as I started typing. Here's what I tried (yours basically does the same now): jbedard@6ffe579 |
@lgalfaso: I addressed your comments (and squashed everything in a single commit). |
@jbedard: Actually, there is a problem with both our imlementation: |
Interesting... that makes it way more complicated :| |
Could watch |
Seems to work: jbedard@1583415, haven't looked into the performance differences at all though (I think it will actually be faster by not doing the interpolation in the watcher though). |
@jbedard: That was my first thought too. One problem is that the count will also be updated, since in |
But that |
I pushed a 2nd commit which seems to fix the issue (in a different way than @jbedard). Will play a bit with jbedard@1583415 |
1e1c080
to
abc03a3
Compare
You are right about that. Overall, I think I like the 2nd watcher approach better - perf implications aside (if any). @lgalfaso: WDYT ? |
Seems like we can't do that. (I guess I am not familiar enough with |
I pushed another commit using the 2 watchers approach (similar to @jbedard's jbedard@1583415) and I am pretty happy with it 😃. I added a check, so that we only unregister and re-register the 2nd watcher only if the key did actually change (e.g. the /ping @lgalfaso If it lgty, let me know so I squash the commits into 1. |
@gkalpak I do not feel comfortable with how this is going. If the idea is to fix #10004, then the PR should be about this. Just trying to bundle everything that can be done to I would like to have a single commit that the only thing it does is fix the valid use case of #10004 (some small cleanup would be ok, but not behavior changes) |
@lgalfaso: Not sure what behaviour changes you are talking about. The changes in this PR are about adding support for Feel free to suggest a simpler approach; I might have missed something. Also, not sure what is the breaking change you mention (other than that one-time expressions will work with `count`)... |
$interpolate(expression.replace(BRACE, startSymbol + numberExp + '-' + | ||
offset + endSymbol)); | ||
}); | ||
for (var key in whens) { |
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.
I find it cleaner to use forEach
even when this implies that we end up using a {}
or Object.keys()
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.
I really wonder how forEach
is cleaner, but I will change it 😃
if (count !== lastCount) { | ||
watchRemover(); | ||
watchRemover = scope.$watch(whensExpFns[count], | ||
function ngPluralizeWhensWatchAction(newVal) { |
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.
please move this function out, as it uses nothing from the closure
sorry, I misread part of the patch once the changes from the comment are in place, the PR LGTM |
d388a4a
to
67c88b7
Compare
@lgalfaso: Thx for the help on watch interceptors. This works great 😃 |
watchRemover = scope.$watch(whensExpFns[newVal], updateElementText); | ||
} | ||
|
||
function ngPluralizeWatchInterceptor(newVal) { |
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.
if at all possible, can we try to do this without interceptors? Otherwise it makes it slightly harder to get rid of them :(
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.
your call @lgalfaso but it would be better
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.
The previous implementation was without interceptors (but used an extra local variable).
So, it is doable (remains to see if it is desirable).
@caitp: Why remove interceptors ? They seem pretty cool :) What's the catch ?
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.
they add an extra hook in an aleady multi-hook process which complicates things and causes headaches which are very hard to debug, I want them gone .v.
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.
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.
I also want them gone... but they do provide a useful feature of filtering the output of an expression like what @lgalfaso mentioned. But I don't like how they are implemented right now, but also haven't thought of anything better yet.
67c88b7
to
8a24974
Compare
Back to not using $parse interceptors. |
LGTM |
8a24974
to
a6029ee
Compare
a6029ee
to
e4dee6a
Compare
(FYI: I just removed an unused |
landed 2b41a58 |
The 1st commit contains the change and test for adding support for
bindOnce
incount
.The 2nd commit contains some minor refactoring (mainly to avoid repetitive actions).
Closes #10004
(Makes #5452 obsolete)