From e0a8385eb018e7974859fc959d13cad4d69f971c Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Tue, 22 Aug 2017 09:37:28 +0200 Subject: [PATCH] Only process properties that have actually changed --- src/create-object.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/create-object.js b/src/create-object.js index 18923c1..ae390e3 100644 --- a/src/create-object.js +++ b/src/create-object.js @@ -36,14 +36,23 @@ module.exports = function createObject(options) { transformedProperties = properties; } - Object.assign(this, transformedProperties); - - if (Object.keys(transformedProperties).some(property => this.sizeBustingProperties.includes(property))) { - /* If the size changes, the cache should also be implicitly busted. */ - this.bustSize(); - this.bustCache(); - } else if (Object.keys(transformedProperties).some(property => this.cacheBustingProperties.includes(property))) { - this.bustCache(); + Object.keys(transformedProperties).forEach((property) => { + /* Don't apply unchanged properties, to prevent unnecessary cache or size busting. */ + if (this[property] === transformedProperties[property]) { + delete transformedProperties[property]; + } + }); + + if (Object.keys(transformedProperties).length > 0) { + Object.assign(this, transformedProperties); + + if (Object.keys(transformedProperties).some(property => this.sizeBustingProperties.includes(property))) { + /* If the size changes, the cache should also be implicitly busted. */ + this.bustSize(); + this.bustCache(); + } else if (Object.keys(transformedProperties).some(property => this.cacheBustingProperties.includes(property))) { + this.bustCache(); + } } }, render: function renderObject(context, options = {}) {