-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat($compile): support expansion of special ngBindon
attributes
#15464
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
1 similar comment
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
CLAs look good, thanks! |
1 similar comment
CLAs look good, thanks! |
This PR is intended mainly to serve as a proof of concept and start a discussion around whether or not we like this implementation and also, the actual name of the attribute prefix we'd like to use. Will work on documentation and additional tests shortly assuming we like it. |
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 like ng-bindon-
better, because it matches ng2's bindon-
pretty closely (but maybe it is too close).
src/ng/compile.js
Outdated
@@ -1803,7 +1803,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { | |||
: function denormalizeTemplate(template) { | |||
return template.replace(/\{\{/g, startSymbol).replace(/}}/g, endSymbol); | |||
}, | |||
NG_ATTR_BINDING = /^ngAttr[A-Z]/; | |||
NG_ATTR_BINDING = /^ng(Attr|Autobind)[A-Z]/; |
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 name of the variable needs to change.
test/ng/compileSpec.js
Outdated
@@ -11441,6 +11441,40 @@ describe('$compile', function() { | |||
}); | |||
}); | |||
|
|||
describe('ngAutobind attributes', function() { | |||
it('should expand `ng-autobind-foo` to a one-way binding and an output expression', function() { |
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 one-way
part is not accurate.
test/ng/compileSpec.js
Outdated
fooChange: '&' | ||
}, | ||
controller: function($attrs) { | ||
testController = this; |
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.
We usually use element.controller('test')
for accessing the controller. It is a good idea to keep the consistency.
50c01bf
to
15617cf
Compare
Ah, I forgot that ng2 even had Anyway, everything should be fixed up. |
a8767ec
to
159221a
Compare
In order to reduce some of the verbosity associated with conforming to the ideas behind unidirectional data-flow, we can introduce a special attribute syntax that will be automatically expanded in order to simulate two-way data binding. For example, `<my-component ng-bindon-foo="bar">` will be expanded into `<my-component foo="bar" foo-change="bar=$event">` Fixes angular#15455
ngAutobind
attributesngBindon
attributes
Any update here? Was hopeful that this would make it to 1.6, but would love it if it could be considered for the next release (and maybe a patch to 1.5? ❤️ ) |
This can still land on 1.6. Since it is not a breaking change, it didn't have to make it into 1.6.0. |
Any update here? |
Let's discuss this next week. (This weeks meeting was too busy 😁) |
For anyone that's been waiting for this, I've written a polyfill that can be used to detect and add support for this feature. It does depend on implementation details and some assumptions since there's no other way to do it, and it does have the cost of extra iterations of the attributes object. https://gist.github.com/dcherman/57621dd904cf598f12b81ae6e0f4b6b2 |
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
feat
What is the current behavior? (You can also link to an open issue here)
Supporting unidirectional data-flow is rather verbose
What is the new behavior (if this is a feature change)?
Supporting unidirectional data-flow is less verbose
Does this PR introduce a breaking change?
Nope
Please check if the PR fulfills these requirements
In order to reduce some of the verbosity associated with conforming to the
ideas behind unidirectional data-flow, we can introduce a special
attribute syntax that will be automatically expanded in order to simulate
two-way data binding.
For example,
<my-component ng-bindon-foo="bar">
will be expanded into<my-component foo="bar" foo-changed="bar = $event">
Fixes #15455