From ba4f444f32852923c865ea3e5d41e6a6d67c0601 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Mon, 29 Feb 2016 13:46:08 +0100 Subject: [PATCH] Implemented support for composite type, fixed insert type issues for y-array --- package.json | 2 +- src/Database.js | 4 +--- src/Struct.js | 2 +- src/Transaction.js | 26 ++++++++++++++++---------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index b103559b..919ad4b6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yjs", - "version": "9.0.4", + "version": "9.1.0", "description": "A framework for real-time p2p shared editing on arbitrary complex data types", "main": "./src/y.js", "scripts": { diff --git a/src/Database.js b/src/Database.js index 6e092b49..fe9f3eb6 100644 --- a/src/Database.js +++ b/src/Database.js @@ -205,9 +205,7 @@ module.exports = function (Y /* :any */) { this.userIdPromise.then(f) } getNextOpId () { - if (this._nextUserId != null) { - return this._nextUserId - } else if (this.userId == null) { + if (this.userId == null) { throw new Error('OperationStore not yet initialized!') } else { return [this.userId, this.opClock++] diff --git a/src/Struct.js b/src/Struct.js index de0c5f54..7981aab3 100644 --- a/src/Struct.js +++ b/src/Struct.js @@ -64,7 +64,7 @@ module.exports = function (Y/* :any */) { if (op.parentSub != null) { e.parentSub = op.parentSub } - if (op.opContent != null) { + if (op.hasOwnProperty('opContent')) { e.opContent = op.opContent } else { e.content = op.content diff --git a/src/Transaction.js b/src/Transaction.js index 26e42677..a29a96ce 100644 --- a/src/Transaction.js +++ b/src/Transaction.js @@ -99,9 +99,9 @@ module.exports = function (Y/* :any */) { } return t } - * createType (typedefinition) { + * createType (typedefinition, id) { var structname = typedefinition.struct - var id = this.store.getNextOpId() + id = id || this.store.getNextOpId() var op = Y.Struct[structname].create(id) op.type = typedefinition.name yield* this.applyCreatedOperations([op]) @@ -653,14 +653,20 @@ module.exports = function (Y/* :any */) { if (o != null || id[0] !== '_') { return o } else { - // need to generate this operation - if (this.store._nextUserId == null) { - var struct = id[1].split('_')[0] - // this.store._nextUserId = id - var op = Y.Struct[struct].create(id) - yield* this.setOperation(op) - // delete this.store._nextUserId - return op + // generate this operation? + if (typeof id[1] === 'string') { + var comp = id[1].split('_') + if (comp.length > 1) { + var struct = comp[0] + var op = Y.Struct[struct].create(id) + 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 + } } else { // Can only generate one operation at a time return null