This commit is contained in:
2021-11-01 21:52:13 +03:00
parent 353e0715ca
commit 82452a959e
12 changed files with 798 additions and 844 deletions
+28 -37
View File
@@ -91,13 +91,16 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
return ob;
};
Collection.prototype.serialize = function () {
return JSON.stringify(this.all());
return JSON.stringify(this.toObject());
};
Collection.prototype.serializeArray = function () {
return JSON.stringify(this.toArray());
};
Collection.prototype.has = function (key) {
return this.data.hasOwnProperty(key) && this.__keys.includes(safeArrayKey(key));
return this.__keys.includes(safeArrayKey(key));
};
Collection.prototype.indexKey = function (key) {
return this.__keys.indexOf(key);
return this.__keys.indexOf(safeArrayKey(key));
};
/**
* @param key
@@ -157,17 +160,13 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
* @return {kit.Collection}
*/
Collection.prototype.each = function (callback = true) {
var BreakException = {}, i;
try {
if(this.__keys.length)
for (i = 0; i < this.__keys.length; i++) {
if(valueEx(callback, this.__values[i], this.__keys[i], this.data) === false) {
throw BreakException;
}
var i;
if(this.__keys.length)
for (i = 0; i < this.__keys.length; i++) {
if(valueEx(callback, this.__values[i], this.__keys[i], this.data) === false) {
break;
}
} catch (e) {
if (e !== BreakException) throw e;
}
}
return this;
};
/**
@@ -175,17 +174,13 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
* @return {kit.Collection}
*/
Collection.prototype.eachReverse = function (callback = true) {
var BreakException = {}, i;
try {
if(this.__keys.length)
for (i = this.__keys.length - 1; i >= 0; i--) {
if(valueEx(callback, this.__values[i], this.__keys[i], this.data) === false) {
throw BreakException;
}
var i;
if(this.__keys.length)
for (i = this.__keys.length - 1; i >= 0; i--) {
if(valueEx(callback, this.__values[i], this.__keys[i], this.data) === false) {
break;
}
} catch (e) {
if (e !== BreakException) throw e;
}
}
return this;
};
/**
@@ -328,7 +323,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
* Method removes and returns the last item from the collection
*/
Collection.prototype.pop = function(){
var index = this.length - 1;
var index = this.__keys.length - 1;
if(index < 0) {
return undefined;
}
@@ -381,23 +376,19 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
* @return {kit.Collection}
*/
Collection.prototype.eachCall = function (context, args1, args2) {
var args = [];
var args = [], i;
if(arguments.length > 1)
for(var i = 1; arguments.length - 1 >= i;i++) {
for(i = 1; arguments.length - 1 >= i;i++) {
args.push(arguments[i]);
}
var BreakException = {}, i;
try {
if(this.__keys.length)
for (i = 0; i < this.__keys.length; i++) {
if(typeof this.__values[i] === 'function' &&
this.__values[i].apply(context, [].concat(args, this.__keys[i])) === false) {
throw BreakException;
}
if(this.__keys.length)
for (i = 0; i < this.__keys.length; i++) {
if(typeof this.__values[i] === 'function' &&
this.__values[i].apply(context, [].concat(args, this.__keys[i])) === false) {
throw BreakException;
}
} catch (e) {
if (e !== BreakException) throw e;
}
}
return this;
};