From afac35fabf233ee11880742128b43946a6880ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 24 Feb 2013 14:56:51 -0800 Subject: [PATCH] Improve handling of bounds caching. Cloning was done in the wrong place. --- src/item/Item.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/item/Item.js b/src/item/Item.js index c2da084b..9cc20db8 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -634,8 +634,12 @@ var Item = this.Item = Base.extend(Callback, { // If we're returning 'bounds', create a LinkedRectangle that uses // the setBounds() setter to update the Item whenever the bounds are // changed: - return name == 'bounds' ? LinkedRectangle.create(this, 'setBounds', - bounds.x, bounds.y, bounds.width, bounds.height) : bounds; + return name == 'getBounds' + ? LinkedRectangle.create(this, 'setBounds', + bounds.x, bounds.y, bounds.width, bounds.height) + // Return a clone of the cahce, so modifications won't + // affect it. + : bounds.clone(); }; }, /** @lends Item# */{ @@ -691,9 +695,7 @@ var Item = this.Item = Base.extend(Callback, { if (cache) { if (!this._bounds) this._bounds = {}; - // Put a separate instance into the cache, so modifications of the - // returned one won't affect it. - this._bounds[cache] = bounds.clone(); + this._bounds[cache] = bounds; } return bounds; },