-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat($compile): allow $watchCollection to be used in bi-directional bindings #9725
feat($compile): allow $watchCollection to be used in bi-directional bindings #9725
Conversation
d348a38
to
3c6690f
Compare
@@ -691,7 +693,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { | |||
var EVENT_HANDLER_ATTR_REGEXP = /^(on[a-z]+|formaction)$/; | |||
|
|||
function parseIsolateBindings(scope, directiveName) { | |||
var LOCAL_REGEXP = /^\s*([@=&])(\??)\s*(\w*)\s*$/; | |||
var LOCAL_REGEXP = /^\s*([@=&])(\??)(\*?)\s*(\w*)\s*$/; |
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 RegExp will also match @*
and &*
which is unwanted.
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.
... and when the bind is optional, it would be =?*
that is very odd as it should be =*?
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 like the =*?
syntax better. Will push fixes later 😄
I'm sorry, but I wasn't able to verify your Contributor License Agreement (CLA) signature. CLA signature is required for any code contributions to AngularJS. Please sign our CLA and ensure that the CLA signature email address and the email address in this PR's commits match. If you signed the CLA as a corporation, please let us know the company's name. Thanks a bunch! PS: If you signed the CLA in the past then most likely the email addresses don't match. Please sign the CLA again or update the email address in the commit of this PR. |
Shouldn't also the origin be updated if the local copy changes ? |
3c6690f
to
6ce0643
Compare
It's working, |
52c6435
to
cc63f8a
Compare
I modified the regexp and wrote a test to verify that the origin scope is updated when the isolate scope changes. |
@@ -1894,7 +1897,9 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { | |||
return lastValue = parentValue; | |||
}; | |||
parentValueWatch.$stateful = true; | |||
var unwatch = scope.$watch($parse(attrs[attrName], parentValueWatch), null, parentGet.literal); | |||
var unwatch = !definition.collection | |||
? scope.$watch($parse(attrs[attrName], parentValueWatch), null, parentGet.literal) |
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 we do this with an if (definition.collection) { ... } else { ... }
instead of the ternary operator? It's just a bit easier on the eyes
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.
Sure 😄
LGTM with nit |
cc63f8a
to
5cbc9b2
Compare
var unwatch = scope.$watch($parse(attrs[attrName], parentValueWatch), null, parentGet.literal); | ||
var unwatch; | ||
if (definition.collection) { | ||
unwatch = scope.$watchCollection(attrs[attrName], parentValueWatch); |
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.
indentation is wrong --- 2 spaces please
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.
Oops, you're right. Sublime betrayed me, it usually detects how to indent based on the rest of the file 😄 Sorry.
b592851
to
df593c2
Compare
Are the tests failing due to changes in this PR? I'm guessing something external went wrong. |
@gabrielmaldi something has been wrong with the unit tests all day, it could be that FF26 is just dead on SL right now. I'll try an experiment to see if it can work, but I am not an SL expert |
hmm I don't think it's FF26 --- it's just that SL is dropping connections really badly... pretty sure that's what we're seeing. |
Thought so by examining the logs 😄 |
It seems to be just talking to FF wrong... but also FF27 when I tried it. I dunno =\ |
df593c2
to
f759570
Compare
@caitp good news, I amended to run the build again and SL seems to be back to normal 😄 And I did sign the CLA (at first I committed with a different email but it should validate now). |
f759570
to
a472ca7
Compare
\o/ |
so I feel like should probably hear an lgtm from Igor, but it basically looks good to me --- however in your tests there is still some "off" indentation, I'll leave a comment |
})); | ||
|
||
it('should update origin scope when isolate scope changes', inject(function() { | ||
$rootScope.collection = [{ |
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 entire block is 1 space further to the right than it should be (lines 3592 to 3609)
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.
Done. And sorry for being so careless about indentation; I'm used to having code formatting automated on save in my own projects.
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.
ah don't worry too hard about it, we all mess up formatting, even on projects that use clang-format in a git hook!
…indings an asterisk can be specified in the binding definition to use $watchCollection instead of $watch. e.g. scope: { prop: '=*' }
a472ca7
to
06707a3
Compare
so, I'm just going to land this because it's doing what igor suggested and it basically looks okay to me --- I worry we might end up reverting it later though if someone decides it shouldn't have gone in. Here goes, merg'in~ |
if this causes a regression, I'm gonna be sad :( |
CLA verified by George Lu and Max Sills |
Great! Lets hope for no regressions and that Igor is fine with extending the syntax for this scenario. I know I'm gonna be waiting for the next release since I have many directives which take collections 😄 |
@caitp: Was this reverted or something ? Why don't I see the changes in the current snapshot ? :( |
@gkalpak it wasn't reverted, but you're right, angularjs.org doesn't seem to be updated... maybe the jenkins machine died or got turned off or something |
So, builds have been failing on the jenkins master branch, it probably gave up before trying to run the build update... that's been since the 20th... Unfortunately I can't recall the password for my account, and I'm pretty sure I don't have credentials to start it up again anyways... So, can see if it's fixed by pushing a build to master, but I think that's all we can do :( the failures on jenkins look like e2e flakes to me, but there isn't much info there so I'm not sure. |
Allow an asterisk to be specified in the binding definition to use
$watchCollection
instead of$watch
.This is a follow-up to #3491 but using
$watchCollection
as @IgorMinar suggested.