This commit is contained in:
2021-10-30 17:20:26 +03:00
parent 1a29c16bcd
commit cd65398fb0
18 changed files with 855 additions and 290 deletions
+69 -5
View File
@@ -1,7 +1,4 @@
/** @module collection */
/**
* в разработке
*/
/** @module Collection */
kit.PluginManager.register('Collection', function(module, exports, require, global) {
var support = require('support');
@@ -107,7 +104,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
* @param value
* @return {kit.Collection}
*/
Collection.prototype.set = Collection.prototype.put = function (key, value) {
Collection.prototype.add = Collection.prototype.set = Collection.prototype.put = function (key, value) {
var index = -1;
if(this.has(key)) {
this.data[key] = this.__values[index = this.indexKey(key)] = value;
@@ -380,6 +377,73 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
debugger;
return this;
};
/**
* @return {kit.Collection}
*/
Collection.prototype.eachCall = function (context, args1, args2) {
var args = [];
if(arguments.length > 1)
for(var 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;
}
}
} catch (e) {
if (e !== BreakException) throw e;
}
return this;
};
/**
* аналог Array.includes
*
* @param searchElement
* @param fromIndex
* @return {boolean}
*/
Collection.prototype.includes = function(searchElement, fromIndex) {
var len = this.__keys.length;
if (len === 0) {
return false;
}
var n = fromIndex | 0;
var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
function sameValueZero(x, y) {
return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y));
}
while (k < len) {
if (sameValueZero(this.__values[k], searchElement)) {
return true;
}
k++;
}
return false;
};
Collection.prototype.search = function(searchElement) {
var len = this.__keys.length;
if (len === 0) {
return false;
}
var k = 0;
function sameValueZero(x, y) {
return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y));
}
while (k < len) {
if (sameValueZero(this.__values[k], searchElement)) {
return this.__keys[k];
}
k++;
}
return false;
};
return module.exports = Collection;
});