From b9e21665e2ec79ec86e27e6cfdcf647a8b3f30c8 Mon Sep 17 00:00:00 2001
From: Kevin Jahns <kevin.jahns@rwth-aachen.de>
Date: Wed, 9 Sep 2015 20:29:39 +0200
Subject: [PATCH] update

---
 gulpfile.js             | 12 +++++++-----
 src/Helper.spec.js      |  4 +++-
 src/OperationStore.js   |  8 ++++++--
 src/Struct.js           | 14 ++++++--------
 src/Types/Array.spec.js |  7 +++++--
 src/y.js                |  2 +-
 6 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/gulpfile.js b/gulpfile.js
index 3f8e5c6d..e8dd0d39 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -49,6 +49,7 @@ var jasmine = require('gulp-jasmine')
 var jasmineBrowser = require('gulp-jasmine-browser')
 var concat = require('gulp-concat')
 var watch = require('gulp-watch')
+var ignore = require('gulp-ignore')
 
 var polyfills = [
   './node_modules/gulp-babel/node_modules/babel-core/node_modules/regenerator/runtime.js'
@@ -95,7 +96,7 @@ gulp.task('build', function () {
       blacklist: ['regenerator'],
       experimental: true
     }))
-    .pipe(sourcemaps.write())
+    .pipe(sourcemaps.write('.'))
     .pipe(gulp.dest('.'))
 })
 
@@ -110,8 +111,9 @@ gulp.task('test', function () {
       experimental: true
     }))
     .pipe(uglify())
-    .pipe(sourcemaps.write())
+    .pipe(sourcemaps.write('.'))
     .pipe(gulp.dest('build'))
+    .pipe(ignore.include('*.js'))
     .pipe(jasmine({
       verbose: true,
       includeStuckTrace: true
@@ -125,9 +127,9 @@ gulp.task('build_jasmine_browser', function () {
     .pipe(babel({
       loose: 'all',
       modules: 'ignore',
-      optional: ['es7.asyncFunctions'],
-      // blacklist: "regenerator",
-      experimental: true
+      // optional: ['es7.asyncFunctions'],
+      blacklist: "regenerator",
+      //experimental: true
     }))
     .pipe(sourcemaps.write())
     .pipe(gulp.dest('build'))
diff --git a/src/Helper.spec.js b/src/Helper.spec.js
index fd86706c..79420395 100644
--- a/src/Helper.spec.js
+++ b/src/Helper.spec.js
@@ -5,7 +5,7 @@
   This is just a compilation of functions that help to test this library!
 ***/
 
-function wait(t = 0) {//eslint-disable-line
+function wait(t = 10) {//eslint-disable-line
   var def = Promise.defer()
   setTimeout(function () {
     def.resolve()
@@ -90,6 +90,8 @@ async function compareAllUsers(users){//eslint-disable-line
   await users[0].connector.flushAll()
   await garbageCollectAllUsers(users)
   await wait(200)
+  await garbageCollectAllUsers(users)
+  await wait(200)
   for (var uid = 0; uid < users.length; uid++) {
     var u = users[uid]
     // compare deleted ops against deleteStore
diff --git a/src/OperationStore.js b/src/OperationStore.js
index 11bd32aa..5e20e828 100644
--- a/src/OperationStore.js
+++ b/src/OperationStore.js
@@ -209,12 +209,16 @@ class AbstractOperationStore { // eslint-disable-line no-unused-vars
           state.clock++
           yield* this.checkDeleteStoreForState(state)
           yield* this.setState(state)
+          var isDeleted = yield* this.store.ds.isDeleted(op.id)
+
           yield* Struct[op.struct].execute.call(this, op)
           yield* this.addOperation(op)
           yield* this.store.operationAdded(this, op)
-          if (op.deleted === true) {
-            this.ds.delete(op.id)
+
+          if (isDeleted) {
+            yield* Struct["Delete"].execute.call(this, {target: op.id})
           }
+
           // find next operation to execute
           op = this.store.waitingOperations.find([op.id[0], state.clock])
           if (op != null) {
diff --git a/src/Struct.js b/src/Struct.js
index 204ceb9c..d509a65a 100644
--- a/src/Struct.js
+++ b/src/Struct.js
@@ -28,7 +28,7 @@ var Struct = {
       return [] // [op.target]
     },
     execute: function * (op) {
-      console.log('Delete', op, console.trace())
+      // console.log('Delete', op, console.trace())
       var target = yield* this.getOperation(op.target)
       if (target != null && !target.deleted) {
         target.deleted = true
@@ -50,13 +50,11 @@ var Struct = {
           yield* t._changed(this, copyObject(op))
         }
       }
-      if (target == null || !target.deleted) {
-        this.ds.delete(op.target)
-        var state = yield* this.getState(op.target[0])
-        if (state === op.target[1]) {
-          yield* this.checkDeleteStoreForState(state)
-          yield* this.setState(state)
-        }
+      this.ds.delete(op.target)
+      var state = yield* this.getState(op.target[0])
+      if (state.clock === op.target[1]) {
+        yield* this.checkDeleteStoreForState(state)
+        yield* this.setState(state)
       }
     }
   },
diff --git a/src/Types/Array.spec.js b/src/Types/Array.spec.js
index 03eb4164..5d85024c 100644
--- a/src/Types/Array.spec.js
+++ b/src/Types/Array.spec.js
@@ -8,10 +8,10 @@ describe('Array Type', function () {
 
   jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000
   beforeEach(async function (done) {
-    await createUsers(this, 2)
+    await createUsers(this, 3)
     y1 = (yconfig1 = this.users[0]).root
     y2 = (yconfig2 = this.users[1]).root
-    // y3 = (yconfig3 = this.users[2]).root
+    y3 = (yconfig3 = this.users[2]).root
     flushAll = this.users[0].connector.flushAll
     done()
   })
@@ -102,8 +102,11 @@ describe('Array Type', function () {
       l2 = await y2.get('Array')
       l1.insert(0, ['x', 'y'])
       l1.delete(0, 2)
+      await wait(500)
       await flushAll()
+      await wait(500)
       expect(l1.toArray()).toEqual(l2.toArray())
+      await compareAllUsers(this.users)
       done()
     })
     it('Basic insert. Then delete the whole array', async function (done) {
diff --git a/src/y.js b/src/y.js
index 86d2e827..7e13f236 100644
--- a/src/y.js
+++ b/src/y.js
@@ -15,7 +15,7 @@ class YConfig { // eslint-disable-line no-unused-vars
     this.db = new Y[opts.db.name](this, opts.db)
     this.connector = new Y[opts.connector.name](this, opts.connector)
     var yconfig = this
-    this.db.requestTransaction(function *() {
+    this.db.requestTransaction(function * requestTransaction () {
       // create initial Map type
       var model = {
         id: ['_', 0],
-- 
GitLab