updated whenOperationExists

This commit is contained in:
Kevin Jahns
2015-06-21 03:50:58 +02:00
parent dcec0fe967
commit b3e09d001f
7 changed files with 31 additions and 15 deletions

View File

@@ -79,14 +79,18 @@ class AbstractOperationStore { //eslint-disable-line no-unused-vars
var store = this;
this.requestTransaction(function*(){
var exe = store.listenersByIdExecuteNow;
var exeNow = store.listenersByIdExecuteNow;
store.listenersByIdExecuteNow = [];
for (let listener of exe) {
yield* listener.f.apply(this, listener.args);
}
var ls = store.listenersById;
store.listenersById = {};
store.listenersByIdRequestPending = false;
for (let listener of exeNow) {
yield* listener.f.apply(this, listener.args);
}
for (var sid in ls){
var l = ls[sid];
var id = JSON.parse(sid);
@@ -100,17 +104,17 @@ class AbstractOperationStore { //eslint-disable-line no-unused-vars
}
}
}
store.listenersByIdRequestPending = false;
});
}
// called by a transaction when an operation is added
operationAdded (op) {
var l = this.listenersById[op.id];
for (var listener of l){
if (--listener.missing === 0){
this.whenOperationsExist([], listener.f, listener.args);
if (l != null) {
for (var listener of l){
if (--listener.missing === 0){
this.whenOperationsExist([], listener.f, listener.args);
}
}
}
}

View File

@@ -2,9 +2,17 @@
/*eslint-env browser,jasmine,console */
describe("OperationStore", function() {
class OperationStore extends AbstractOperationStore {
constructor (){
super();
}
requestTransaction (makeGen) {
var gen = makeGen.apply();
var gen = makeGen.apply({
getOperation: function*(){
return true;
}
});
function handle(res : any){
if (res.done){
@@ -22,18 +30,20 @@ describe("OperationStore", function() {
it("calls when operation added", function(done) {
var id = ["u1", 1];
os.whenOperationsExist([id], function*(){
expect(true).toEqual(true);
done();
});
os.operationAdded({id: id});
});
it("calls when no requirements", function(done) {
os.whenOperationsExist([], function*(){
expect(true).toEqual(true);
done();
});
});
it("calls when no requirements with arguments", function(done) {
os.whenOperationsExist([], function*(arg){
expect(arg).toBeTrue();
expect(arg).toBeTruthy();
done();
}, [true]);
});

View File

@@ -48,6 +48,7 @@ var IndexedDB = (function(){ //eslint-disable-line no-unused-vars
return op;
}
*removeOperation (id) {
this.buffer[JSON.stringify(id)] = null;
return yield this.os.delete(id);
}
*setState (state : State) : State {