Method that copies properties from another object moved to the BaseObject class. Not using getProperties() to avoid creating an intermediate object that is not used later

This commit is contained in:
Michał Zielański
2020-08-27 09:18:08 +02:00
parent 8e0a61ac5f
commit 0001292a62
10 changed files with 20 additions and 19 deletions

View File

@@ -188,6 +188,18 @@ class BaseObject extends Observable {
}
}
/**
* Apply any properties from another object without triggering events.
* @param {BaseObject} source The source object.
* @protected
*/
applyProperties(source) {
if (!source.values_) {
return;
}
assign(this.values_ || (this.values_ = {}), source.values_);
}
/**
* Unsets a property.
* @param {string} key Key name.

View File

@@ -42,7 +42,7 @@ class Circle extends SimpleGeometry {
undefined,
this.layout
);
circle.importPropertiesFrom(this);
circle.applyProperties(this);
return circle;
}

View File

@@ -109,17 +109,6 @@ class Geometry extends BaseObject {
return abstract();
}
/**
* Import properties from another geometry.
* @param {Geometry} geometry Source geometry.
* @protected
*/
importPropertiesFrom(geometry) {
if (geometry.hasProperties()) {
this.setProperties(geometry.getProperties(), true);
}
}
/**
* @abstract
* @param {number} x X.

View File

@@ -69,7 +69,7 @@ class GeometryCollection extends Geometry {
clone() {
const geometryCollection = new GeometryCollection(null);
geometryCollection.setGeometries(this.geometries_);
geometryCollection.importPropertiesFrom(this);
geometryCollection.applyProperties(this);
return geometryCollection;
}

View File

@@ -91,7 +91,7 @@ class LineString extends SimpleGeometry {
this.flatCoordinates.slice(),
this.layout
);
lineString.importPropertiesFrom(this);
lineString.applyProperties(this);
return lineString;
}

View File

@@ -107,7 +107,7 @@ class MultiLineString extends SimpleGeometry {
this.layout,
this.ends_.slice()
);
multiLineString.importPropertiesFrom(this);
multiLineString.applyProperties(this);
return multiLineString;
}

View File

@@ -61,7 +61,7 @@ class MultiPoint extends SimpleGeometry {
this.flatCoordinates.slice(),
this.layout
);
multiPoint.importPropertiesFrom(this);
multiPoint.applyProperties(this);
return multiPoint;
}

View File

@@ -160,7 +160,7 @@ class MultiPolygon extends SimpleGeometry {
this.layout,
newEndss
);
multiPolygon.importPropertiesFrom(this);
multiPolygon.applyProperties(this);
return multiPolygon;
}

View File

@@ -30,7 +30,7 @@ class Point extends SimpleGeometry {
*/
clone() {
const point = new Point(this.flatCoordinates.slice(), this.layout);
point.importPropertiesFrom(this);
point.applyProperties(this);
return point;
}

View File

@@ -123,7 +123,7 @@ class Polygon extends SimpleGeometry {
this.layout,
this.ends_.slice()
);
polygon.importPropertiesFrom(this);
polygon.applyProperties(this);
return polygon;
}