Implemented support for composite type, fixed insert type issues for y-array

This commit is contained in:
Kevin Jahns 2016-02-29 13:46:08 +01:00
parent effc2fe576
commit ba4f444f32
4 changed files with 19 additions and 15 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "yjs", "name": "yjs",
"version": "9.0.4", "version": "9.1.0",
"description": "A framework for real-time p2p shared editing on arbitrary complex data types", "description": "A framework for real-time p2p shared editing on arbitrary complex data types",
"main": "./src/y.js", "main": "./src/y.js",
"scripts": { "scripts": {

View File

@ -205,9 +205,7 @@ module.exports = function (Y /* :any */) {
this.userIdPromise.then(f) this.userIdPromise.then(f)
} }
getNextOpId () { getNextOpId () {
if (this._nextUserId != null) { if (this.userId == null) {
return this._nextUserId
} else if (this.userId == null) {
throw new Error('OperationStore not yet initialized!') throw new Error('OperationStore not yet initialized!')
} else { } else {
return [this.userId, this.opClock++] return [this.userId, this.opClock++]

View File

@ -64,7 +64,7 @@ module.exports = function (Y/* :any */) {
if (op.parentSub != null) { if (op.parentSub != null) {
e.parentSub = op.parentSub e.parentSub = op.parentSub
} }
if (op.opContent != null) { if (op.hasOwnProperty('opContent')) {
e.opContent = op.opContent e.opContent = op.opContent
} else { } else {
e.content = op.content e.content = op.content

View File

@ -99,9 +99,9 @@ module.exports = function (Y/* :any */) {
} }
return t return t
} }
* createType (typedefinition) { * createType (typedefinition, id) {
var structname = typedefinition.struct var structname = typedefinition.struct
var id = this.store.getNextOpId() id = id || this.store.getNextOpId()
var op = Y.Struct[structname].create(id) var op = Y.Struct[structname].create(id)
op.type = typedefinition.name op.type = typedefinition.name
yield* this.applyCreatedOperations([op]) yield* this.applyCreatedOperations([op])
@ -653,14 +653,20 @@ module.exports = function (Y/* :any */) {
if (o != null || id[0] !== '_') { if (o != null || id[0] !== '_') {
return o return o
} else { } else {
// need to generate this operation // generate this operation?
if (this.store._nextUserId == null) { if (typeof id[1] === 'string') {
var struct = id[1].split('_')[0] var comp = id[1].split('_')
// this.store._nextUserId = id if (comp.length > 1) {
var op = Y.Struct[struct].create(id) var struct = comp[0]
yield* this.setOperation(op) var op = Y.Struct[struct].create(id)
// delete this.store._nextUserId yield* this.setOperation(op)
return 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 { } else {
// Can only generate one operation at a time // Can only generate one operation at a time
return null return null