From 069a81db748bb51f8e26875d2d2f5fd236f0b992 Mon Sep 17 00:00:00 2001 From: DavidHequet Date: Fri, 9 Oct 2015 15:55:02 +0200 Subject: [PATCH 1/2] Allow ol.Object property update without notification Add an optional notify argument to object set and setProperties methods. If the argument is not provided, set and setProperties trigger an event. If you update many objects or do so frequently and do not need notification, performance is improved by setting silent to true. --- src/ol/object.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/ol/object.js b/src/ol/object.js index 7092204613..0bd5c06864 100644 --- a/src/ol/object.js +++ b/src/ol/object.js @@ -197,12 +197,17 @@ ol.Object.prototype.notify = function(key, oldValue) { * Sets a value. * @param {string} key Key name. * @param {*} value Value. + * @param {boolean=} opt_silent Update property without triggering notification. * @api stable */ -ol.Object.prototype.set = function(key, value) { - var oldValue = this.values_[key]; - this.values_[key] = value; - this.notify(key, oldValue); +ol.Object.prototype.set = function(key, value, opt_silent) { + if (opt_silent === true) { + this.values_[key] = value; + } else { + var oldValue = this.values_[key]; + this.values_[key] = value; + this.notify(key, oldValue); + } }; @@ -210,12 +215,13 @@ ol.Object.prototype.set = function(key, value) { * Sets a collection of key-value pairs. Note that this changes any existing * properties and adds new ones (it does not remove any existing properties). * @param {Object.} values Values. + * @param {boolean=} opt_silent update propertie silently * @api stable */ -ol.Object.prototype.setProperties = function(values) { +ol.Object.prototype.setProperties = function(values, opt_silent) { var key; for (key in values) { - this.set(key, values[key]); + this.set(key, values[key], opt_silent); } }; @@ -223,12 +229,15 @@ ol.Object.prototype.setProperties = function(values) { /** * Unsets a property. * @param {string} key Key name. + * @param {boolean=} opt_silent update propertie silently * @api stable */ -ol.Object.prototype.unset = function(key) { +ol.Object.prototype.unset = function(key, opt_silent) { if (key in this.values_) { var oldValue = this.values_[key]; delete this.values_[key]; - this.notify(key, oldValue); + if (!opt_silent) { + this.notify(key, oldValue); + } } }; From c02fdf2393c862a8fad900550f3ca41ba6bffb87 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 11 Nov 2015 11:11:21 -0700 Subject: [PATCH 2/2] Doc corrections and truthy check --- src/ol/object.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ol/object.js b/src/ol/object.js index 0bd5c06864..49e69c875b 100644 --- a/src/ol/object.js +++ b/src/ol/object.js @@ -197,11 +197,11 @@ ol.Object.prototype.notify = function(key, oldValue) { * Sets a value. * @param {string} key Key name. * @param {*} value Value. - * @param {boolean=} opt_silent Update property without triggering notification. + * @param {boolean=} opt_silent Update without triggering an event. * @api stable */ ol.Object.prototype.set = function(key, value, opt_silent) { - if (opt_silent === true) { + if (opt_silent) { this.values_[key] = value; } else { var oldValue = this.values_[key]; @@ -215,7 +215,7 @@ ol.Object.prototype.set = function(key, value, opt_silent) { * Sets a collection of key-value pairs. Note that this changes any existing * properties and adds new ones (it does not remove any existing properties). * @param {Object.} values Values. - * @param {boolean=} opt_silent update propertie silently + * @param {boolean=} opt_silent Update without triggering an event. * @api stable */ ol.Object.prototype.setProperties = function(values, opt_silent) { @@ -229,7 +229,7 @@ ol.Object.prototype.setProperties = function(values, opt_silent) { /** * Unsets a property. * @param {string} key Key name. - * @param {boolean=} opt_silent update propertie silently + * @param {boolean=} opt_silent Unset without triggering an event. * @api stable */ ol.Object.prototype.unset = function(key, opt_silent) {