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",
"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": {

View File

@ -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++]

View File

@ -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

View File

@ -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