mardi 16 août 2016

Creating alias to a dynamic property now that Ember.Binding is deprecated

How can I add alias or observer to a property that's name I only know when the component is initialized?

I need this for a generic use component where the property name depends on what data was passed to the component. In previous Ember versions I could just create the binding on init:

binding = Ember.Binding.from("model.settings." + this.get('type')).to("setting");
binding.connect(this);

Then use the "setting" wherever it is needed and everything gets correctly updated when or if the property changes. The "type" property is passed to the component from the outside and is different for every instance of the component so I can't hard code the property name in the component itself.

Now Ember.Binding was deprecated in Ember 2.7 and will be removed in Ember 3.0.

I can't figure out how to achieve this without Ember.Binding. And no, there isn't a good way to pass the value from elsewhere or manage this without a binding as far as I can tell. The actual component is a bit more complicated than what I described above but the problem remains same.




Aucun commentaire:

Enregistrer un commentaire