Skip to content

Commit

Permalink
Get dependency values from properties instead of cache, see #146
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Oct 21, 2017
1 parent 6d093d0 commit 26dd4b5
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions js/DerivedProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ define( function( require ) {

this.dependencies = dependencies; // @private

// @private Keep track of each dependency and only update the changed value, for speed
this.dependencyValues = dependencies.map( function( property ) {return property.get();} );

var initialValue = derivation.apply( null, this.dependencyValues );
var initialValue = derivation.apply( null, dependencies.map( function( property ) {return property.get();} ) );

// We must pass supertype tandem to parent class so addInstance is called only once in the subclassiest constructor.
Property.call( this, initialValue, _.extend( {}, options, {
Expand All @@ -63,10 +60,9 @@ define( function( require ) {

for ( var i = 0; i < dependencies.length; i++ ) {
var dependency = dependencies[ i ];
(function( dependency, i ) {
var listener = function( newValue ) {
self.dependencyValues[ i ] = newValue;
Property.prototype.set.call( self, derivation.apply( null, self.dependencyValues ) );
(function( dependency ) {
var listener = function() {
Property.prototype.set.call( self, derivation.apply( null, dependencies.map( function( property ) {return property.get();} ) ) );
};
self.dependencyListeners.push( listener );
dependency.lazyLink( listener );
Expand All @@ -91,7 +87,6 @@ define( function( require ) {
}
this.dependencies = null;
this.dependencyListeners = null;
this.dependencyValues = null;

this.tandem.removeInstance( this );

Expand Down

0 comments on commit 26dd4b5

Please sign in to comment.