Notify ol.Object source when transform is called
This commit is contained in:
@@ -61,10 +61,17 @@ goog.inherits(ol.ObjectEvent, goog.events.Event);
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {ol.Object} target
|
||||
* @param {string} key
|
||||
* @param {ol.Object} source Source object.
|
||||
* @param {ol.Object} target Target object.
|
||||
* @param {string} sourceKey Source key.
|
||||
* @param {string} targetKey Target key.
|
||||
*/
|
||||
ol.ObjectAccessor = function(target, key) {
|
||||
ol.ObjectAccessor = function(source, target, sourceKey, targetKey) {
|
||||
|
||||
/**
|
||||
* @type {ol.Object}
|
||||
*/
|
||||
this.source = source;
|
||||
|
||||
/**
|
||||
* @type {ol.Object}
|
||||
@@ -74,7 +81,12 @@ ol.ObjectAccessor = function(target, key) {
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
this.key = key;
|
||||
this.sourceKey = sourceKey;
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
this.targetKey = targetKey;
|
||||
|
||||
/**
|
||||
* @type {function(?): ?}
|
||||
@@ -97,8 +109,7 @@ ol.ObjectAccessor = function(target, key) {
|
||||
ol.ObjectAccessor.prototype.transform = function(from, to) {
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
|
||||
this.target.notify(this.key);
|
||||
this.source.notify(this.sourceKey);
|
||||
};
|
||||
|
||||
|
||||
@@ -267,7 +278,7 @@ ol.Object.prototype.bindTo = function(key, target, opt_targetKey) {
|
||||
* @this {ol.Object}
|
||||
*/
|
||||
function() {
|
||||
this.notifyInternal_(key);
|
||||
this.notify(key);
|
||||
}, undefined, this);
|
||||
|
||||
// listen for beforechange events and relay if key matches
|
||||
@@ -276,9 +287,9 @@ ol.Object.prototype.bindTo = function(key, target, opt_targetKey) {
|
||||
this.createBeforeChangeListener_(key, targetKey),
|
||||
undefined, this);
|
||||
|
||||
var accessor = new ol.ObjectAccessor(target, targetKey);
|
||||
var accessor = new ol.ObjectAccessor(this, target, key, targetKey);
|
||||
this.accessors_[key] = accessor;
|
||||
this.notifyInternal_(key);
|
||||
this.notify(key);
|
||||
return accessor;
|
||||
};
|
||||
|
||||
@@ -319,7 +330,7 @@ ol.Object.prototype.get = function(key) {
|
||||
if (accessors.hasOwnProperty(key)) {
|
||||
var accessor = accessors[key];
|
||||
var target = accessor.target;
|
||||
var targetKey = accessor.key;
|
||||
var targetKey = accessor.targetKey;
|
||||
var getterName = ol.Object.getGetterName(targetKey);
|
||||
var getter = /** @type {function(): *|undefined} */
|
||||
(goog.object.get(target, getterName));
|
||||
@@ -387,30 +398,9 @@ ol.Object.prototype.getProperties = function() {
|
||||
|
||||
|
||||
/**
|
||||
* Notify all observers of a change on this property. This notifies both
|
||||
* objects that are bound to the object's property as well as the object
|
||||
* that it is bound to.
|
||||
* @param {string} key Key name.
|
||||
* @todo api
|
||||
*/
|
||||
ol.Object.prototype.notify = function(key) {
|
||||
var accessors = this.accessors_;
|
||||
if (accessors.hasOwnProperty(key)) {
|
||||
var accessor = accessors[key];
|
||||
var target = accessor.target;
|
||||
var targetKey = accessor.key;
|
||||
target.notify(targetKey);
|
||||
} else {
|
||||
this.notifyInternal_(key);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} key Key name.
|
||||
* @private
|
||||
*/
|
||||
ol.Object.prototype.notifyInternal_ = function(key) {
|
||||
var eventType = ol.Object.getChangeEventType(key);
|
||||
this.dispatchEvent(eventType);
|
||||
this.dispatchEvent(
|
||||
@@ -431,7 +421,7 @@ ol.Object.prototype.set = function(key, value) {
|
||||
if (accessors.hasOwnProperty(key)) {
|
||||
var accessor = accessors[key];
|
||||
var target = accessor.target;
|
||||
var targetKey = accessor.key;
|
||||
var targetKey = accessor.targetKey;
|
||||
value = accessor.from(value);
|
||||
var setterName = ol.Object.getSetterName(targetKey);
|
||||
var setter = /** @type {function(*)|undefined} */
|
||||
@@ -443,7 +433,7 @@ ol.Object.prototype.set = function(key, value) {
|
||||
}
|
||||
} else {
|
||||
this.values_[key] = value;
|
||||
this.notifyInternal_(key);
|
||||
this.notify(key);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user