Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yield & component helper => two way data binding not working ? #13061

Closed
plcarmel opened this issue Mar 7, 2016 · 13 comments
Closed

yield & component helper => two way data binding not working ? #13061

plcarmel opened this issue Mar 7, 2016 · 13 comments
Assignees

Comments

@plcarmel
Copy link

plcarmel commented Mar 7, 2016

DEBUG: -------------------------------
DEBUG: Ember : 2.4.1
DEBUG: Ember Data : 2.4.0
DEBUG: jQuery : 2.2.1
DEBUG: -------------------------------

I don't know if this is a bug but it seems to contradict the documentation at
[http://emberjs.com/api/classes/Ember.Templates.helpers.html#toc_nested-usage]

This is the example that is given:
{{yield (hash nameInput=(component "my-input-component" value=model.name placeholder="First Name"))}}

I tried it but without being able to achieve two way data binding.

To replicate the problem

templates/components/test-binding.hbs:
{{yield (component 'my-input' value=value)}}

templates/components/my-input.hbs:
{{input value=value}}

templates/application.hbs:

{{#test-binding value=value as |component|}}
  {{component component}}
{{/test-binding}}

value: {{value}}

A work-around

It works it the value is encapsulated inside a hash. Please note that the way I do it differs from the example in the documentation, which is not working.

templates/components/test-binding-2.hbs:
{{yield (component 'my-input-2' model=model)}}

templates/components/my-input-2.hbs:
{{input value=model.value}}

templates/application.hbs:

{{#test-binding-2 model=model as |component|}}
  {{component component}}
{{/test-binding-2}}

model.value: {{model.value}}

controllers/application.js:

import Ember from 'ember';
export default Ember.Controller.extend({
  model: { value: 'Hello world' }
});
@GCorbel
Copy link

GCorbel commented Mar 15, 2016

Can you try simply :

{{#test-binding value=value as |component|}}
  {{component}}
{{/test-binding}}

value: {{value}}

I find {{component component}} a bit weird.

@plcarmel
Copy link
Author

From the same documentation:

"Contextual components are created using the nested form of the component helper, and may be passed attrs and positional params. Contextual components must be invoked with a . in their path, unless they are being passed to the invoking {{component helper."

@pixelhandler
Copy link
Contributor

@plcarmel can you create an ember-twiddle example that demonstrate the issue? Also I'm curious if 2-way binding is supposed to function, the docs mention binding, but not 2-way.

@plcarmel
Copy link
Author

In the example given, a (custom) input component is used. So, it is implicit that two way binding should work in that example. There is no action registered on the component so one-way data binding would render the component useless.

Anyway, things need to be clarified. I will create the Ember Twiddle soon (one week max), stay tuned.

@courajs
Copy link
Contributor

courajs commented Mar 21, 2016

I may have found the same bug. I don't think yield is a factor here. Here's my reduced test case: Twiddle. Let me know if you think this is the same issue.

@courajs
Copy link
Contributor

courajs commented Mar 21, 2016

@Serabe You have a lot of knowledge on (component right?

@Serabe
Copy link
Member

Serabe commented Mar 22, 2016

Looking into it

@plcarmel
Copy link
Author

Yes, I think this is the same issue.

@Serabe
Copy link
Member

Serabe commented Mar 24, 2016

TL;DR Found the issue. I think I fixed it but a few more tests are needed. I hope to have it done pretty soon.

For normal component invocation, Ember adds a mut automatically. Sadly, this does not happen for contextual components. I am adding a compiler plugin for doing so, but needs more testing before being published.

If everything goes ok, I hope to have it finished before next week. But again, only if everything goes ok.

@courajs
Copy link
Contributor

courajs commented Mar 24, 2016

@Serabe Thanks for the update, and for working on it :)

@krisselden
Copy link
Contributor

If you manually use value=(mut model.name) does it work?

@Serabe
Copy link
Member

Serabe commented Mar 24, 2016 via email

Serabe added a commit to Serabe/ember.js that referenced this issue Mar 26, 2016
As explained in issue emberjs#13061, given a component `change-button` with template:

```hbs
<button {{action (action (mut val) 10)}}>Change to 10</button>
```

If it is invoked as in the following template:

```hbs
{{change-button val=value}}
<span class="value">
  {{value}}
</span>
```

Clicking on the button will cause `.value` to contain `10`.

On the other hand, invoking it via a closure component:

```hbs
{{component (component "change-button" val=value)}}
<span class="value">
  {{value}}
</span>
```

Clicking on the button will not change the text in `.value`.

This PR adds a transform that adds `mut` to params and hash values.
rwjblue pushed a commit that referenced this issue Mar 26, 2016
As explained in issue #13061, given a component `change-button` with template:

```hbs
<button {{action (action (mut val) 10)}}>Change to 10</button>
```

If it is invoked as in the following template:

```hbs
{{change-button val=value}}
<span class="value">
  {{value}}
</span>
```

Clicking on the button will cause `.value` to contain `10`.

On the other hand, invoking it via a closure component:

```hbs
{{component (component "change-button" val=value)}}
<span class="value">
  {{value}}
</span>
```

Clicking on the button will not change the text in `.value`.

This PR adds a transform that adds `mut` to params and hash values.

(cherry picked from commit 31bb7a2)
rwjblue pushed a commit that referenced this issue Apr 3, 2016
As explained in issue #13061, given a component `change-button` with template:

```hbs
<button {{action (action (mut val) 10)}}>Change to 10</button>
```

If it is invoked as in the following template:

```hbs
{{change-button val=value}}
<span class="value">
  {{value}}
</span>
```

Clicking on the button will cause `.value` to contain `10`.

On the other hand, invoking it via a closure component:

```hbs
{{component (component "change-button" val=value)}}
<span class="value">
  {{value}}
</span>
```

Clicking on the button will not change the text in `.value`.

This PR adds a transform that adds `mut` to params and hash values.

(cherry picked from commit 31bb7a2)
@Serabe
Copy link
Member

Serabe commented Apr 17, 2016

Fixed in #13177

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

No branches or pull requests

6 participants