remove experimental list methods for object-use

upd4.1
Jens Mönig 2017-02-14 13:39:44 +01:00
rodzic 3f23cc9fce
commit 176936a211
2 zmienionych plików z 5 dodań i 63 usunięć

Wyświetl plik

@ -3367,3 +3367,7 @@ Fixes:
170209
------
* Blocks: fixed #1406
170214
------
* Lists: remove experimental methods for object-use

Wyświetl plik

@ -62,7 +62,7 @@ CellMorph, ArrowMorph, MenuMorph, snapEquals, Morph, isNil, localize,
MorphicPreferences, TableDialogMorph, SpriteBubbleMorph, SpeechBubbleMorph,
TableFrameMorph, TableMorph, Variable, isSnapObject*/
modules.lists = '2017-January-31';
modules.lists = '2017-February-14';
var List;
var ListWatcherMorph;
@ -314,68 +314,6 @@ List.prototype.version = function (startRow, rows) {
return v;
};
// List object use (hierarchical dictionary)
// *very* experimental and ineffective as hell
// don't rely on any of this to stay around, -Jens
function snapObject(parent) {
return new List([new List(['__proto__', parent])]);
}
List.prototype.setAttribute = function (key, value) {
var assoc = this.assoc(key);
if (assoc) {
assoc.put(value, 2);
this.changed();
} else {
this.add(new List([key, value]));
}
};
List.prototype.getAttribute = function (key) {
var assoc = this.assoc(key),
proto;
if (assoc) {
return assoc.at(2);
}
proto = this.getAttribute('__proto__');
if (proto) {
return proto.getAttribute(key);
}
throw new Error('unknown attribute: ' + key.toString());
};
List.prototype.removeAttribute = function (key) {
var i, assoc;
for (i = 1; i <= this.length(); i += 1) {
assoc = this.at(i);
if (snapEquals(assoc.at(1), key)) {
this.remove(i);
return;
}
}
};
List.prototype.attributes = function () {
var i, arr = [];
for (i = 1; i <= this.length(); i += 1) {
arr.push(this.at(i).at(1));
}
return new List(arr);
};
List.prototype.assoc = function (key) {
// private
var i, assoc;
for (i = 1; i <= this.length(); i += 1) {
assoc = this.at(i);
if (snapEquals(assoc.at(1), key)) {
return assoc;
}
}
return null;
};
// List conversion:
List.prototype.asArray = function () {