late join should work now. Need to test more. root is passed to transaction generator
This commit is contained in:
parent
b25977be06
commit
f8ad9abcc0
@ -11,6 +11,7 @@
|
|||||||
},
|
},
|
||||||
"parser": "babel-eslint",
|
"parser": "babel-eslint",
|
||||||
"globals": {
|
"globals": {
|
||||||
|
"copyObject": true,
|
||||||
"Struct": true,
|
"Struct": true,
|
||||||
"OperationStore": true,
|
"OperationStore": true,
|
||||||
"AbstractOperationStore": true,
|
"AbstractOperationStore": true,
|
||||||
|
@ -4,6 +4,15 @@ type State = {
|
|||||||
clock: number
|
clock: number
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
function copyObject (o) {
|
||||||
|
var c = {};
|
||||||
|
for (var key in o) {
|
||||||
|
c[key] = o[key];
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
type StateVector = Array<State>;
|
type StateVector = Array<State>;
|
||||||
type OperationSet = Object; // os[Id] = op
|
type OperationSet = Object; // os[Id] = op
|
||||||
type StateSet = Object;
|
type StateSet = Object;
|
||||||
@ -75,12 +84,30 @@ Y.Memory = (function(){ //eslint-disable-line no-unused-vars
|
|||||||
for (var clock = startPos; clock <= endPos; clock++) {
|
for (var clock = startPos; clock <= endPos; clock++) {
|
||||||
var op = yield* this.getOperation([user, clock]);
|
var op = yield* this.getOperation([user, clock]);
|
||||||
if (op != null) {
|
if (op != null) {
|
||||||
ops.push(op);
|
ops.push(yield* this.makeOperationReady.call(this, startSS, op));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ops;
|
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
|
class OperationStore extends AbstractOperationStore { //eslint-disable-line no-undef
|
||||||
constructor (y) {
|
constructor (y) {
|
||||||
@ -90,7 +117,7 @@ Y.Memory = (function(){ //eslint-disable-line no-unused-vars
|
|||||||
}
|
}
|
||||||
requestTransaction (makeGen : Function) {
|
requestTransaction (makeGen : Function) {
|
||||||
var t = new Transaction(this);
|
var t = new Transaction(this);
|
||||||
var gen = makeGen.call(t);
|
var gen = makeGen.call(t, new Y.Map.Create(["_", 0]));
|
||||||
var res = gen.next();
|
var res = gen.next();
|
||||||
while(!res.done){
|
while(!res.done){
|
||||||
if (res.value === "transaction") {
|
if (res.value === "transaction") {
|
||||||
|
3
src/y.js
3
src/y.js
@ -6,14 +6,13 @@ class Y { //eslint-disable-line no-unused-vars
|
|||||||
constructor (opts) {
|
constructor (opts) {
|
||||||
this.db = new Y[opts.db.name](this, opts.db);
|
this.db = new Y[opts.db.name](this, opts.db);
|
||||||
this.connector = new Y[opts.connector.name](this, opts.connector);
|
this.connector = new Y[opts.connector.name](this, opts.connector);
|
||||||
var y = this;
|
|
||||||
this.db.requestTransaction(function*(){
|
this.db.requestTransaction(function*(){
|
||||||
|
// create initial Map type
|
||||||
yield* this.addOperation({
|
yield* this.addOperation({
|
||||||
id: ["_", 0],
|
id: ["_", 0],
|
||||||
struct: "Map",
|
struct: "Map",
|
||||||
map: {}
|
map: {}
|
||||||
});
|
});
|
||||||
y.root = new Y.Map.Create(["_", 0]);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
transact (generator) {
|
transact (generator) {
|
||||||
|
@ -23,52 +23,45 @@ describe("Yjs (basic)", function(){
|
|||||||
}
|
}
|
||||||
this.users = [];
|
this.users = [];
|
||||||
});
|
});
|
||||||
it("There is an initial Map type", function(done){
|
it("There is an initial Map type", function(){
|
||||||
var y = this.users[0];
|
var y = this.users[0];
|
||||||
y.transact(function*(){
|
y.transact(function*(root){
|
||||||
expect(y.root).not.toBeUndefined();
|
expect(root).not.toBeUndefined();
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
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];
|
var y = this.users[0];
|
||||||
y.transact(function*(){
|
y.transact(function*(root){
|
||||||
yield* y.root.val("stuff", "stuffy");
|
yield* root.val("stuff", "stuffy");
|
||||||
expect(yield* y.root.val("stuff")).toEqual("stuffy");
|
expect(yield* root.val("stuff")).toEqual("stuffy");
|
||||||
});
|
});
|
||||||
|
|
||||||
y.connector.flushAll();
|
y.connector.flushAll();
|
||||||
|
|
||||||
function getTransaction(yy){
|
var transaction = function*(root){
|
||||||
return function*(){
|
expect(yield* root.val("stuff")).toEqual("stuffy");
|
||||||
expect(yield* yy.root.val("stuff")).toEqual("stuffy");
|
|
||||||
};
|
};
|
||||||
}
|
|
||||||
for (var key in this.users) {
|
for (var key in this.users) {
|
||||||
var u = this.users[key];
|
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];
|
var y = this.users[0];
|
||||||
y.connector.flushAll();
|
y.connector.flushAll();
|
||||||
y.transact(function*(){
|
y.transact(function*(root){
|
||||||
yield* y.root.val("stuff", "stuffy");
|
yield* root.val("stuff", "stuffy");
|
||||||
expect(yield* y.root.val("stuff")).toEqual("stuffy");
|
expect(yield* root.val("stuff")).toEqual("stuffy");
|
||||||
});
|
});
|
||||||
|
|
||||||
function getTransaction(yy){
|
var transaction = function*(root){
|
||||||
return function*(){
|
expect(yield* root.val("stuff")).toEqual("stuffy");
|
||||||
expect(yield* yy.root.val("stuff")).toEqual("stuffy");
|
|
||||||
};
|
};
|
||||||
}
|
|
||||||
y.connector.flushAll();
|
y.connector.flushAll();
|
||||||
|
|
||||||
for (var key in this.users) {
|
for (var key in this.users) {
|
||||||
var u = this.users[key];
|
var u = this.users[key];
|
||||||
u.transact(getTransaction(u));
|
u.transact(transaction);
|
||||||
}
|
}
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user