Make ol.Object#accessors_ a private renameable property
This commit is contained in:
+13
-20
@@ -107,7 +107,6 @@ ol.ObjectAccessor.prototype.transform = function(from, to) {
|
|||||||
* @enum {string}
|
* @enum {string}
|
||||||
*/
|
*/
|
||||||
ol.ObjectProperty = {
|
ol.ObjectProperty = {
|
||||||
ACCESSORS: 'ol_accessors_',
|
|
||||||
BINDINGS: 'ol_bindings_'
|
BINDINGS: 'ol_bindings_'
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -129,6 +128,12 @@ ol.Object = function(opt_values) {
|
|||||||
*/
|
*/
|
||||||
this.values_ = {};
|
this.values_ = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {Object.<string, ol.ObjectAccessor>}
|
||||||
|
*/
|
||||||
|
this.accessors_ = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lookup of beforechange listener keys.
|
* Lookup of beforechange listener keys.
|
||||||
* @type {Object.<string, goog.events.Key>}
|
* @type {Object.<string, goog.events.Key>}
|
||||||
@@ -173,16 +178,6 @@ ol.Object.capitalize = function(str) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {ol.Object} obj Object.
|
|
||||||
* @return {Object.<string, ol.ObjectAccessor>} Accessors.
|
|
||||||
*/
|
|
||||||
ol.Object.getAccessors = function(obj) {
|
|
||||||
return obj[ol.ObjectProperty.ACCESSORS] ||
|
|
||||||
(obj[ol.ObjectProperty.ACCESSORS] = {});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} key Key name.
|
* @param {string} key Key name.
|
||||||
* @return {string} Change name.
|
* @return {string} Change name.
|
||||||
@@ -273,8 +268,7 @@ ol.Object.prototype.bindTo = function(key, target, opt_targetKey) {
|
|||||||
undefined, this);
|
undefined, this);
|
||||||
|
|
||||||
var accessor = new ol.ObjectAccessor(target, targetKey);
|
var accessor = new ol.ObjectAccessor(target, targetKey);
|
||||||
var accessors = ol.Object.getAccessors(this);
|
this.accessors_[key] = accessor;
|
||||||
accessors[key] = accessor;
|
|
||||||
this.notifyInternal_(key);
|
this.notifyInternal_(key);
|
||||||
return accessor;
|
return accessor;
|
||||||
};
|
};
|
||||||
@@ -312,7 +306,7 @@ ol.Object.prototype.createBeforeChangeListener_ = function(key, targetKey) {
|
|||||||
*/
|
*/
|
||||||
ol.Object.prototype.get = function(key) {
|
ol.Object.prototype.get = function(key) {
|
||||||
var value;
|
var value;
|
||||||
var accessors = ol.Object.getAccessors(this);
|
var accessors = this.accessors_;
|
||||||
if (accessors.hasOwnProperty(key)) {
|
if (accessors.hasOwnProperty(key)) {
|
||||||
var accessor = accessors[key];
|
var accessor = accessors[key];
|
||||||
var target = accessor.target;
|
var target = accessor.target;
|
||||||
@@ -336,7 +330,7 @@ ol.Object.prototype.get = function(key) {
|
|||||||
* @return {Array.<string>} List of property names.
|
* @return {Array.<string>} List of property names.
|
||||||
*/
|
*/
|
||||||
ol.Object.prototype.getKeys = function() {
|
ol.Object.prototype.getKeys = function() {
|
||||||
var accessors = ol.Object.getAccessors(this);
|
var accessors = this.accessors_;
|
||||||
var keysObject;
|
var keysObject;
|
||||||
if (goog.object.isEmpty(this.values_)) {
|
if (goog.object.isEmpty(this.values_)) {
|
||||||
if (goog.object.isEmpty(accessors)) {
|
if (goog.object.isEmpty(accessors)) {
|
||||||
@@ -372,7 +366,7 @@ ol.Object.prototype.getProperties = function() {
|
|||||||
for (key in this.values_) {
|
for (key in this.values_) {
|
||||||
properties[key] = this.values_[key];
|
properties[key] = this.values_[key];
|
||||||
}
|
}
|
||||||
for (key in ol.Object.getAccessors(this)) {
|
for (key in this.accessors_) {
|
||||||
properties[key] = this.get(key);
|
properties[key] = this.get(key);
|
||||||
}
|
}
|
||||||
return properties;
|
return properties;
|
||||||
@@ -387,7 +381,7 @@ ol.Object.prototype.getProperties = function() {
|
|||||||
* @todo stability experimental
|
* @todo stability experimental
|
||||||
*/
|
*/
|
||||||
ol.Object.prototype.notify = function(key) {
|
ol.Object.prototype.notify = function(key) {
|
||||||
var accessors = ol.Object.getAccessors(this);
|
var accessors = this.accessors_;
|
||||||
if (accessors.hasOwnProperty(key)) {
|
if (accessors.hasOwnProperty(key)) {
|
||||||
var accessor = accessors[key];
|
var accessor = accessors[key];
|
||||||
var target = accessor.target;
|
var target = accessor.target;
|
||||||
@@ -420,7 +414,7 @@ ol.Object.prototype.notifyInternal_ = function(key) {
|
|||||||
ol.Object.prototype.set = function(key, value) {
|
ol.Object.prototype.set = function(key, value) {
|
||||||
this.dispatchEvent(
|
this.dispatchEvent(
|
||||||
new ol.ObjectEvent(ol.ObjectEventType.BEFOREPROPERTYCHANGE, key));
|
new ol.ObjectEvent(ol.ObjectEventType.BEFOREPROPERTYCHANGE, key));
|
||||||
var accessors = ol.Object.getAccessors(this);
|
var accessors = this.accessors_;
|
||||||
if (accessors.hasOwnProperty(key)) {
|
if (accessors.hasOwnProperty(key)) {
|
||||||
var accessor = accessors[key];
|
var accessor = accessors[key];
|
||||||
var target = accessor.target;
|
var target = accessor.target;
|
||||||
@@ -471,8 +465,7 @@ ol.Object.prototype.unbind = function(key) {
|
|||||||
delete listeners[key];
|
delete listeners[key];
|
||||||
goog.events.unlistenByKey(listener);
|
goog.events.unlistenByKey(listener);
|
||||||
var value = this.get(key);
|
var value = this.get(key);
|
||||||
var accessors = ol.Object.getAccessors(this);
|
delete this.accessors_[key];
|
||||||
delete accessors[key];
|
|
||||||
this.values_[key] = value;
|
this.values_[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user