This commit is contained in:
2021-10-11 11:14:25 +03:00
parent 46ef6b48ec
commit 076141ad80
2 changed files with 16 additions and 16 deletions
+16 -14
View File
@@ -19,15 +19,15 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
function setLastIndex(key){
var n = Number(key);
if (support.arr.isKey(key) && n > this.lastIndex) {
this.lastIndex = n;
if (support.arr.isKey(key) && n > this.__lastIndex) {
this.__lastIndex = n;
}
return this.lastIndex;
return this.__lastIndex;
}
function actualParams() {
var index;
this.length = this.__keys.length;
this.lastIndex = 0;
this.__lastIndex = 0;
for(index in this.__keys) {
setLastIndex.call(this, this.__keys[index]);
}
@@ -39,21 +39,21 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
var Collection = function (data = []) {
this.data = data;
if(Array.isArray(data)) {
this.type = 'array';
this.__type = 'array';
}
else if(typeof data === 'object') {
this.type = 'object';
this.__type = 'object';
if(data.hasOwnProperty('length') && !Object.keys(data).includes('length')) {
this.type = 'arrayObject';
this.__type = 'arrayObject';
}
}
else {
this.type = 'array';
this.__type = 'array';
this.data = [data];
console.warn('collection: not support data' + typeof data);
}
var key;
this.lastIndex = 0;
this.__lastIndex = 0;
this.length = 0;
this.__keys = [];
this.__values = [];
@@ -66,7 +66,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
};
Collection.prototype.all = function () {
if(this.type === 'array' || this.type === 'arrayObject') {
if(this.__type === 'array' || this.__type === 'arrayObject') {
return this.toArray();
}
return this.toObject();
@@ -115,7 +115,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
* @return {kit.Collection}
*/
Collection.prototype.push = function (value) {
this.set(this.lastIndex + 1, value);
this.set(this.__lastIndex + 1, value);
return this;
};
Collection.prototype.get = function (key, defValue = undefined) {
@@ -136,7 +136,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
* @return {kit.Collection}
*/
Collection.prototype.map = function (callback) {
var res = getSimilarInstance(this.type);
var res = getSimilarInstance(this.__type);
for (var key of Object.keys(this.data)) {
res.put(key, valueEx(callback, this.data[key], key, this.data));
}
@@ -185,7 +185,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
* @return {kit.Collection}
*/
Collection.prototype.filter = function (callback = filter) {
var res = getSimilarInstance(this.type);
var res = getSimilarInstance(this.__type);
this.each(function (value, key, arr) {
if(valueEx(callback, value, key, arr)) {
res.put(key, value);
@@ -322,7 +322,9 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
console.log('Collection', this.data);
return this;
};
/**
* @return {kit.Collection}
*/
Collection.prototype.dd = function () {
this.dump();
debugger;