dagda1
dagda1

Reputation: 28860

Ember.Binding.transform migration to latest code

Ember.Binding.transform has been removed or replaced in the latest ember. I have a number of bindings that take this form:

valueBinding: Ember.Binding.transform({
  to: function(value, binding) {
    //return something
  },
  from: function(value, binding) {
    //return something
  }
}).from('parentView.content.finishBy'),

Can anyone advise me how I should update my code to the new regime?

Upvotes: 1

Views: 719

Answers (2)

pangratz
pangratz

Reputation: 16163

You can add your computed property definition to Ember.computed, see http://jsbin.com/awufuv/edit#source:

Ember.computed.finishBy = function() {
  return Ember.computed('parentView.content.finishBy', function(key) {
    var finishBy = Ember.getPath(this, 'parentView.content.finishBy');
    return finishBy === 'now';
  }).cacheable();
};

You can then use it like this:

App.obj = Ember.Object.create({
  parentView: {
    content: {
      finishBy: 'now'
    }
  },
  finishProp: Ember.computed.finishBy()
});

See more examples in https://github.com/emberjs/ember.js/blob/master/packages/ember-metal/lib/computed.js#L417-434


Just to be clear: you're not forced to add your custom computed property to Ember.computed. You can basically declare the function anywhere in your code. Now that I think about it, you might want to add your helper to your applications namespace instead of adding / poluting it to Ember. But that's just an issue of personal preference.

Upvotes: 1

Bradley Priest
Bradley Priest

Reputation: 7458

There's a pretty good discussion on the original commit on how to update your code.

However, in your case, I think you could just use a computed property:

value: function(key, value){
  if(arguments.length===1){
    //return something
  } else{
    //set and return something
  }
}).property('parentView.content.finishBy')

Upvotes: 0

Related Questions