list and map types work now and they support delete. added random tests

This commit is contained in:
Kevin Jahns
2015-07-09 01:30:57 +02:00
parent a1026bc365
commit 0493d99d57
6 changed files with 188 additions and 19 deletions

View File

@@ -16,9 +16,22 @@
}
}
*insert (pos, contents) {
if (typeof pos !== "number") {
throw new Error("pos must be a number!");
}
if (!(contents instanceof Array)) {
throw new Error("contents must be an Array of objects!");
}
var t = yield "transaction";
yield* Y.Struct.List.insert.call(t, this._model, pos, contents);
}
*delete (pos) {
if (typeof pos !== "number") {
throw new Error("pos must be a number!");
}
var t = yield "transaction";
yield* Y.Struct.List.delete.call(t, this._model, pos);
}
}
Y.List = function* YList(){

View File

@@ -7,7 +7,16 @@
*val () {
var t = yield "transaction";
var model = yield* t.getOperation(this._model);
if (arguments.length === 1) {
if (arguments.length === 0) {
var res = {};
for (var key in model.map) {
var v = yield* Y.Struct.Map.get.call(t, model, key);
if (v != null) {
res[key] = v;
}
}
return res;
} else if (arguments.length === 1) {
return yield* Y.Struct.Map.get.call(t, model, arguments[0]);
} else if (arguments.length === 2) {
return yield* Y.Struct.Map.set.call(t, model, arguments[0], arguments[1]);
@@ -15,6 +24,11 @@
throw new Error("Implement this case!");
}
}
*delete (key) {
var t = yield "transaction";
var model = yield* t.getOperation(this._model);
yield* Y.Struct.Map.delete.call(t, model, key);
}
}
Y.Map = function* YMap(){