Skip to content
Snippets Groups Projects
Commit f8ad9abc authored by Kevin Jahns's avatar Kevin Jahns
Browse files

late join should work now. Need to test more. root is passed to transaction generator

parent b25977be
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@
},
"parser": "babel-eslint",
"globals": {
"copyObject": true,
"Struct": true,
"OperationStore": true,
"AbstractOperationStore": true,
......
......@@ -4,6 +4,15 @@ type State = {
clock: number
};
function copyObject (o) {
var c = {};
for (var key in o) {
c[key] = o[key];
}
return c;
}
type StateVector = Array<State>;
type OperationSet = Object; // os[Id] = op
type StateSet = Object;
......@@ -75,12 +84,30 @@ Y.Memory = (function(){ //eslint-disable-line no-unused-vars
for (var clock = startPos; clock <= endPos; clock++) {
var op = yield* this.getOperation([user, clock]);
if (op != null) {
ops.push(op);
ops.push(yield* this.makeOperationReady.call(this, startSS, op));
}
}
}
return ops;
}
*makeOperationReady (ss, op) {
var clock;
var o = op;
while (true){
// while unknown, go to the right
o = yield* this.getOperation(o.right);
if (o == null) {
break;
}
clock = ss[o.id[0]];
if (clock != null && o.id[1] < clock ) {
break;
}
}
op = copyObject(op);
op.right = (o == null) ? null : o.id;
return op;
}
}
class OperationStore extends AbstractOperationStore { //eslint-disable-line no-undef
constructor (y) {
......@@ -90,7 +117,7 @@ Y.Memory = (function(){ //eslint-disable-line no-unused-vars
}
requestTransaction (makeGen : Function) {
var t = new Transaction(this);
var gen = makeGen.call(t);
var gen = makeGen.call(t, new Y.Map.Create(["_", 0]));
var res = gen.next();
while(!res.done){
if (res.value === "transaction") {
......
......@@ -6,14 +6,13 @@ class Y { //eslint-disable-line no-unused-vars
constructor (opts) {
this.db = new Y[opts.db.name](this, opts.db);
this.connector = new Y[opts.connector.name](this, opts.connector);
var y = this;
this.db.requestTransaction(function*(){
// create initial Map type
yield* this.addOperation({
id: ["_", 0],
struct: "Map",
map: {}
});
y.root = new Y.Map.Create(["_", 0]);
});
}
transact (generator) {
......
......@@ -23,52 +23,45 @@ describe("Yjs (basic)", function(){
}
this.users = [];
});
it("There is an initial Map type", function(done){
it("There is an initial Map type", function(){
var y = this.users[0];
y.transact(function*(){
expect(y.root).not.toBeUndefined();
done();
y.transact(function*(root){
expect(root).not.toBeUndefined();
});
});
it("Basic get&set of Map property (converge via sync)", function(done){
it("Basic get&set of Map property (converge via sync)", function(){
var y = this.users[0];
y.transact(function*(){
yield* y.root.val("stuff", "stuffy");
expect(yield* y.root.val("stuff")).toEqual("stuffy");
y.transact(function*(root){
yield* root.val("stuff", "stuffy");
expect(yield* root.val("stuff")).toEqual("stuffy");
});
y.connector.flushAll();
function getTransaction(yy){
return function*(){
expect(yield* yy.root.val("stuff")).toEqual("stuffy");
};
}
var transaction = function*(root){
expect(yield* root.val("stuff")).toEqual("stuffy");
};
for (var key in this.users) {
var u = this.users[key];
u.transact(getTransaction(u));
u.transact(transaction);
}
done();
});
it("Basic get&set of Map property (converge via update)", function(done){
it("Basic get&set of Map property (converge via update)", function(){
var y = this.users[0];
y.connector.flushAll();
y.transact(function*(){
yield* y.root.val("stuff", "stuffy");
expect(yield* y.root.val("stuff")).toEqual("stuffy");
y.transact(function*(root){
yield* root.val("stuff", "stuffy");
expect(yield* root.val("stuff")).toEqual("stuffy");
});
function getTransaction(yy){
return function*(){
expect(yield* yy.root.val("stuff")).toEqual("stuffy");
};
}
var transaction = function*(root){
expect(yield* root.val("stuff")).toEqual("stuffy");
};
y.connector.flushAll();
for (var key in this.users) {
var u = this.users[key];
u.transact(getTransaction(u));
u.transact(transaction);
}
done();
});
});
This diff is collapsed.
Source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment