made createType synchronous
This commit is contained in:
parent
4078020afd
commit
e1e94bcf5d
@ -505,6 +505,46 @@ module.exports = function (Y /* :any */) {
|
|||||||
}, 0)
|
}, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
Get a type based on the id of its model.
|
||||||
|
If it does not exist yes, create it.
|
||||||
|
TODO: delete type from store.initializedTypes[id] when corresponding id was deleted!
|
||||||
|
*/
|
||||||
|
* getType (id, args) {
|
||||||
|
var sid = JSON.stringify(id)
|
||||||
|
var t = this.store.initializedTypes[sid]
|
||||||
|
if (t == null) {
|
||||||
|
var op/* :MapStruct | ListStruct */ = yield* this.getOperation(id)
|
||||||
|
if (op != null) {
|
||||||
|
t = yield* Y[op.type].typeDefinition.initType.call(this, this.store, op, args)
|
||||||
|
this.store.initializedTypes[sid] = t
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
createType (typedefinition, id) {
|
||||||
|
var structname = typedefinition[0].struct
|
||||||
|
id = id || this.getNextOpId(1)
|
||||||
|
var op = Y.Struct[structname].create(id)
|
||||||
|
op.type = typedefinition[0].name
|
||||||
|
|
||||||
|
/* TODO: implement for y-xml support
|
||||||
|
if (typedefinition[0].appendAdditionalInfo != null) {
|
||||||
|
yield* typedefinition[0].appendAdditionalInfo.call(this, op, typedefinition[1])
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
this.requestTransaction(function * () {
|
||||||
|
if (op[0] === '_') {
|
||||||
|
yield* this.setOperation(op)
|
||||||
|
} else {
|
||||||
|
yield* this.applyCreatedOperations([op])
|
||||||
|
}
|
||||||
|
})
|
||||||
|
var t = Y[op.type].typeDefinition.createNewType(this, op)
|
||||||
|
this.initializedTypes[JSON.stringify(op.id)] = t
|
||||||
|
return t
|
||||||
|
//return yield* this.getType(id, typedefinition[1])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Y.AbstractDatabase = AbstractDatabase
|
Y.AbstractDatabase = AbstractDatabase
|
||||||
}
|
}
|
||||||
|
@ -82,57 +82,6 @@ module.exports = function (Y/* :any */) {
|
|||||||
os: Store;
|
os: Store;
|
||||||
ss: Store;
|
ss: Store;
|
||||||
*/
|
*/
|
||||||
/*
|
|
||||||
Get a type based on the id of its model.
|
|
||||||
If it does not exist yes, create it.
|
|
||||||
TODO: delete type from store.initializedTypes[id] when corresponding id was deleted!
|
|
||||||
*/
|
|
||||||
* getType (id, args) {
|
|
||||||
var sid = JSON.stringify(id)
|
|
||||||
var t = this.store.initializedTypes[sid]
|
|
||||||
if (t == null) {
|
|
||||||
var op/* :MapStruct | ListStruct */ = yield* this.getOperation(id)
|
|
||||||
if (op != null) {
|
|
||||||
t = yield* Y[op.type].typeDefinition.initType.call(this, this.store, op, args)
|
|
||||||
this.store.initializedTypes[sid] = t
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
* createType (typedefinition, id) {
|
|
||||||
var structname = typedefinition[0].struct
|
|
||||||
id = id || this.store.getNextOpId(1)
|
|
||||||
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(1)
|
|
||||||
var 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])
|
|
||||||
}
|
|
||||||
// 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!)
|
Apply operations that this user created (no remote ones!)
|
||||||
* does not check for Struct.*.requiredOps()
|
* does not check for Struct.*.requiredOps()
|
||||||
|
18
src/Utils.js
18
src/Utils.js
@ -238,7 +238,13 @@ module.exports = function (Y /* : any*/) {
|
|||||||
// finished with remaining operations
|
// finished with remaining operations
|
||||||
self.waiting.push(d)
|
self.waiting.push(d)
|
||||||
}
|
}
|
||||||
checkDelete(op)
|
if (op.key == null) {
|
||||||
|
// deletes in list
|
||||||
|
checkDelete(op)
|
||||||
|
} else {
|
||||||
|
// deletes in map
|
||||||
|
this.waiting.push(op)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.waiting.push(op)
|
this.waiting.push(op)
|
||||||
}
|
}
|
||||||
@ -287,7 +293,11 @@ module.exports = function (Y /* : any*/) {
|
|||||||
var o = this.waiting[i]
|
var o = this.waiting[i]
|
||||||
if (o.struct === 'Insert') {
|
if (o.struct === 'Insert') {
|
||||||
var _o = yield* transaction.getInsertion(o.id)
|
var _o = yield* transaction.getInsertion(o.id)
|
||||||
if (!Y.utils.compareIds(_o.id, o.id)) {
|
if (_o.parentSub != null && _o.left != null) {
|
||||||
|
// if o is an insertion of a map struc (parentSub is defined), then it shouldn't be necessary to compute left
|
||||||
|
this.waiting.splice(i,1)
|
||||||
|
i-- // update index
|
||||||
|
} else if (!Y.utils.compareIds(_o.id, o.id)) {
|
||||||
// o got extended
|
// o got extended
|
||||||
o.left = [o.id[0], o.id[1] - 1]
|
o.left = [o.id[0], o.id[1] - 1]
|
||||||
} else if (_o.left == null) {
|
} else if (_o.left == null) {
|
||||||
@ -469,12 +479,14 @@ module.exports = function (Y /* : any*/) {
|
|||||||
if (def.struct == null ||
|
if (def.struct == null ||
|
||||||
def.initType == null ||
|
def.initType == null ||
|
||||||
def.class == null ||
|
def.class == null ||
|
||||||
def.name == null
|
def.name == null ||
|
||||||
|
def.createNewType == null
|
||||||
) {
|
) {
|
||||||
throw new Error('Custom type was not initialized correctly!')
|
throw new Error('Custom type was not initialized correctly!')
|
||||||
}
|
}
|
||||||
this.struct = def.struct
|
this.struct = def.struct
|
||||||
this.initType = def.initType
|
this.initType = def.initType
|
||||||
|
this.createNewType = def.createNewType
|
||||||
this.class = def.class
|
this.class = def.class
|
||||||
this.name = def.name
|
this.name = def.name
|
||||||
if (def.appendAdditionalInfo != null) {
|
if (def.appendAdditionalInfo != null) {
|
||||||
|
2
src/y.js
2
src/y.js
@ -151,7 +151,7 @@ class YConfig {
|
|||||||
var type = Y[typeName]
|
var type = Y[typeName]
|
||||||
var typedef = type.typeDefinition
|
var typedef = type.typeDefinition
|
||||||
var id = ['_', typedef.struct + '_' + typeName + '_' + propertyname + '_' + typeConstructor]
|
var id = ['_', typedef.struct + '_' + typeName + '_' + propertyname + '_' + typeConstructor]
|
||||||
share[propertyname] = yield* this.createType(type.apply(typedef, args), id)
|
share[propertyname] = this.store.createType(type.apply(typedef, args), id)
|
||||||
}
|
}
|
||||||
this.store.whenTransactionsFinished()
|
this.store.whenTransactionsFinished()
|
||||||
.then(callback)
|
.then(callback)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user