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

Feature request: make one-way expression bindings for components #13854

Closed
thorn0 opened this issue Jan 27, 2016 · 18 comments
Closed

Feature request: make one-way expression bindings for components #13854

thorn0 opened this issue Jan 27, 2016 · 18 comments

Comments

@thorn0
Copy link
Contributor

thorn0 commented Jan 27, 2016

See http://teropa.info/blog/2015/10/18/refactoring-angular-apps-to-components.html#replace-two-way-binding-with-one-way-binding

There seems to be little value in the ability of components to change values in the parent scope via two-way =-bindings. @-bindings are one-way, but they can be used only for string values. It'd be logical to introduce a new kind of one-way bindings for expressions of any type or to change the behavior of =-bindings for components (defined with the component method).

@17cupsofcoffee
Copy link

👍 This would make it a lot easier to migrate components across to Angular 2, as well - the less we're relying on two-way binding, the less we'll have to refactor later on. At the minute I'm just trying to enforce 'don't mutate the inputs' as a code convention, but it'd be great to not have to rely on that.

@Narretz
Copy link
Contributor

Narretz commented Jan 27, 2016

There's actually a PR for that: #12835
I personally like the idea.
👍

@robstove
Copy link

Nice start. Out of curiosity, what is the reasoning for using '#' for specifying the binding mode?

@thorn0
Copy link
Contributor Author

thorn0 commented Jan 30, 2016

I believe it's still not late for the 1.5 release to include this. It'd be really consistent with the rest of the changes related to the component approach. Please consider extracting it from the ice box before the release.

Let me quote the description of the Ice Box milestone:

Milestone for valid issues and bugs that we have no aspirations on fixing any time soon because they are not affecting primary use-cases and are not aligned with our goals.

I can't agree that it's not aligned with the current goal of migration facilitation.

@robstove
Copy link

@thorn0 +1

@Narretz
Copy link
Contributor

Narretz commented Feb 1, 2016

We'll talk about this in the meeting today.

Regarding the symbol for it, there's nothing set, but > is favorable. - is also okay, but might be confused with the dash delimiter. # has no real connection to bindings.

@thorn0
Copy link
Contributor Author

thorn0 commented Feb 1, 2016

@Narretz That's great. As for the argument of 'further complicating the DDO API', the API docs can be made to appear less complicated by adding a standard highlighted paragraph 'Best Practice', which would recommend using these new bindings for inputs and & (or events?) for outputs.

@Narretz
Copy link
Contributor

Narretz commented Feb 1, 2016

@robstove

Yes, last minute addition for 1.5. Although, compared to the PR here #12835 We are not going to copy the parentValue, instead we just set it on the isolate scope. This means, if you have bind an object and then change a property on that object, it'll be reflected in the origin scope. This is because completely copying the object to the isolate scope is very difficult. If you need to make a copy, you can always do that yourself.

@robstove
Copy link

robstove commented Feb 1, 2016

Perfect! Will look forward to this enhancement. Thanks guys.

@gkalpak
Copy link
Member

gkalpak commented Feb 1, 2016

Where do we bikeshed about the symbol ? I think < is better 😃
(No, seriously, I do... 😛 )

@robstove
Copy link

robstove commented Feb 1, 2016

Dash '-' seemed appropriate to me. I see '=' as two directions and '-' as one direction (not the boy band). 😄

@Narretz
Copy link
Contributor

Narretz commented Feb 1, 2016

@gkalpak Why <? To me >, because parent > child

@thorn0
Copy link
Contributor Author

thorn0 commented Feb 1, 2016

bindings: { propertyName: "<attrName" }

Which means: the value is copied from the attribute attrName to the property propertyName.

Indeed, < looks better.

@robstove
Copy link

robstove commented Feb 1, 2016

How does this look:

binding: { propertyName: "*attrName" }

@thorn0
Copy link
Contributor Author

thorn0 commented Feb 1, 2016

@robstove * is already in use. It can be combined with = for watching collections. The new one-way binding should support collections too so we might end up with propertyName: "**attrName" if we choose *. 🚲

@robstove
Copy link

robstove commented Feb 1, 2016

@thorn0 Ah good point. Forgot about collections.

petebacondarwin pushed a commit that referenced this issue Feb 3, 2016
This change allows the developer to bind an isolate scope / controller property
to an expression, using a `<` binding, in such a way that if the value of the
expression changes, the scope/controller property is updated but not the
converse.

The binding is implemented as a single simple watch, which can also provide
performance benefits over two way bindings.

Closes #13928
Closes #13854
Closes #12835
Closes #13900
@aoancea
Copy link

aoancea commented Feb 5, 2016

I personally like the idea.

@Narretz Well thank you!

@aoancea
Copy link

aoancea commented Feb 5, 2016

Nice start. Out of curiosity, what is the reasoning for using '#' for specifying the binding mode?

@robstove This is pretty much what came into my mind when I was prototyping the idea
For me though, from the ideas in this post, it would make more sense to use '>' as you are sending something to the child as @Narretz described

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants