remove Ox.Break
This commit is contained in:
parent
4139e171ca
commit
bda90f6b6b
44 changed files with 152 additions and 165 deletions
|
|
@ -381,7 +381,7 @@ Ox.api = function(items, options) {
|
|||
(query.operator == '&' && !match)
|
||||
|| (query.operator == '|' && match)
|
||||
) {
|
||||
Ox.Break();
|
||||
return false; // break
|
||||
}
|
||||
});
|
||||
return match;
|
||||
|
|
@ -604,7 +604,7 @@ Ox.range = function() {
|
|||
length = article.length;
|
||||
sort[value] = sort[value].slice(length + 1) + ', '
|
||||
+ sort[value].slice(0, length);
|
||||
Ox.Break();
|
||||
return false; // break
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -60,17 +60,17 @@
|
|||
function iterate() {
|
||||
Ox.forEach(keys.slice(i), function(key) {
|
||||
if (key in collection) {
|
||||
try {
|
||||
iterator.call(that, collection[key], key, collection);
|
||||
} catch (error) {
|
||||
if (error === Ox.BreakError) {
|
||||
i = n;
|
||||
}
|
||||
throw error;
|
||||
if (iterator.call(
|
||||
that, collection[key], key, collection
|
||||
) === false) {
|
||||
i = n;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
+new Date() >= time + ms && Ox.Break();
|
||||
if (+new Date() >= time + ms) {
|
||||
return false; // break
|
||||
}
|
||||
});
|
||||
if (i < n) {
|
||||
setTimeout(function() {
|
||||
|
|
|
|||
|
|
@ -148,10 +148,9 @@ Ox.filter = function(collection, iterator, that) {
|
|||
|
||||
/*@
|
||||
Ox.forEach <f> forEach loop
|
||||
`Ox.forEach` loops over arrays, objects and strings. Calling `Ox.Break`
|
||||
inside the iterator or returning `false` from the iterator acts like a
|
||||
`break` statement. Unlike `Array.prototype.forEach`, which leaks its counter
|
||||
variable to the outer scope, `Ox.forEach` returns it.
|
||||
`Ox.forEach` loops over arrays, objects and strings. Returning `false` from
|
||||
the iterator acts like a `break` statement. Unlike `for`, which leaks its
|
||||
counter variable to the outer scope, `Ox.forEach` returns it.
|
||||
(collection, iterator[, that]) -> <n> Next index
|
||||
collection <a|o|s> Collection
|
||||
iterator <f> Iterator
|
||||
|
|
@ -172,33 +171,23 @@ Ox.forEach <f> forEach loop
|
|||
@*/
|
||||
Ox.forEach = function(collection, iterator, that) {
|
||||
var i = 0, key, type = Ox.typeOf(collection);
|
||||
try {
|
||||
if (type == 'object' || type == 'storage') {
|
||||
for (key in collection) {
|
||||
if (Ox.hasOwn(collection, key)) {
|
||||
// iterator.call(that, collection[key], key, collection);
|
||||
if (iterator.call(that, collection[key], key, collection) === false) {
|
||||
// console.warn('Returning false in Ox.forEach is deprecated.');
|
||||
break;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
collection = Ox.toArray(collection);
|
||||
for (i = 0; i < collection.length; i++) {
|
||||
if (i in collection) {
|
||||
// iterator.call(that, collection[i], i, collection);
|
||||
if (iterator.call(that, collection[i], i, collection) === false) {
|
||||
// console.warn('Returning false in Ox.forEach is deprecated.');
|
||||
break;
|
||||
}
|
||||
if (type == 'object' || type == 'storage') {
|
||||
for (key in collection) {
|
||||
if (Ox.hasOwn(collection, key)) {
|
||||
if (iterator.call(that, collection[key], key, collection) === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
} catch (error) {
|
||||
if (error !== Ox.BreakError) {
|
||||
throw error;
|
||||
} else {
|
||||
collection = Ox.toArray(collection);
|
||||
for (i = 0; i < collection.length; i++) {
|
||||
if (i in collection) {
|
||||
if (iterator.call(that, collection[i], i, collection) === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return i;
|
||||
|
|
@ -217,7 +206,7 @@ Ox.indexOf <f> Returns the first index of a collection element that passes a tes
|
|||
@*/
|
||||
Ox.indexOf = function(collection, test) {
|
||||
var index = Ox.forEach(collection, function(value) {
|
||||
test(value) && Ox.Break();
|
||||
return !test(value); // break if test succeeds
|
||||
});
|
||||
return Ox.isObject(collection) ? Object.keys(collection)[index] || null
|
||||
: index == collection.length ? -1 : index;
|
||||
|
|
|
|||
|
|
@ -84,15 +84,6 @@ this.Ox = function(value) {
|
|||
return Ox.wrap(value);
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.Break <f> Breaks from `Ox.forEach` and `Ox.loop`
|
||||
@*/
|
||||
Ox.Break = function() {
|
||||
throw Ox.BreakError;
|
||||
};
|
||||
|
||||
Ox.BreakError = new SyntaxError('Illegal Ox.Break() statement');
|
||||
|
||||
/*@
|
||||
Ox.load <f> Loads one or more modules
|
||||
A module named "Foo" provides `Ox.Foo/Ox.Foo.js`, in which it defines one
|
||||
|
|
@ -283,7 +274,7 @@ Ox.loop <f> For-loop, functional-style
|
|||
step <n> Step value
|
||||
fn <f> Iterator function
|
||||
i <n> Counter value
|
||||
> Ox.loop(10, function(i) { i == 4 && Ox.Break(); })
|
||||
> Ox.loop(10, function(i) { if (i == 4) { return false; } })
|
||||
4
|
||||
> Ox.loop(0, 3, 2, function() {})
|
||||
4
|
||||
|
|
@ -295,17 +286,9 @@ Ox.loop = function() {
|
|||
step = length == 4 ? arguments[2] : (start <= stop ? 1 : -1),
|
||||
iterator = arguments[length - 1],
|
||||
i;
|
||||
try {
|
||||
for (i = start; step > 0 ? i < stop : i > stop; i += step) {
|
||||
// iterator(i);
|
||||
if (iterator(i) === false) {
|
||||
// console.warn('Returning false in Ox.loop is deprecated.');
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
if (error !== Ox.BreakError) {
|
||||
throw error;
|
||||
for (i = start; step > 0 ? i < stop : i > stop; i += step) {
|
||||
if (iterator(i) === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
|
|
|
|||
|
|
@ -359,13 +359,13 @@ Ox.formatDateRange = function(start, end, utc) {
|
|||
if (precision[0] == precision[1]) {
|
||||
isOneUnit = true;
|
||||
Ox.loop(precision[0], function(i) {
|
||||
if (i < precision[0] - 1 && parts[0][i] != parts[1][i]) {
|
||||
if (
|
||||
(i < precision[0] - 1 && parts[0][i] != parts[1][i])
|
||||
|| (i == precision[0] - 1 && parts[0][i] != parts[1][i] - 1)
|
||||
) {
|
||||
isOneUnit = false;
|
||||
return false; // break
|
||||
}
|
||||
if (i == precision[0] - 1 && parts[0][i] != parts[1][i] - 1) {
|
||||
isOneUnit = false;
|
||||
}
|
||||
!isOneUnit && Ox.Break();
|
||||
});
|
||||
}
|
||||
if (isOneUnit) {
|
||||
|
|
@ -706,7 +706,7 @@ Ox.formatValue = function(number, string, bin) {
|
|||
ret = Ox.formatNumber(
|
||||
number / Math.pow(base, index), index ? index - 1 : 0
|
||||
) + ' ' + prefix + (prefix && bin ? 'i' : '') + string;
|
||||
Ox.Break();
|
||||
return false; // break
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -252,8 +252,7 @@
|
|||
// If an area crosses the dateline,
|
||||
// we split it into two parts,
|
||||
// west and east of the dateline
|
||||
var areas = [areaA, areaB].map(splitArea),
|
||||
ret;
|
||||
var areas = [areaA, areaB].map(splitArea), ret;
|
||||
function contains(areaA, areaB) {
|
||||
return areaA.sw.lat <= areaB.sw.lat
|
||||
&& areaA.sw.lng <= areaB.sw.lng
|
||||
|
|
@ -266,10 +265,10 @@
|
|||
Ox.forEach(areas[0], function(area0) {
|
||||
ret = contains(area0, area1);
|
||||
// Break if the outer part contains the inner part
|
||||
ret && Ox.Break();
|
||||
return !ret;
|
||||
});
|
||||
// Break if no outer part contains the inner part
|
||||
!ret && Ox.Break();
|
||||
return ret;
|
||||
});
|
||||
return ret;
|
||||
};
|
||||
|
|
@ -327,7 +326,7 @@
|
|||
: Ox.joinAreas(intersections);
|
||||
}
|
||||
if (ret === null) {
|
||||
Ox.Break();
|
||||
return false; // break
|
||||
} else {
|
||||
ret = splitArea(ret);
|
||||
}
|
||||
|
|
@ -378,7 +377,7 @@
|
|||
Ox.forEach(gaps, function(gap, i) {
|
||||
if (Ox.containsArea(gap, area)) {
|
||||
ret = i;
|
||||
Ox.Break();
|
||||
return false; // break
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ Ox.doc = (function() {
|
|||
Ox.forEach(item.returns, function(v) {
|
||||
if (v['class']) {
|
||||
constructors.push(item);
|
||||
Ox.Break();
|
||||
return false; // break
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -654,7 +654,7 @@ Ox.identify = (function() {
|
|||
Ox.forEach(identifiers, function(words, type) {
|
||||
if (words.indexOf(identifier) > -1) {
|
||||
ret = type;
|
||||
Ox.Break();
|
||||
return false; // break
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -874,7 +874,7 @@ Ox.test = function(argument, callback) {
|
|||
if (v.tests[statement]) {
|
||||
id = k;
|
||||
test = v.tests[statement];
|
||||
Ox.Break();
|
||||
return false; // break
|
||||
}
|
||||
});
|
||||
Ox.test.data[id].results.push(Ox.extend(test, {
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ Ox.keyOf = function(object, value) {
|
|||
Ox.forEach(object, function(v, k) {
|
||||
if (v === value) {
|
||||
key = k;
|
||||
Ox.Break();
|
||||
return false; // break
|
||||
}
|
||||
});
|
||||
return key;
|
||||
|
|
|
|||
|
|
@ -358,7 +358,7 @@ Ox.parseUserAgent = function(userAgent) {
|
|||
string: string,
|
||||
version: versions[version] || version
|
||||
};
|
||||
Ox.Break();
|
||||
return false; // break
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ Ox.isEqual = function(a, b) {
|
|||
ret = true;
|
||||
Ox.forEach(a, function(value, key) {
|
||||
ret = Ox.isEqual(value, b[key]);
|
||||
!ret && Ox.Break();
|
||||
return ret; // break if not equal
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue