updated whenOperationExists
This commit is contained in:
parent
dcec0fe967
commit
b3e09d001f
@ -118,10 +118,11 @@ gulp.task("build_jasmine_browser", function(){
|
||||
.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, ["test"]);
|
||||
// gulp.watch(files.test, ["test"]);
|
||||
gulp.watch(files.test, ["build"]);
|
||||
|
||||
return gulp.src("build/jasmine_browser.js")
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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]);
|
||||
});
|
||||
|
@ -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 {
|
Loading…
x
Reference in New Issue
Block a user