Rename ol.MVCArray to ol.Array
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
goog.provide('ol');
|
||||
|
||||
goog.require('ol.Array');
|
||||
goog.require('ol.Bounds');
|
||||
goog.require('ol.Camera');
|
||||
goog.require('ol.Extent');
|
||||
goog.require('ol.Layer');
|
||||
goog.require('ol.LayerView');
|
||||
goog.require('ol.MVCArray');
|
||||
goog.require('ol.Object');
|
||||
goog.require('ol.Projection');
|
||||
goog.require('ol.TileBounds');
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
* @see https://developers.google.com/maps/documentation/javascript/reference
|
||||
*/
|
||||
|
||||
goog.provide('ol.MVCArray');
|
||||
goog.provide('ol.MVCArrayEvent');
|
||||
goog.provide('ol.MVCArrayEventType');
|
||||
goog.provide('ol.Array');
|
||||
goog.provide('ol.ArrayEvent');
|
||||
goog.provide('ol.ArrayEventType');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.asserts');
|
||||
@@ -17,7 +17,7 @@ goog.require('ol.Object');
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
ol.MVCArrayEventType = {
|
||||
ol.ArrayEventType = {
|
||||
INSERT_AT: 'insert_at',
|
||||
REMOVE_AT: 'remove_at',
|
||||
SET_AT: 'set_at'
|
||||
@@ -28,12 +28,12 @@ ol.MVCArrayEventType = {
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {goog.events.Event}
|
||||
* @param {ol.MVCArrayEventType} type Type.
|
||||
* @param {ol.ArrayEventType} type Type.
|
||||
* @param {number} index Index.
|
||||
* @param {*=} opt_prev Value.
|
||||
* @param {Object=} opt_target Target.
|
||||
*/
|
||||
ol.MVCArrayEvent = function(type, index, opt_prev, opt_target) {
|
||||
ol.ArrayEvent = function(type, index, opt_prev, opt_target) {
|
||||
|
||||
goog.base(this, type, opt_target);
|
||||
|
||||
@@ -48,7 +48,7 @@ ol.MVCArrayEvent = function(type, index, opt_prev, opt_target) {
|
||||
this.prev = opt_prev;
|
||||
|
||||
};
|
||||
goog.inherits(ol.MVCArrayEvent, goog.events.Event);
|
||||
goog.inherits(ol.ArrayEvent, goog.events.Event);
|
||||
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ goog.inherits(ol.MVCArrayEvent, goog.events.Event);
|
||||
* @extends {ol.Object}
|
||||
* @param {Array=} opt_array Array.
|
||||
*/
|
||||
ol.MVCArray = function(opt_array) {
|
||||
ol.Array = function(opt_array) {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
@@ -70,33 +70,33 @@ ol.MVCArray = function(opt_array) {
|
||||
this.updateLength_();
|
||||
|
||||
};
|
||||
goog.inherits(ol.MVCArray, ol.Object);
|
||||
goog.inherits(ol.Array, ol.Object);
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
ol.MVCArray.LENGTH = 'length';
|
||||
ol.Array.LENGTH = 'length';
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.MVCArray|Array} arg Argument.
|
||||
* @return {ol.MVCArray} MVCArray.
|
||||
* @param {ol.Array|Array} arg Argument.
|
||||
* @return {ol.Array} Array.
|
||||
*/
|
||||
ol.MVCArray.create = function(arg) {
|
||||
if (arg instanceof ol.MVCArray) {
|
||||
ol.Array.create = function(arg) {
|
||||
if (arg instanceof ol.Array) {
|
||||
return arg;
|
||||
} else {
|
||||
return new ol.MVCArray(arg);
|
||||
return new ol.Array(arg);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
ol.MVCArray.prototype.clear = function() {
|
||||
while (this[ol.MVCArray.LENGTH]) {
|
||||
ol.Array.prototype.clear = function() {
|
||||
while (this[ol.Array.LENGTH]) {
|
||||
this.pop();
|
||||
}
|
||||
};
|
||||
@@ -105,7 +105,7 @@ ol.MVCArray.prototype.clear = function() {
|
||||
/**
|
||||
* @param {function(*, number)} callback Callback.
|
||||
*/
|
||||
ol.MVCArray.prototype.forEach = function(callback) {
|
||||
ol.Array.prototype.forEach = function(callback) {
|
||||
goog.array.forEach(this.array_, callback);
|
||||
};
|
||||
|
||||
@@ -113,7 +113,7 @@ ol.MVCArray.prototype.forEach = function(callback) {
|
||||
/**
|
||||
* @return {Array} Array.
|
||||
*/
|
||||
ol.MVCArray.prototype.getArray = function() {
|
||||
ol.Array.prototype.getArray = function() {
|
||||
return this.array_;
|
||||
};
|
||||
|
||||
@@ -122,7 +122,7 @@ ol.MVCArray.prototype.getArray = function() {
|
||||
* @param {number} index Index.
|
||||
* @return {*} Element.
|
||||
*/
|
||||
ol.MVCArray.prototype.getAt = function(index) {
|
||||
ol.Array.prototype.getAt = function(index) {
|
||||
return this.array_[index];
|
||||
};
|
||||
|
||||
@@ -130,8 +130,8 @@ ol.MVCArray.prototype.getAt = function(index) {
|
||||
/**
|
||||
* @return {number} Length.
|
||||
*/
|
||||
ol.MVCArray.prototype.getLength = function() {
|
||||
return /** @type {number} */ (this.get(ol.MVCArray.LENGTH));
|
||||
ol.Array.prototype.getLength = function() {
|
||||
return /** @type {number} */ (this.get(ol.Array.LENGTH));
|
||||
};
|
||||
|
||||
|
||||
@@ -139,13 +139,13 @@ ol.MVCArray.prototype.getLength = function() {
|
||||
* @param {number} index Index.
|
||||
* @param {*} elem Element.
|
||||
*/
|
||||
ol.MVCArray.prototype.insertAt = function(index, elem) {
|
||||
ol.Array.prototype.insertAt = function(index, elem) {
|
||||
goog.array.insertAt(this.array_, elem, index);
|
||||
this.updateLength_();
|
||||
this.dispatchEvent(new ol.MVCArrayEvent(
|
||||
ol.MVCArrayEventType.INSERT_AT, index, undefined, this));
|
||||
if (this[ol.MVCArrayEventType.INSERT_AT]) {
|
||||
this[ol.MVCArrayEventType.INSERT_AT](index);
|
||||
this.dispatchEvent(new ol.ArrayEvent(
|
||||
ol.ArrayEventType.INSERT_AT, index, undefined, this));
|
||||
if (this[ol.ArrayEventType.INSERT_AT]) {
|
||||
this[ol.ArrayEventType.INSERT_AT](index);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -153,7 +153,7 @@ ol.MVCArray.prototype.insertAt = function(index, elem) {
|
||||
/**
|
||||
* @return {*} Element.
|
||||
*/
|
||||
ol.MVCArray.prototype.pop = function() {
|
||||
ol.Array.prototype.pop = function() {
|
||||
return this.removeAt(this.getLength() - 1);
|
||||
};
|
||||
|
||||
@@ -162,7 +162,7 @@ ol.MVCArray.prototype.pop = function() {
|
||||
* @param {*} elem Element.
|
||||
* @return {number} Length.
|
||||
*/
|
||||
ol.MVCArray.prototype.push = function(elem) {
|
||||
ol.Array.prototype.push = function(elem) {
|
||||
var n = this.array_.length;
|
||||
this.insertAt(n, elem);
|
||||
return n;
|
||||
@@ -173,14 +173,14 @@ ol.MVCArray.prototype.push = function(elem) {
|
||||
* @param {number} index Index.
|
||||
* @return {*} Value.
|
||||
*/
|
||||
ol.MVCArray.prototype.removeAt = function(index) {
|
||||
ol.Array.prototype.removeAt = function(index) {
|
||||
var prev = this.array_[index];
|
||||
goog.array.removeAt(this.array_, index);
|
||||
this.updateLength_();
|
||||
this.dispatchEvent(new ol.MVCArrayEvent(ol.MVCArrayEventType.REMOVE_AT,
|
||||
this.dispatchEvent(new ol.ArrayEvent(ol.ArrayEventType.REMOVE_AT,
|
||||
index, prev, this));
|
||||
if (this[ol.MVCArrayEventType.REMOVE_AT]) {
|
||||
this[ol.MVCArrayEventType.REMOVE_AT](index);
|
||||
if (this[ol.ArrayEventType.REMOVE_AT]) {
|
||||
this[ol.ArrayEventType.REMOVE_AT](index);
|
||||
}
|
||||
return prev;
|
||||
};
|
||||
@@ -190,15 +190,15 @@ ol.MVCArray.prototype.removeAt = function(index) {
|
||||
* @param {number} index Index.
|
||||
* @param {*} elem Element.
|
||||
*/
|
||||
ol.MVCArray.prototype.setAt = function(index, elem) {
|
||||
var n = this[ol.MVCArray.LENGTH];
|
||||
ol.Array.prototype.setAt = function(index, elem) {
|
||||
var n = this[ol.Array.LENGTH];
|
||||
if (index < n) {
|
||||
var prev = this.array_[index];
|
||||
this.array_[index] = elem;
|
||||
this.dispatchEvent(new ol.MVCArrayEvent(ol.MVCArrayEventType.SET_AT,
|
||||
this.dispatchEvent(new ol.ArrayEvent(ol.ArrayEventType.SET_AT,
|
||||
index, prev, this));
|
||||
if (this[ol.MVCArrayEventType.SET_AT]) {
|
||||
this[ol.MVCArrayEventType.SET_AT](index, prev);
|
||||
if (this[ol.ArrayEventType.SET_AT]) {
|
||||
this[ol.ArrayEventType.SET_AT](index, prev);
|
||||
}
|
||||
} else {
|
||||
var j;
|
||||
@@ -213,6 +213,6 @@ ol.MVCArray.prototype.setAt = function(index, elem) {
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ol.MVCArray.prototype.updateLength_ = function() {
|
||||
ol.Array.prototype.updateLength_ = function() {
|
||||
this.set('length', this.array_.length);
|
||||
};
|
||||
@@ -1,11 +1,11 @@
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.testing.jsunit');
|
||||
goog.require('ol.MVCArray');
|
||||
goog.require('ol.MVCArrayEventType');
|
||||
goog.require('ol.Array');
|
||||
goog.require('ol.ArrayEventType');
|
||||
|
||||
|
||||
function testEmpty() {
|
||||
var a = new ol.MVCArray();
|
||||
var a = new ol.Array();
|
||||
assertEquals(0, a.getLength());
|
||||
assertTrue(goog.array.equals(a.getArray(), []));
|
||||
assertUndefined(a.getAt(0));
|
||||
@@ -14,7 +14,7 @@ function testEmpty() {
|
||||
|
||||
function testConstruct() {
|
||||
var array = [0, 1, 2];
|
||||
var a = new ol.MVCArray(array);
|
||||
var a = new ol.Array(array);
|
||||
assertEquals(0, a.getAt(0));
|
||||
assertEquals(1, a.getAt(1));
|
||||
assertEquals(2, a.getAt(2));
|
||||
@@ -22,7 +22,7 @@ function testConstruct() {
|
||||
|
||||
|
||||
function testPush() {
|
||||
var a = new ol.MVCArray();
|
||||
var a = new ol.Array();
|
||||
a.push(1);
|
||||
assertEquals(1, a.getLength());
|
||||
assertTrue(goog.array.equals(a.getArray(), [1]));
|
||||
@@ -31,7 +31,7 @@ function testPush() {
|
||||
|
||||
|
||||
function testPushPop() {
|
||||
var a = new ol.MVCArray();
|
||||
var a = new ol.Array();
|
||||
a.push(1);
|
||||
a.pop();
|
||||
assertEquals(0, a.getLength());
|
||||
@@ -41,7 +41,7 @@ function testPushPop() {
|
||||
|
||||
|
||||
function testInsertAt() {
|
||||
var a = new ol.MVCArray([0, 2]);
|
||||
var a = new ol.Array([0, 2]);
|
||||
a.insertAt(1, 1);
|
||||
assertEquals(0, a.getAt(0));
|
||||
assertEquals(1, a.getAt(1));
|
||||
@@ -50,7 +50,7 @@ function testInsertAt() {
|
||||
|
||||
|
||||
function testSetAt() {
|
||||
var a = new ol.MVCArray();
|
||||
var a = new ol.Array();
|
||||
a.setAt(1, 1);
|
||||
assertEquals(2, a.getLength());
|
||||
assertUndefined(a.getAt(0));
|
||||
@@ -59,7 +59,7 @@ function testSetAt() {
|
||||
|
||||
|
||||
function testRemoveAt() {
|
||||
var a = new ol.MVCArray([0, 1, 2]);
|
||||
var a = new ol.Array([0, 1, 2]);
|
||||
a.removeAt(1);
|
||||
assertEquals(0, a.getAt(0));
|
||||
assertEquals(2, a.getAt(1));
|
||||
@@ -67,7 +67,7 @@ function testRemoveAt() {
|
||||
|
||||
|
||||
function testForEachEmpty() {
|
||||
var a = new ol.MVCArray();
|
||||
var a = new ol.Array();
|
||||
var forEachCalled = false;
|
||||
a.forEach(function() {
|
||||
forEachCalled = true;
|
||||
@@ -77,7 +77,7 @@ function testForEachEmpty() {
|
||||
|
||||
|
||||
function testForEachPopulated() {
|
||||
var a = new ol.MVCArray();
|
||||
var a = new ol.Array();
|
||||
a.push(1);
|
||||
a.push(2);
|
||||
var forEachCount = 0;
|
||||
@@ -89,9 +89,9 @@ function testForEachPopulated() {
|
||||
|
||||
|
||||
function testSetAtEvent() {
|
||||
var a = new ol.MVCArray(['a', 'b']);
|
||||
var a = new ol.Array(['a', 'b']);
|
||||
var index, prev;
|
||||
goog.events.listen(a, ol.MVCArrayEventType.SET_AT, function(e) {
|
||||
goog.events.listen(a, ol.ArrayEventType.SET_AT, function(e) {
|
||||
index = e.index;
|
||||
prev = e.prev;
|
||||
});
|
||||
@@ -102,9 +102,9 @@ function testSetAtEvent() {
|
||||
|
||||
|
||||
function testRemoveAtEvent() {
|
||||
var a = new ol.MVCArray(['a']);
|
||||
var a = new ol.Array(['a']);
|
||||
var index, prev;
|
||||
goog.events.listen(a, ol.MVCArrayEventType.REMOVE_AT, function(e) {
|
||||
goog.events.listen(a, ol.ArrayEventType.REMOVE_AT, function(e) {
|
||||
index = e.index;
|
||||
prev = e.prev;
|
||||
});
|
||||
@@ -115,9 +115,9 @@ function testRemoveAtEvent() {
|
||||
|
||||
|
||||
function testInsertAtEvent() {
|
||||
var a = new ol.MVCArray([0, 2]);
|
||||
var a = new ol.Array([0, 2]);
|
||||
var index;
|
||||
goog.events.listen(a, ol.MVCArrayEventType.INSERT_AT, function(e) {
|
||||
goog.events.listen(a, ol.ArrayEventType.INSERT_AT, function(e) {
|
||||
index = e.index;
|
||||
});
|
||||
a.insertAt(1, 1);
|
||||
@@ -126,7 +126,7 @@ function testInsertAtEvent() {
|
||||
|
||||
|
||||
function testSetAtBeyondEnd() {
|
||||
var a = new ol.MVCArray();
|
||||
var a = new ol.Array();
|
||||
var inserts = [];
|
||||
a.insert_at = function(index) {
|
||||
inserts.push(index);
|
||||
@@ -145,18 +145,18 @@ function testSetAtBeyondEnd() {
|
||||
|
||||
function testCreateFromArray() {
|
||||
var a = [0, 1, 2];
|
||||
var mvcArray = ol.MVCArray.create(a);
|
||||
assertTrue(mvcArray instanceof ol.MVCArray);
|
||||
assertEquals(3, mvcArray.getLength());
|
||||
assertEquals(0, mvcArray.getAt(0));
|
||||
assertEquals(1, mvcArray.getAt(1));
|
||||
assertEquals(2, mvcArray.getAt(2));
|
||||
var array = ol.Array.create(a);
|
||||
assertTrue(array instanceof ol.Array);
|
||||
assertEquals(3, array.getLength());
|
||||
assertEquals(0, array.getAt(0));
|
||||
assertEquals(1, array.getAt(1));
|
||||
assertEquals(2, array.getAt(2));
|
||||
}
|
||||
|
||||
|
||||
function testCreateFromMVCArray() {
|
||||
var mvcArray1 = new ol.MVCArray();
|
||||
var mvcArray2 = ol.MVCArray.create(mvcArray1);
|
||||
assertTrue(mvcArray1 === mvcArray2);
|
||||
function testCreateFromArray() {
|
||||
var array1 = new ol.Array();
|
||||
var array2 = ol.Array.create(array1);
|
||||
assertTrue(array1 === array2);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user