Implemented Xml Struct

This commit is contained in:
Kevin Jahns
2017-08-24 14:44:23 +02:00
parent 86c46cf0ec
commit ab6cde07e6
19 changed files with 1087 additions and 590 deletions

View File

@@ -588,7 +588,7 @@ export default function extendDatabase (Y /* :any */) {
createType (typedefinition, id) {
var structname = typedefinition[0].struct
id = id || this.getNextOpId(1)
var op = Y.Struct[structname].create(id)
var op = Y.Struct[structname].create(id, typedefinition[1])
op.type = typedefinition[0].name
this.requestTransaction(function * () {

File diff suppressed because it is too large Load Diff

View File

@@ -863,7 +863,12 @@ export default function extendTransaction (Y) {
var comp = id[1].split('_')
if (comp.length > 1) {
var struct = comp[0]
var op = Y.Struct[struct].create(id)
let type = Y[comp[1]]
let args = null
if (type != null) {
args = Y.utils.parseTypeDefinition(type, comp[3])
}
var op = Y.Struct[struct].create(id, args)
op.type = comp[1]
yield * this.setOperation(op)
return op

View File

@@ -840,4 +840,17 @@ export default function Utils (Y) {
}
}
Y.utils.generateUserId = generateUserId
Y.utils.parseTypeDefinition = function parseTypeDefinition (type, typeArgs) {
var args = []
try {
args = JSON.parse('[' + typeArgs + ']')
} catch (e) {
throw new Error('Was not able to parse type definition!')
}
if (type.typeDefinition.parseArguments != null) {
args = type.typeDefinition.parseArguments(args[0])[1]
}
return args
}
}

View File

@@ -176,23 +176,15 @@ class YConfig extends Y.utils.NamedEventHandler {
// create shared object
for (var propertyname in opts.share) {
var typeConstructor = opts.share[propertyname].split('(')
let typeArgs = ''
if (typeConstructor.length === 2) {
typeArgs = typeConstructor[1].split(')')[0] || ''
}
var typeName = typeConstructor.splice(0, 1)
var type = Y[typeName]
var typedef = type.typeDefinition
var id = [0xFFFFFF, typedef.struct + '_' + typeName + '_' + propertyname + '_' + typeConstructor]
var args = []
if (typeConstructor.length === 1) {
try {
args = JSON.parse('[' + typeConstructor[0].split(')')[0] + ']')
} catch (e) {
throw new Error('Was not able to parse type definition! (share.' + propertyname + ')')
}
if (type.typeDefinition.parseArguments == null) {
throw new Error(typeName + ' does not expect arguments!')
} else {
args = typedef.parseArguments(args[0])[1]
}
}
var id = [0xFFFFFF, typedef.struct + '_' + typeName + '_' + propertyname + '_' + typeArgs]
let args = Y.utils.parseTypeDefinition(type, typeArgs)
share[propertyname] = yield * this.store.initType.call(this, id, args)
}
})