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

feat($compile): support expansion of special ngBindon attributes #15464

Closed
wants to merge 1 commit into from

Conversation

dcherman
Copy link
Contributor

@dcherman dcherman commented Dec 2, 2016

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

@googlebot
Copy link

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. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

1 similar comment
@googlebot
Copy link

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. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@googlebot
Copy link

CLAs look good, thanks!

1 similar comment
@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no labels Dec 2, 2016
@dcherman
Copy link
Contributor Author

dcherman commented Dec 2, 2016

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.

Copy link
Member

@gkalpak gkalpak left a 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).

@@ -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]/;
Copy link
Member

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.

@@ -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() {
Copy link
Member

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.

fooChange: '&'
},
controller: function($attrs) {
testController = this;
Copy link
Member

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.

@dcherman dcherman force-pushed the ngBanana branch 2 times, most recently from 50c01bf to 15617cf Compare December 2, 2016 22:28
@dcherman
Copy link
Contributor Author

dcherman commented Dec 2, 2016

Ah, I forgot that ng2 even had bindon since I was used to the shorthand syntax. That explains the suggestion.

Anyway, everything should be fixed up.

@dcherman dcherman force-pushed the ngBanana branch 2 times, most recently from a8767ec to 159221a Compare December 2, 2016 22:30
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
@dcherman dcherman changed the title WIP: feat($compile): support expansion of special ngAutobind attributes feat($compile): support expansion of special ngBindon attributes Dec 3, 2016
@dcherman
Copy link
Contributor Author

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? ❤️ )

@gkalpak
Copy link
Member

gkalpak commented Dec 13, 2016

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.
Let's discuss this next week.

@dcherman
Copy link
Contributor Author

Any update here?

@gkalpak
Copy link
Member

gkalpak commented Jan 11, 2017

Let's discuss this next week. (This weeks meeting was too busy 😁)

@dcherman
Copy link
Contributor Author

dcherman commented Mar 4, 2017

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

@dcherman dcherman closed this Jun 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Support unidirectional dataflow syntactic sugar
3 participants