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

"setProperties" does not pass "attrs" as expected #11537

Closed
BenjaminHorn opened this issue Jun 23, 2015 · 2 comments
Closed

"setProperties" does not pass "attrs" as expected #11537

BenjaminHorn opened this issue Jun 23, 2015 · 2 comments

Comments

@BenjaminHorn
Copy link

I have a wrapping component, which yields some other component in itself. (Think about form control group or a table cell component).

To make it as flexible as possible I pass attrs to the hash property. And all component will set hash on itself.

Ember.Component.reopen({
  init: function(){
    this._super();
    this.setProperties(this.get('hash'));
  }
});

http://jsbin.com/suvenijuxu/1/edit?html,js,output

It works fine with Strings but not with objects. In my-wrapper component attrs.model.name has the correct value (see the template), but after attrs is passed to the property hash and set by setProperties it is transformed to MutStream. (see console.log)

Why does this transformation happens? Is this the expected behavior? Is my approach considered as an anti-pattern? Is there a workaround? What does MutStream or MUTABLE_REFERENCE mean?

@rwjblue
Copy link
Member

rwjblue commented Jul 1, 2015

By default Ember has used two way data binding for a very long time. We are transitioning away from that, but at the moment we are still very much in two-way binding land.

The object you are seeing is a Mutable Object, and is how we represent two way bound attributes. They have a .value property and an .update method (using update is how to set the upstream source). At this point, we generally are not suggesting folks use this.attrs for much because of this confusion. The confusion will be cleared up when we migrate to angle bracket invocation and can change the default binding from two-way to one-way. See emberjs/rfcs#60 for details.


You can get your scenario working by forcing the model param to be readonly by using (readonly) subexpression to force one way binding: http://jsbin.com/lofoje/edit?html,js

@rwjblue rwjblue closed this as completed Jul 1, 2015
@BenjaminHorn
Copy link
Author

Thanks @rwjblue to taking the time explaining it. Unfortunately I don't see any different in your jsbin. {{model.name}} is still empty. (To be exact: not rendered and it is now a KeyStream ).

I thought about a different solution to my problem: A Helper will know everything about the parameters passed to it, but I don't know how to call a component from a helper. This used to worked but not anymore. (Since env is not passed)

    export default function(params, hash, options, env) {
      ...
      return env.helpers.component.helperFunction.call(this, ["my-component"], hash, options, env);
    }

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

2 participants