Rename ol.MVCArray to ol.Array

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