Extending computed properties, how to get dependent key?


#1

In the following example I create two object, the second extends the first. Both define a computed property test1Prop. Everything works pretty good, except the dependent keys of test1Prop don’t get ‘extended’, they get replaced.

This following example shows the cp doesn’t get recomputed when C1’s dependent key gets updated… So I know I could just add the dependent key to C2’s test1Prop, but what do I do in the case when I don’t know what C1’s dependent keys are beforehand? I ran into this problem while developing a set of mixins that all extend the same computed property, and I’m not going to be able to know before hand what order and which one of the mixins are added in.

C1 = Ember.Object.extend({
  test1: true,
  test1Prop: function(){
    console.log( 'c1' );
    return this.get( 'test1' );
  }.property( 'test1' )
});

C2 = C1.extend({
  test2: true,
  test1Prop: function(){
    var t1 = this._super(),
        t2 = this.get( 'test2' );
    
    console.log( 'c2' );
    return { test1: t1, test2: t2 };
  }.property( 'test2' )
});

c=C2.create();

console.log( '1st', c.get('test1Prop') );

c.set( 'test1', false );

console.log( '2nd', c.get('test1Prop') );