mirror of
https://bitbucket.org/bellord13/kit.git
synced 2026-11-13 19:06:11 +03:00
fix
This commit is contained in:
@@ -19,6 +19,10 @@ __PluginManager__.registerPlugins({
|
|||||||
type: 'loader',
|
type: 'loader',
|
||||||
deps: ['support']
|
deps: ['support']
|
||||||
},
|
},
|
||||||
|
flexKit: {
|
||||||
|
path: __pmConfig__.assetsPath + '/flex-kit',
|
||||||
|
css: '/flex-kit.css'
|
||||||
|
},
|
||||||
support: {
|
support: {
|
||||||
path: __pmConfig__.assetsPath + '/support',
|
path: __pmConfig__.assetsPath + '/support',
|
||||||
module: '/support.js',
|
module: '/support.js',
|
||||||
|
|||||||
@@ -2,15 +2,9 @@
|
|||||||
<script src="../assets/core/core.js"></script>
|
<script src="../assets/core/core.js"></script>
|
||||||
<script src="../assets/core/core.register.js"></script>
|
<script src="../assets/core/core.register.js"></script>
|
||||||
|
|
||||||
<?
|
<div class="kit-wrapper">
|
||||||
print_r('by php collection: ');
|
<div class="kit-logger"></div>
|
||||||
$x = [];
|
</div>
|
||||||
$x[10] = 10;
|
|
||||||
$x[1] = 1;
|
|
||||||
print_r($x);
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
@@ -26,37 +20,33 @@ print_r($x);
|
|||||||
window.args = arguments;
|
window.args = arguments;
|
||||||
})(1, 2, 3, 'as');
|
})(1, 2, 3, 'as');
|
||||||
|
|
||||||
function assertSame(value, need, msg) {
|
|
||||||
if(value === need) {
|
kit.ready(['collection', 'testing', 'flexKit'], function () {
|
||||||
console.log(true, msg);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.error(msg, '-', 'value:', value, 'need:', need);
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
<h1>в консоле</h1>
|
var unit = new kit.testing.Unit();
|
||||||
<script>
|
unit.logger.info('Коллекции by php collection: Array ( [10] => 10 [1] => 1 )');
|
||||||
|
unit.logger.notice(' ');
|
||||||
|
unit.logger.info('ARRAY');
|
||||||
|
var assertSame = unit.assertSame.bind(unit);
|
||||||
|
|
||||||
kit.ready(['collection'], function () {
|
|
||||||
|
|
||||||
console.warn('ARRAY');
|
|
||||||
|
|
||||||
var arr = [];
|
var arr = [];
|
||||||
arr[10] = 100;
|
arr[10] = 100;
|
||||||
var collection = new kit.Collection(arr);
|
var collection = new kit.Collection(arr);
|
||||||
assertSame(collection.count(), 1, 'Количество');
|
assertSame(1, collection.count(), 'Количество');
|
||||||
assertSame(collection.has(10), true, 'has (int) 10');
|
assertSame(true, collection.has(10), 'has (int) 10');
|
||||||
assertSame(collection.has('10'), true, 'has 10');
|
assertSame(true, collection.has('10'), 'has 10');
|
||||||
assertSame(collection.has('5'), false, 'has 5');
|
assertSame(false, collection.has('5'), 'has 5');
|
||||||
assertSame(collection.get(3, 2), 2, 'get');
|
assertSame(2, collection.get(3, 2), 'get');
|
||||||
assertSame(collection.get(10, 2), 100, 'get');
|
assertSame(100, collection.get(10, 2), 'get');
|
||||||
assertSame(collection.get(11), undefined, 'get');
|
assertSame(undefined, collection.get(11), 'get');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
console.warn('Object');
|
unit.logger.info(' ');
|
||||||
|
unit.logger.info('Object');
|
||||||
|
unit.logger.info(' ');
|
||||||
|
|
||||||
var ob = {
|
var ob = {
|
||||||
a: 1,
|
a: 1,
|
||||||
@@ -65,28 +55,28 @@ kit.ready(['collection'], function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
collection = new kit.Collection(ob);
|
collection = new kit.Collection(ob);
|
||||||
assertSame(collection.count(), 3, 'Количество');
|
assertSame(3, collection.count(), 'Количество');
|
||||||
assertSame(collection.has(10), true, 'has');
|
assertSame(true, collection.has(10), 'has');
|
||||||
assertSame(collection.has('10'), true, 'has');
|
assertSame(true, collection.has('10'), 'has');
|
||||||
assertSame(collection.has('5'), false, 'has');
|
assertSame(false, collection.has('5'), 'has');
|
||||||
assertSame(collection.get('a'), 1, 'get');
|
assertSame(1, collection.get('a'), 'get');
|
||||||
assertSame(collection.get(3, 2), 2, 'get');
|
assertSame(2, collection.get(3, 2), 'get');
|
||||||
assertSame(collection.get(10, 2), 3, 'get');
|
assertSame(3, collection.get(10, 2), 'get');
|
||||||
assertSame(collection.get(11), undefined, 'get');
|
assertSame(undefined, collection.get(11), 'get');
|
||||||
assertSame(JSON.stringify(collection.set(5, 19).all()), JSON.stringify({
|
assertSame(JSON.stringify({
|
||||||
a: 1,
|
a: 1,
|
||||||
b: 2,
|
b: 2,
|
||||||
10: 3,
|
10: 3,
|
||||||
5: 19,
|
5: 19,
|
||||||
}), 'get all');
|
}), JSON.stringify(collection.set(5, 19).all()), 'get all');
|
||||||
|
|
||||||
|
|
||||||
var testFunction = function (q, w, e, r, t, y) {
|
var testFunction = function (q, w, e, r, t, y) {
|
||||||
var c = new kit.Collection(arguments);
|
var c = new kit.Collection(arguments);
|
||||||
assertSame(c.count(), 8, 'arguments count');
|
assertSame(8, c.count(), 'arguments count');
|
||||||
assertSame(c.get(0), 1, 'arguments get');
|
assertSame(1, c.get(0), 'arguments get');
|
||||||
assertSame(c.get(7), 8, 'arguments get');
|
assertSame(8, c.get(7), 'arguments get');
|
||||||
assertSame(c.get(8, 80), 80, 'arguments get');
|
assertSame(80, c.get(8, 80), 'arguments get');
|
||||||
}
|
}
|
||||||
testFunction(1, 2, 3, 4, 5, 6, 7, 8);
|
testFunction(1, 2, 3, 4, 5, 6, 7, 8);
|
||||||
|
|
||||||
@@ -94,95 +84,95 @@ kit.ready(['collection'], function () {
|
|||||||
|
|
||||||
|
|
||||||
collection = new kit.Collection([1, 2, 3, '', 0, NaN, undefined, null, false, true]);
|
collection = new kit.Collection([1, 2, 3, '', 0, NaN, undefined, null, false, true]);
|
||||||
assertSame(collection.filter().count(), 4, 'filter');
|
assertSame(4, collection.filter().count(), 'filter');
|
||||||
|
|
||||||
collection = new kit.Collection([4, 5, 6]);
|
collection = new kit.Collection([4, 5, 6]);
|
||||||
assertSame(collection.every(function (item) {
|
assertSame(true, collection.every(function (item) {
|
||||||
return item > 2;
|
return item > 2;
|
||||||
}), true, 'every');
|
}), 'every');
|
||||||
assertSame(collection.every(function (item) {
|
assertSame(false, collection.every(function (item) {
|
||||||
return item > 5;
|
return item > 5;
|
||||||
}), false, 'every');
|
}), 'every');
|
||||||
assertSame(collection.every(function (item) {
|
assertSame(false, collection.every(function (item) {
|
||||||
return item < 1;
|
return item < 1;
|
||||||
}), false, 'every');
|
}), 'every');
|
||||||
|
|
||||||
|
|
||||||
collection = new kit.Collection([10, 20, 30]);
|
collection = new kit.Collection([10, 20, 30]);
|
||||||
assertSame(collection.first(), 10, 'first');
|
assertSame(10, collection.first(), 'first');
|
||||||
assertSame(collection.first(function (item) {
|
assertSame(20, collection.first(function (item) {
|
||||||
return item > 15;
|
return item > 15;
|
||||||
}), 20, 'first');
|
}), 'first');
|
||||||
assertSame(collection.first(function (item) {
|
assertSame(undefined, collection.first(function (item) {
|
||||||
return item < 0;
|
return item < 0;
|
||||||
}), undefined, 'first');
|
}), 'first');
|
||||||
|
|
||||||
assertSame(collection.last(), 30, 'first');
|
assertSame(30, collection.last(), 'first');
|
||||||
assertSame(collection.last(function (item) {
|
assertSame(20, collection.last(function (item) {
|
||||||
return item < 25;
|
return item < 25;
|
||||||
}), 20, 'first');
|
}), 'first');
|
||||||
assertSame(collection.last(function (item) {
|
assertSame(undefined, collection.last(function (item) {
|
||||||
return item < 0;
|
return item < 0;
|
||||||
}), undefined, 'first');
|
}), 'first');
|
||||||
|
|
||||||
assertSame(collection.keys().count(), 3, 'keys');
|
assertSame(3, collection.keys().count(), 'keys');
|
||||||
|
|
||||||
xOb = {1: 1, 100: 100};
|
xOb = {1: 1, 100: 100};
|
||||||
x = new kit.Collection(xOb);
|
x = new kit.Collection(xOb);
|
||||||
x.push(200);
|
x.push(200);
|
||||||
assertSame(x.last(), 200, 'object push last');
|
assertSame(200, x.last(), 'object push last');
|
||||||
x.push(0);
|
x.push(0);
|
||||||
assertSame(x.last(), 0, 'object push last');
|
assertSame(0, x.last(), 'object push last');
|
||||||
x.push(undefined);
|
x.push(undefined);
|
||||||
assertSame(x.last(), undefined, 'object push last');
|
assertSame(undefined, x.last(), 'object push last');
|
||||||
x.push('window');
|
x.push('window');
|
||||||
assertSame(x.last(), 'window', 'object push last');
|
assertSame('window', x.last(), 'object push last');
|
||||||
assertSame(x.get(x.lastKey()), 'window', 'get lastKey');
|
assertSame('window', x.get(x.lastKey()), 'get lastKey');
|
||||||
assertSame(x.length, 6, 'length');
|
assertSame(6, x.length, 'length');
|
||||||
|
|
||||||
x = new kit.Collection([1, 100]);
|
x = new kit.Collection([1, 100]);
|
||||||
x.push(200);
|
x.push(200);
|
||||||
assertSame(x.last(), 200, 'array push last');
|
assertSame(200, x.last(), 'array push last');
|
||||||
x.push(0);
|
x.push(0);
|
||||||
assertSame(x.last(), 0, 'array push last');
|
assertSame(0, x.last(), 'array push last');
|
||||||
assertSame(x.length, 4, 'length');
|
assertSame(4, x.length, 'length');
|
||||||
|
|
||||||
x = new kit.Collection({1: 1, 100: 100});
|
x = new kit.Collection({1: 1, 100: 100});
|
||||||
x.push(10);
|
x.push(10);
|
||||||
x.set('as', 13);
|
x.set('as', 13);
|
||||||
assertSame(x.length, 4, 'length');
|
assertSame(4, x.length, 'length');
|
||||||
x.forget('as');
|
x.forget('as');
|
||||||
assertSame(x.length, 3, 'length after forget');
|
assertSame(3, x.length, 'length after forget');
|
||||||
assertSame(x.get('as', 33), 33, 'get after forget');
|
assertSame(33, x.get('as', 33), 'get after forget');
|
||||||
|
|
||||||
xOb = {1: 10, 100: 101};
|
xOb = {1: 10, 100: 101};
|
||||||
x = new kit.Collection(xOb);
|
x = new kit.Collection(xOb);
|
||||||
assertSame(x.pull(100), 101, 'pull');
|
assertSame(101, x.pull(100), 'pull');
|
||||||
assertSame(x.length, 1, 'length after pull');
|
assertSame(1, x.length, 'length after pull');
|
||||||
|
|
||||||
xOb = {1: 10, 100: 101};
|
xOb = {1: 10, 100: 101};
|
||||||
x = new kit.Collection(xOb);
|
x = new kit.Collection(xOb);
|
||||||
assertSame(x.pop(), 101, 'pop');
|
assertSame(101, x.pop(), 'pop');
|
||||||
assertSame(x.length, 1, 'length after pop');
|
assertSame(1, x.length, 'length after pop');
|
||||||
|
|
||||||
xOb = {1: 10, 100: 101};
|
xOb = {1: 10, 100: 101};
|
||||||
x = new kit.Collection(xOb);
|
x = new kit.Collection(xOb);
|
||||||
assertSame(x.shift(), 10, 'shift');
|
assertSame(10, x.shift(), 'shift');
|
||||||
assertSame(x.length, 1, 'length after shift');
|
assertSame(1, x.length, 'length after shift');
|
||||||
|
|
||||||
xOb = {a: 'a10', b: 'b11'};
|
xOb = {a: 'a10', b: 'b11'};
|
||||||
x = new kit.Collection(xOb);
|
x = new kit.Collection(xOb);
|
||||||
x.set(1, 10);
|
x.set(1, 10);
|
||||||
assertSame(x.shift(), 'a10', 'shift +');
|
assertSame('a10', x.shift(), 'shift +');
|
||||||
assertSame(x.length, 2, 'length after shift');
|
assertSame(2, x.length, 'length after shift');
|
||||||
assertSame(x.last(), 10, 'last after shift');
|
assertSame(10, x.last(), 'last after shift');
|
||||||
|
|
||||||
xOb = {a: 'a10', b: 'b11'};
|
xOb = {a: 'a10', b: 'b11'};
|
||||||
x = new kit.Collection(xOb);
|
x = new kit.Collection(xOb);
|
||||||
x2 = x.map(function (value, key) {
|
x2 = x.map(function (value, key) {
|
||||||
return value + '!';
|
return value + '!';
|
||||||
});
|
});
|
||||||
assertSame(x2.get('a'), 'a10!', 'map object');
|
assertSame('a10!', x2.get('a'), 'map object');
|
||||||
|
|
||||||
|
|
||||||
xOb = [10, 20, 30];
|
xOb = [10, 20, 30];
|
||||||
@@ -190,36 +180,36 @@ kit.ready(['collection'], function () {
|
|||||||
x2 = x.map(function (value, key) {
|
x2 = x.map(function (value, key) {
|
||||||
return value * 2;
|
return value * 2;
|
||||||
});
|
});
|
||||||
assertSame(x2.last(), 60, 'map array');
|
assertSame(60, x2.last(), 'map array');
|
||||||
|
|
||||||
xOb = {a: 'a10', b: 'b11', 10: 101};
|
xOb = {a: 'a10', b: 'b11', 10: 101};
|
||||||
x = new kit.Collection(xOb);
|
x = new kit.Collection(xOb);
|
||||||
x.set(11, 111);
|
x.set(11, 111);
|
||||||
x2 = x.except([10]);
|
x2 = x.except([10]);
|
||||||
assertSame(x2.last(), 111, 'except last+');
|
assertSame(111, x2.last(), 'except last+');
|
||||||
assertSame(x2.length, 3, 'except length');
|
assertSame(3, x2.length, 'except length');
|
||||||
x3 = x2.except('11');
|
x3 = x2.except('11');
|
||||||
assertSame(x3.last(), 'b11', 'except last+');
|
assertSame('b11', x3.last(), 'except last+');
|
||||||
assertSame(x3.length, 2, 'except length');
|
assertSame(2, x3.length, 'except length');
|
||||||
|
|
||||||
|
|
||||||
xOb = {a: 'a10', b: 'b11', 10: 101};
|
xOb = {a: 'a10', b: 'b11', 10: 101};
|
||||||
x = new kit.Collection(xOb);
|
x = new kit.Collection(xOb);
|
||||||
x.set(11, 111);
|
x.set(11, 111);
|
||||||
x2 = x.only(['a', 'b', '11']);
|
x2 = x.only(['a', 'b', '11']);
|
||||||
assertSame(x2.last(), 111, 'only last+');
|
assertSame(111, x2.last(), 'only last+');
|
||||||
assertSame(x2.length, 3, 'only length');
|
assertSame(3, x2.length, 'only length');
|
||||||
x3 = x2.only('11');
|
x3 = x2.only('11');
|
||||||
assertSame(x3.last(), 111, 'only last+');
|
assertSame(111, x3.last(), 'only last+');
|
||||||
assertSame(x3.length, 1, 'only length');
|
assertSame(1, x3.length, 'only length');
|
||||||
|
|
||||||
|
|
||||||
xOb = {a: 'a10', b: 'b11', 10: 101};
|
xOb = {a: 'a10', b: 'b11', 10: 101};
|
||||||
x = new kit.Collection(xOb);
|
x = new kit.Collection(xOb);
|
||||||
x.set(11, 111);
|
x.set(11, 111);
|
||||||
assertSame(x.indexKey(11), 3, 'indexKey (int)');
|
assertSame(3, x.indexKey(11), 'indexKey (int)');
|
||||||
assertSame(x.indexKey('11'), 3, 'indexKey (string)');
|
assertSame(3, x.indexKey('11'), 'indexKey (string)');
|
||||||
assertSame(x.indexKey('111'), -1, 'indexKey (-1)');
|
assertSame(-1, x.indexKey('111'), 'indexKey (-1)');
|
||||||
|
|
||||||
xOb = [
|
xOb = [
|
||||||
{
|
{
|
||||||
@@ -237,9 +227,9 @@ kit.ready(['collection'], function () {
|
|||||||
];
|
];
|
||||||
x = new kit.Collection(xOb);
|
x = new kit.Collection(xOb);
|
||||||
y = x.pluck('name');
|
y = x.pluck('name');
|
||||||
assertSame(y.toArray().join('-'), 'Igor-Max-Nikita', 'pluck');
|
assertSame('Igor-Max-Nikita', y.toArray().join('-'), 'pluck');
|
||||||
y = x.pluck('age');
|
y = x.pluck('age');
|
||||||
assertSame(y.toArray().join('-'), '20-19-18', 'pluck с проверкой сохранения порядка');
|
assertSame('20-19-18', y.toArray().join('-'), 'pluck с проверкой сохранения порядка');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user