more arrow-function refactorings in lists.js

pull/95/head
jmoenig 2020-04-26 18:09:09 +02:00
rodzic 5f9a60559e
commit d3d5634eae
1 zmienionych plików z 15 dodań i 20 usunięć

Wyświetl plik

@ -242,9 +242,7 @@ List.prototype.contains = function (element) {
pair = pair.rest; pair = pair.rest;
} }
// in case I'm arrayed // in case I'm arrayed
return pair.contents.some(function (any) { return pair.contents.some(any => snapEquals(any, element));
return snapEquals(any, element);
});
}; };
List.prototype.isEmpty = function () { List.prototype.isEmpty = function () {
@ -455,7 +453,7 @@ List.prototype.asCSV = function () {
return string; return string;
} }
cell = ['\"']; cell = ['\"'];
string.split('').forEach(function (letter) { string.split('').forEach(letter => {
cell.push(letter); cell.push(letter);
if (letter === '\"') { if (letter === '\"') {
cell.push(letter); cell.push(letter);
@ -465,9 +463,9 @@ List.prototype.asCSV = function () {
return cell.join(''); return cell.join('');
} }
if (items.some(function (any) {return any instanceof List; })) { if (items.some(any => any instanceof List)) {
// 2-dimensional table // 2-dimensional table
items.forEach(function (item) { items.forEach(item => {
if (item instanceof List) { if (item instanceof List) {
rows.push(item.itemsArray().map(encodeCell).join(',')); rows.push(item.itemsArray().map(encodeCell).join(','));
} else { } else {
@ -488,14 +486,14 @@ List.prototype.asJSON = function (guessObjects) {
var items = list.itemsArray(), var items = list.itemsArray(),
obj = {}; obj = {};
if (canBeObject(items)) { if (canBeObject(items)) {
items.forEach(function (pair) { items.forEach(pair => {
var value = pair.length() === 2 ? pair.at(2) : undefined; var value = pair.length() === 2 ? pair.at(2) : undefined;
obj[pair.at(1)] = (value instanceof List ? obj[pair.at(1)] = (value instanceof List ?
objectify(value, guessObjects) : value); objectify(value, guessObjects) : value);
}); });
return obj; return obj;
} }
return items.map(function (element) { return items.map(element => {
return element instanceof List ? return element instanceof List ?
objectify(element, guessObjects) : element; objectify(element, guessObjects) : element;
}); });
@ -506,14 +504,11 @@ List.prototype.asJSON = function (guessObjects) {
// might be better represented as dictionary/object // might be better represented as dictionary/object
// than as array // than as array
var keys; var keys;
if (array.every(function (element) { if (array.every(
return element instanceof List && (element.length() < 3); element => element instanceof List && (element.length() < 3)
})) { )) {
keys = array.map(function (each) {return each.at(1); }); keys = array.map(each => each.at(1));
return keys.every(function (each) { return keys.every(each => isString(each) && isUniqueIn(each, keys));
return isString(each) &&
isUniqueIn(each, keys);
});
} }
} }
@ -573,7 +568,7 @@ List.prototype.equalTo = function (other) {
}; };
List.prototype.canBeCSV = function () { List.prototype.canBeCSV = function () {
return this.itemsArray().every(function (value) { return this.itemsArray().every(value => {
return (!isNaN(+value) && typeof value !== 'boolean') || return (!isNaN(+value) && typeof value !== 'boolean') ||
isString(value) || isString(value) ||
(value instanceof List && value.hasOnlyAtomicData()); (value instanceof List && value.hasOnlyAtomicData());
@ -581,7 +576,7 @@ List.prototype.canBeCSV = function () {
}; };
List.prototype.canBeJSON = function () { List.prototype.canBeJSON = function () {
return this.itemsArray().every(function (value) { return this.itemsArray().every(value => {
return !isNaN(+value) || return !isNaN(+value) ||
isString(value) || isString(value) ||
value === true || value === true ||
@ -591,7 +586,7 @@ List.prototype.canBeJSON = function () {
}; };
List.prototype.hasOnlyAtomicData = function () { List.prototype.hasOnlyAtomicData = function () {
return this.itemsArray().every(function (value) { return this.itemsArray().every(value => {
return (!isNaN(+value) && typeof value !== 'boolean') || return (!isNaN(+value) && typeof value !== 'boolean') ||
isString(value); isString(value);
}); });
@ -712,7 +707,7 @@ ListWatcherMorph.prototype.init = function (list, parentCell) {
ListWatcherMorph.prototype.update = function (anyway) { ListWatcherMorph.prototype.update = function (anyway) {
var i, idx, ceil, morphs, cell, cnts, label, button, max, var i, idx, ceil, morphs, cell, cnts, label, button, max,
starttime, maxtime = 1000; starttime, maxtime = 1000;
this.frame.contents.children.forEach(function (m) { this.frame.contents.children.forEach(m => {
if (m instanceof CellMorph) { if (m instanceof CellMorph) {
if (m.contentsMorph instanceof ListWatcherMorph) { if (m.contentsMorph instanceof ListWatcherMorph) {
m.contentsMorph.update(); m.contentsMorph.update();