From 2a601ac6f62f54ace0a4e7902a2920e100919505 Mon Sep 17 00:00:00 2001 From: Kevin Jahns <kevin.jahns@rwth-aachen.de> Date: Sun, 13 Sep 2015 18:22:45 +0200 Subject: [PATCH] fixed some bugs & linted & prettyfied gulpfile --- gulpfile.js | 117 ++++++++++++----------------- package.json | 7 +- q.js | 12 --- src/Helper.spec.js | 13 +--- src/OperationStore.js | 15 ++++ src/OperationStores/Memory.js | 4 +- src/OperationStores/Memory.spec.js | 10 ++- src/Struct.js | 2 +- src/Types/Array.spec.js | 7 +- src/y.js | 2 +- test.js | 34 --------- 11 files changed, 82 insertions(+), 141 deletions(-) delete mode 100644 q.js delete mode 100644 test.js diff --git a/gulpfile.js b/gulpfile.js index 5490e79d..fb93bb36 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -30,7 +30,7 @@ Commands: - build: Build this library - - develop: + - dev: Watch the ./src directory. Builds and specs the library on changes. Starts an http-server and serves the test suite on http://127.0.0.1:8888. @@ -49,11 +49,6 @@ 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' -] var options = minimist(process.argv.slice(2), { string: ['export', 'name', 'testport', 'testfiles'], @@ -64,49 +59,57 @@ var options = minimist(process.argv.slice(2), { testfiles: 'src/**/*.js' } }) -var yfiles = polyfills.concat(['src/y.js', 'src/Connector.js', 'src/OperationStore.js', 'src/Struct.js', 'src/Utils.js', - 'src/OperationStores/RedBlackTree.js', 'src/Memory.js', 'src/**/*.js']) + +var polyfills = [ + './node_modules/gulp-babel/node_modules/babel-core/node_modules/regenerator/runtime.js' +] + +var concatOrder = [ + 'Helper.spec.js', + 'y.js', + 'Connector.js', + 'OperationStore.js', + 'Struct.js', + 'Utils.js', + 'OperationStores/RedBlackTree.js', + 'OperationStores/Memory.js', + 'OperationStores/IndexedDB.js', + 'Connectors/Test.js', + 'Connectors/WebRTC.js', + 'Types/Array.js', + 'Types/Map.js', + 'Types/TextBind.js' +] var files = { - y: yfiles.concat(['!src/**/*.spec.js']), - test: yfiles.concat([options.testfiles]), - build_test: ['build_test/y.js'] + production: polyfills.concat(concatOrder.map(function (f) { + return 'src/' + f + })), + test: concatOrder.map(function (f) { + return 'build/' + f + }).concat(['build/**/*.spec.js']) } -gulp.task('build', function () { - /* - return gulp.src(files.y) - .pipe(sourcemaps.init()) - .pipe(concat(options.name)) - .pipe(babel({ - loose: "all", - modules: options.export, - // blacklist: "regenerator" // you can't uglify when regenerator is blacklisted! - })) - .pipe(uglify()) - .pipe(sourcemaps.write(".")) - .pipe(gulp.dest("."));*/ - return gulp.src(files.y) +gulp.task('build:deploy', function () { + gulp.src('src/**/*.js') .pipe(sourcemaps.init()) - .pipe(concat(options.name)) + .pipe(concat('y.js')) .pipe(babel({ loose: 'all', modules: 'ignore', - optional: ['es7.asyncFunctions'], - blacklist: ['regenerator'], experimental: true })) - .pipe(sourcemaps.write('.')) + .pipe(uglify()) + .pipe(sourcemaps.write()) .pipe(gulp.dest('.')) }) -gulp.task('testbuild', function () { +gulp.task('build:test', function () { gulp.src('src/**/*.js') .pipe(sourcemaps.init()) .pipe(babel({ loose: 'all', modules: 'ignore', - // optional: ['es7.asyncFunctions'], blacklist: 'regenerator', experimental: true })) @@ -114,54 +117,30 @@ gulp.task('testbuild', function () { .pipe(gulp.dest('build')) }) -gulp.task('build_jasmine_browser', function () { - gulp.src(files.test) - .pipe(sourcemaps.init()) - .pipe(concat('jasmine_browser.js')) - .pipe(babel({ - loose: 'all', - modules: 'ignore', - // optional: ['es7.asyncFunctions'], - blacklist: 'regenerator' - // experimental: true - })) - .pipe(sourcemaps.write()) - .pipe(gulp.dest('build')) +gulp.task('dev:node', ['test'], function () { + gulp.watch('src/**/*.js', ['test']) }) -var testy = [ - "build/Helper.spec.js", - "build/y.js", - "build/Connector.js", - "build/OperationStore.js", - "build/Struct.js", - "build/Utils.js", - "build/OperationStores/RedBlackTree.js", - "build/OperationStores/Memory.js", - "build/OperationStores/IndexedDB.js", - "build/Connectors/Test.js", - "build/Connectors/WebRTC.js", - "build/Types/Array.js", - "build/Types/Map.js", - "build/Types/TextBind.js", - "build/**/*.spec.js" -] -gulp.task('develop', ['testbuild'], function () { - //gulp.watch(files.test, ['build_jasmine_browser']) - // gulp.watch(files.test, ["test"]) - gulp.watch('src/**/*.js', ['testbuild']) - return gulp.src(testy) +gulp.task('dev:browser', ['build:test'], function () { + gulp.watch('src/**/*.js', ['build:test']) + + gulp.src(files.test) .pipe(watch('build/**/*.js')) .pipe(jasmineBrowser.specRunner()) .pipe(jasmineBrowser.server({port: options.testport})) }) -gulp.task('test', ['testbuild'], function () { - return gulp.src(testy) +gulp.task('dev', ['build:test'], function () { + gulp.start('dev:browser') + gulp.start('dev:node') +}) + +gulp.task('test', ['build:test'], function () { + return gulp.src(files.test) .pipe(jasmine({ verbose: true, includeStuckTrace: true })) }) -gulp.task('default', ['build', 'test']) +gulp.task('default', ['test']) diff --git a/package.json b/package.json index aed81744..d7dc1ed5 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ }, "pre-commit": [ "lint", - "build" + "test" ], "standard": { "parser": "babel-eslint", @@ -41,11 +41,10 @@ }, "homepage": "http://y-js.org", "devDependencies": { - "babel-eslint": "^3.1.23", + "babel-eslint": "^4.1.1", "gulp": "^3.9.0", "gulp-babel": "^5.1.0", "gulp-concat": "^2.5.2", - "gulp-ignore": "^1.2.1", "gulp-jasmine": "^2.0.1", "gulp-jasmine-browser": "^0.1.3", "gulp-sourcemaps": "^1.5.2", @@ -54,6 +53,6 @@ "gulp-watch": "^4.2.4", "minimist": "^1.1.1", "pre-commit": "^1.0.10", - "standard": "^5.0.0-2" + "standard": "^5.2.2" } } diff --git a/q.js b/q.js deleted file mode 100644 index 31dbc05f..00000000 --- a/q.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict'; - - -var x = new Promise(function(r){r(true)}) - -x.then(function(q){console.log("yay",q)}) - -var ff = function * (){ - -} - -console.log("dtrn") diff --git a/src/Helper.spec.js b/src/Helper.spec.js index 74879f09..4fd7e903 100644 --- a/src/Helper.spec.js +++ b/src/Helper.spec.js @@ -1,5 +1,5 @@ /* global Y */ -/* eslint-env browser,jasmine */ +/* eslint-env browser, jasmine */ /* This is just a compilation of functions that help to test this library! @@ -15,9 +15,6 @@ if (typeof global !== 'undefined') { } g.g = g -//var co = require('co') -// g.co = co - function wait (t) { if (t == null) { t = 10 @@ -194,7 +191,6 @@ function async (makeGenerator) { return Promise.resolve(result.value).then(function (res) { return handle(generator.next(res)) }, function (err) { - debugger return handle(generator.throw(err)) }) } @@ -207,10 +203,3 @@ function async (makeGenerator) { } } g.wrapCo = async - -/*function wrapCo (gen) { - return function (done) { - return co.wrap(gen)(done) - } -} -g.wrapCo = wrapCo*/ diff --git a/src/OperationStore.js b/src/OperationStore.js index c5b9a4b7..ef00145b 100644 --- a/src/OperationStore.js +++ b/src/OperationStore.js @@ -79,10 +79,25 @@ class AbstractOperationStore { // eslint-disable-line no-unused-vars if (o.left != null) { var left = yield* this.getOperation(o.left) left.right = o.right + yield* this.setOperation(left) } if (o.right != null) { var right = yield* this.getOperation(o.right) right.left = o.left + yield* this.setOperation(right) + } + var parent = yield* this.getOperation(o.parent) + var setParent = false + if (Y.utils.compareIds(parent.start, o.id)) { + setParent = true + parent.start = o.right + } + if (Y.utils.compareIds(parent.end, o.id)) { + setParent = true + parent.end = o.left + } + if (setParent) { + yield* this.setOperation(parent) } yield* this.removeOperation(o.id) } diff --git a/src/OperationStores/Memory.js b/src/OperationStores/Memory.js index 67483fdf..2ccf1285 100644 --- a/src/OperationStores/Memory.js +++ b/src/OperationStores/Memory.js @@ -16,12 +16,12 @@ class DeleteStore extends Y.utils.RBTree { } isDeleted (id) { var n = this.findNodeWithUpperBound(id) - return n !== null && n.val.id[0] === id[0] && id[0] < n.val.id[0] + n.val.len + return n !== null && n.val.id[0] === id[0] && id[1] < n.val.id[1] + n.val.len } delete (id) { var n = this.findNodeWithUpperBound(id) if (n != null && n.val.id[0] === id[0]) { - if (n.val.id[1] === id[1]) { + if (n.val.id[1] <= id[1] && id[1] < n.val.id[1] + n.val.len) { // already deleted return } else if (n.val.id[1] + n.val.len === id[1]) { diff --git a/src/OperationStores/Memory.spec.js b/src/OperationStores/Memory.spec.js index 4755bfd3..59fd04b9 100644 --- a/src/OperationStores/Memory.spec.js +++ b/src/OperationStores/Memory.spec.js @@ -10,14 +10,20 @@ describe('Memory', function () { it('Deleted operation is deleted', function () { ds.delete(['u1', 10]) expect(ds.isDeleted(['u1', 10])).toBeTruthy() - expect(ds.toDeleteSet()).toBeTruthy({'u1': [10, 1]}) + expect(ds.toDeleteSet()).toEqual({'u1': [[10, 1]]}) }) it('Deleted operation extends other deleted operation', function () { ds.delete(['u1', 10]) ds.delete(['u1', 11]) expect(ds.isDeleted(['u1', 10])).toBeTruthy() expect(ds.isDeleted(['u1', 11])).toBeTruthy() - expect(ds.toDeleteSet()).toBeTruthy({'u1': [10, 2]}) + expect(ds.toDeleteSet()).toEqual({'u1': [[10, 2]]}) + }) + it('Deleted operation extends other deleted operation', function () { + ds.delete(['0', 3]) + ds.delete(['0', 4]) + ds.delete(['0', 2]) + expect(ds.toDeleteSet()).toEqual({'0': [[2, 3]]}) }) it('Creates operations', function () { var dels = ds.getDeletions({5: [[4, 1]]}) diff --git a/src/Struct.js b/src/Struct.js index d66dbd86..973ae5a7 100644 --- a/src/Struct.js +++ b/src/Struct.js @@ -34,7 +34,7 @@ var Struct = { var target = yield* this.getOperation(op.target) if (target != null && !target.deleted) { target.deleted = true - if (target.left !== null && (yield* this.getOperation(target.left)).deleted) { + if (target.left === null || (yield* this.getOperation(target.left)).deleted) { this.store.addToGarbageCollector(target.id) target.gc = true } diff --git a/src/Types/Array.spec.js b/src/Types/Array.spec.js index d4ce3e00..7b27e6e3 100644 --- a/src/Types/Array.spec.js +++ b/src/Types/Array.spec.js @@ -6,7 +6,7 @@ var numberOfYArrayTests = 5 describe('Array Type', function () { var y1, y2, y3, yconfig1, yconfig2, yconfig3, flushAll - jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000 + jasmine.DEFAULT_TIMEOUT_INTERVAL = 100 beforeEach(wrapCo(function * (done) { yield createUsers(this, 3) y1 = (yconfig1 = this.users[0]).root @@ -23,7 +23,6 @@ describe('Array Type', function () { describe('Basic tests', function () { it('insert three elements, try re-get property', wrapCo(function * (done) { - console.log("blahhhhhhhhhhhhhhhhh ") var array = yield y1.set('Array', Y.Array) array.insert(0, [1, 2, 3]) array = yield y1.get('Array') // re-get property @@ -104,9 +103,9 @@ describe('Array Type', function () { l2 = yield y2.get('Array') l1.insert(0, ['x', 'y']) l1.delete(0, 2) - yield wait(500) + yield wait() yield flushAll() - yield wait(500) + yield wait() expect(l1.toArray()).toEqual(l2.toArray()) yield compareAllUsers(this.users) done() diff --git a/src/y.js b/src/y.js index 2b313342..78bc13a2 100644 --- a/src/y.js +++ b/src/y.js @@ -57,6 +57,6 @@ class YConfig { // eslint-disable-line no-unused-vars if (g) { // eslint-disable-line g.Y = Y //eslint-disable-line - debugger //eslint-disable-line + // debugger //eslint-disable-line } Y.utils = {} diff --git a/test.js b/test.js deleted file mode 100644 index 3cf0cdb1..00000000 --- a/test.js +++ /dev/null @@ -1,34 +0,0 @@ -'use strict'; - -function * aaa (){} - -class Y { - constructor () { - this.y = 4 - } -} - -class X extends Y { - constructor (a) { - this.x = 'true' - } - stuff () { - console.log("yay") - var r = function * () { - yield "dtrn" - } - var test = r() - console.dir(r()) - } -} -var Q = {} -Q["X"] = X - -var P = Q['X'] -var x = new P( 44 ) - -(new Promise(function(resolve){ - resolve(true) -})).then(function(arg){ - console.log("yay", arg) -}) -- GitLab