Commit bfe36960 authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Controla actualización de props mutables

La comprobación de cambio de valor de propiedad antes de actualizar
(mediante SET_PROPS) introducida en d928487c trajo consigo problemas. En
aquellos casos donde el valor sea de tipo object, lo que se asigna es la
referencia, y no su valor. Esto ocasiona que sólo se pudieran actualizar
la primera vez, ya que luego el valor se había cambiado instantáneamente
al cambiar el original.

Para estos casos, se realiza una copia (siempre que no se trate de una
instancia de módulo) y se evita el problema.
parent dfb9cb3a
Loading
Loading
Loading
Loading
+35 −24
Original line number Diff line number Diff line
@@ -733,16 +733,24 @@ define([
			var propNames = [];

			for (var prop in req) {
				var value = req[prop],
				var value = this._getUnmutableValue(req[prop]),
					oldValue = this[prop];

				if (this._checkPropIsShareable(prop)) {
				if (!this._checkPropIsShareable(prop)) {
					console.error('Tried to set not settable property "%s" at module "%s"', prop, this.getChannel());
					continue;
				}

				if (value === oldValue) {
					console.warn('Tried to update property "%s" using same value "%s" at module "%s"', prop, value,
						this.getChannel());

					continue;
				}

				this[prop] = value;
				propNames.push(prop);

				var evtKey = this._createEvent(prop + this.propSetSuffix),
					methodName = '_on' + Utilities.capitalize(prop) + 'PropSet',
					changeObj = {
@@ -751,15 +759,9 @@ define([
						value: value
					};

					this[prop] = value;

				this._emitEvt(evtKey, changeObj);
				this[methodName] && this[methodName](changeObj);

					propNames.push(prop);
				} else {
					console.error("Tried to set not settable property '%s' at module '%s'", prop, this.getChannel());
				}
			}

			this._emitEvt('PROPS_SET', {
@@ -767,6 +769,15 @@ define([
			});
		},

		_getUnmutableValue: function(value) {

			if (typeof value === 'object' && !value.ownChannel) {
				return lang.clone(value);
			}

			return value;
		},

		_subGetProps: function(req) {

			var props = {};