Update: BaseArrayClass
MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="2.0.0-beta2-20170718-1936" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
+<plugin id="cordova-plugin-googlemaps" version="2.0.0-beta2-20170719-2130" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>cordova-plugin-googlemaps</name>
<js-module name="BaseClass" src="www/BaseClass.js">
<runs />

MODIFY
www/BaseArrayClass.js
www/BaseArrayClass.js
@@ -13,7 +13,7 @@ function BaseArrayClass(array) {
}
self.map = function(fn, callback) {
- if (typeof fn !== "function" || _array.length === 0) {
+ if (typeof fn !== "function") {
return;
}
var results = [];
@@ -42,6 +42,10 @@ function BaseArrayClass(array) {
});
var _arrayLength = _array.length;
var finishCnt = 0;
+ if (_arrayLength === 0) {
+ callback.call(self, []);
+ return;
+ }
_array.forEach(function(item, idx) {
fn.call(self, item, function(value) {
results[idx] = value;
@@ -54,7 +58,7 @@ function BaseArrayClass(array) {
};
self.forEach = function(fn, callback) {
- if (typeof fn !== "function" || _array.length === 0) {
+ if (typeof fn !== "function") {
return;
}
if (typeof fn === "function" && typeof callback !== "function") {
@@ -78,6 +82,11 @@ function BaseArrayClass(array) {
//------------------------
var finishCnt = 0;
var _arrayLength = _array.length;
+ if (_arrayLength === 0) {
+ callback.call(self);
+ return;
+ }
+
_array.forEach(function(item, idx) {
fn.call(self, item, function() {
finishCnt++;
@@ -88,16 +97,59 @@ function BaseArrayClass(array) {
});
};
- self.empty = function(noNotify) {
- var tmp = [];
- for (var i = 0; i < _array.length; i++) {
- tmp.push(1);
+ self.filter = function(fn, callback) {
+ if (typeof fn !== "function") {
+ return;
}
- tmp.forEach(function() {
- self.removeAt(0, noNotify);
+ if (typeof fn === "function" && typeof callback !== "function") {
+ //------------------------
+ // example:
+ // baseArray.filter(function(item, idx) {
+ // ...
+ // return true or false
+ // });
+ //------------------------
+ return _array.filter(fn.bind(self));
+ }
+ //------------------------
+ // example:
+ // baseArray.filter(function(item, callback) {
+ // ...
+ // callback(true or false);
+ // }, function(filteredItems) {
+ //
+ // });
+ //------------------------
+ var finishCnt = 0;
+ var _arrayLength = _array.length;
+ if (_arrayLength === 0) {
+ callback.call(self, []);
+ return;
+ }
+ var results = [];
+ _array.forEach(function(item, idx) {
+ fn.call(self, item, function(isOk) {
+ if (isOk) {
+ results.push(item);
+ }
+ finishCnt++;
+ if (finishCnt === _arrayLength) {
+ callback.call(self, results);
+ }
+ });
});
};
+ self.indexOf = function(item) {
+ return _array.indexOf(item);
+ };
+ self.empty = function(noNotify) {
+ var cnt = _array.length;
+ for (var i = 0; i < cnt; i++) {
+ self.removeAt(0, noNotify);
+ }
+ };
+
self.push = function(value, noNotify) {
_array.push(value);
if (noNotify !== true) {
@@ -156,6 +208,12 @@ function BaseArrayClass(array) {
self.getLength = function() {
return _array.length;
};
+ self.reverse = function() {
+ _array = _array.reverse();
+ };
+ self.sort = function(func) {
+ _array = _array.sort(func);
+ };
return self;
}

Update: BaseArrayClass