From f844dcbc1e0a03ee36991270509409cd22497df4 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Mon, 14 Mar 2016 19:46:57 +0100 Subject: [PATCH] bugfixes creating structs without loading type (e.g. for y-websockets-server) --- dist | 2 +- gulpfile.helper.js | 6 ++-- src/SpecHelper.js | 2 +- src/Transaction.js | 70 ++++++++++++++++++++++++++++++---------------- src/y.js | 5 ++-- 5 files changed, 55 insertions(+), 30 deletions(-) diff --git a/dist b/dist index 51c8d3bd..5cfe2096 160000 --- a/dist +++ b/dist @@ -1 +1 @@ -Subproject commit 51c8d3bdc6e9b4e485fcce88f50ab132f65db252 +Subproject commit 5cfe209688c31ae496b6c86db0dc5adbf15b8046 diff --git a/gulpfile.helper.js b/gulpfile.helper.js index 743deabb..c07e1ad4 100644 --- a/gulpfile.helper.js +++ b/gulpfile.helper.js @@ -91,10 +91,12 @@ module.exports = function (gulp, helperOptions) { var browserify = require('browserify') var source = require('vinyl-source-stream') var buffer = require('vinyl-buffer') + return browserify({ - entries: files.specs, + entries: files.specs, // .concat(files.distEs5), debug: true - }).bundle() + })// .transform('babelify', { presets: ['es2015'] }) + .bundle() .pipe(source('specs.js')) .pipe(buffer()) // .pipe($.sourcemaps.init({loadMaps: true})) diff --git a/src/SpecHelper.js b/src/SpecHelper.js index a78f73be..d5daca9d 100644 --- a/src/SpecHelper.js +++ b/src/SpecHelper.js @@ -25,7 +25,7 @@ g.g = g g.YConcurrency_TestingMode = true -jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000 +jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000 g.describeManyTimes = function describeManyTimes (times, name, f) { for (var i = 0; i < times; i++) { diff --git a/src/Transaction.js b/src/Transaction.js index 6d354184..ee1556cf 100644 --- a/src/Transaction.js +++ b/src/Transaction.js @@ -100,6 +100,26 @@ module.exports = function (Y/* :any */) { return t } * createType (typedefinition, id) { + var structname = typedefinition[0].struct + id = id || this.store.getNextOpId() + var op + if (id[0] === '_') { + op = yield* this.getOperation(id) + } else { + op = Y.Struct[structname].create(id) + op.type = typedefinition[0].name + } + if (typedefinition[0].appendAdditionalInfo != null) { + yield* typedefinition[0].appendAdditionalInfo.call(this, op, typedefinition[1]) + } + if (op[0] === '_') { + yield* this.setOperation(op) + } else { + yield* this.applyCreatedOperations([op]) + } + return yield* this.getType(id, typedefinition[1]) + } + /* createType (typedefinition, id) { var structname = typedefinition[0].struct id = id || this.store.getNextOpId() var op = Y.Struct[structname].create(id) @@ -107,9 +127,12 @@ module.exports = function (Y/* :any */) { if (typedefinition[0].appendAdditionalInfo != null) { yield* typedefinition[0].appendAdditionalInfo.call(this, op, typedefinition[1]) } - yield* this.applyCreatedOperations([op]) + // yield* this.applyCreatedOperations([op]) + yield* Y.Struct[op.struct].execute.call(this, op) + yield* this.addOperation(op) + yield* this.store.operationAdded(this, op) return yield* this.getType(id, typedefinition[1]) - } + }*/ /* Apply operations that this user created (no remote ones!) * does not check for Struct.*.requiredOps() @@ -156,7 +179,7 @@ module.exports = function (Y/* :any */) { yield* this.markDeleted(targetId, 1) } - if (target != null && target.gc == null) { + if (target != null) { if (!target.deleted) { callType = true // set deleted & notify type @@ -187,7 +210,7 @@ module.exports = function (Y/* :any */) { } if (target.opContent != null) { yield* this.deleteOperation(target.opContent) - target.opContent = null + // target.opContent = null } } var left @@ -474,10 +497,12 @@ module.exports = function (Y/* :any */) { yield* this.setOperation(origin) } } - - if (o.parent != null) { - // remove gc'd op from parent, if it exists - var parent /* MapOperation */ = yield* this.getOperation(o.parent) + var parent + if (o.parent != null){ + parent = yield* this.getOperation(o.parent) + } + // remove gc'd op from parent, if it exists + if (parent != null) { var setParent = false // whether to save parent to the os if (o.parentSub != null) { if (Y.utils.compareIds(parent.map[o.parentSub], o.id)) { @@ -656,23 +681,20 @@ module.exports = function (Y/* :any */) { if (o != null || id[0] !== '_') { return o } else { - /* // generate this operation? - if (typeof id[1] === 'string') { - var comp = id[1].split('_') - if (comp.length > 2 || id[0] === '_') { - var struct = comp[0] - var op = Y.Struct[struct].create(id) - op.type = comp[1] - yield* this.setOperation(op) - return op - } else { - // won't be called. but just in case.. - console.error('Unexpected case. How can this happen?') - debugger // eslint-disable-line - return null - } + // generate this operation? + var comp = id[1].split('_') + if (comp.length > 1) { + var struct = comp[0] + var op = Y.Struct[struct].create(id) + op.type = comp[1] + yield* this.setOperation(op) + return op } else { - */ + // won't be called. but just in case.. + console.error('Unexpected case. How can this happen?') + debugger // eslint-disable-line + return null + } return null } } diff --git a/src/y.js b/src/y.js index 58d91737..815e5ac2 100644 --- a/src/y.js +++ b/src/y.js @@ -145,9 +145,10 @@ class YConfig { throw new Error('Was not able to parse type definition! (share.' + propertyname + ')') } } - var id = ['_', propertyname + '_' + typeConstructor] var type = Y[typeName] - share[propertyname] = yield* this.createType(type.apply(type.typeDefinition, args), id) + var typedef = type.typeDefinition + var id = ['_', typedef.struct + '_' + typeName + '_' + propertyname + '_' + typeConstructor] + share[propertyname] = yield* this.createType(type.apply(typedef, args), id) } this.store.whenTransactionsFinished() .then(callback)