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

@ -118,10 +118,11 @@ gulp.task("build_jasmine_browser", function(){
.pipe(gulp.dest("build")); .pipe(gulp.dest("build"));
}); });
gulp.task("develop", ["build_jasmine_browser", "test", "build"], function(){
gulp.task("develop", ["build_jasmine_browser", "build"], function(){
gulp.watch(files.test, ["build_jasmine_browser"]); gulp.watch(files.test, ["build_jasmine_browser"]);
gulp.watch(files.test, ["test"]); // gulp.watch(files.test, ["test"]);
gulp.watch(files.test, ["build"]); gulp.watch(files.test, ["build"]);
return gulp.src("build/jasmine_browser.js") return gulp.src("build/jasmine_browser.js")

View File

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

View File

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

View File

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

2
y.js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long