Compare commits

...

2 Commits

Author SHA1 Message Date
Kevin Jahns
428d825f41 Deploy 11.2.1 2016-05-24 15:24:53 +02:00
Kevin Jahns
b9f9c762eb Deploy 11.2.0 2016-05-10 18:12:57 +02:00
5 changed files with 89 additions and 72 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "yjs", "name": "yjs",
"version": "11.1.0", "version": "11.2.1",
"homepage": "y-js.org", "homepage": "y-js.org",
"authors": [ "authors": [
"Kevin Jahns <kevin.jahns@rwth-aachen.de>" "Kevin Jahns <kevin.jahns@rwth-aachen.de>"

149
y.es6
View File

@@ -963,56 +963,73 @@ module.exports = function (Y /* :any */) {
} }
} }
} }
// called by a transaction when an operation is added /*
* Called by a transaction when an operation is added.
* This function is especially important for y-indexeddb, where several instances may share a single database.
* Every time an operation is created by one instance, it is send to all other instances and operationAdded is called
*
* If it's not a Delete operation:
* * Checks if another operation is executable (listenersById)
* * Update state, if possible
*
* Always:
* * Call type
*/
* operationAdded (transaction, op) { * operationAdded (transaction, op) {
// increase SS if (op.struct === 'Delete') {
yield* transaction.updateState(op.id[0]) var target = yield* transaction.getInsertion(op.target)
var type = this.initializedTypes[JSON.stringify(target.parent)]
var opLen = op.content != null ? op.content.length : 1 if (type != null) {
for (let i = 0; i < opLen; i++) { yield* type._changed(transaction, op)
// notify whenOperation listeners (by id) }
var sid = JSON.stringify([op.id[0], op.id[1] + i]) } else {
var l = this.listenersById[sid] // increase SS
delete this.listenersById[sid] yield* transaction.updateState(op.id[0])
var opLen = op.content != null ? op.content.length : 1
if (l != null) { for (let i = 0; i < opLen; i++) {
for (var key in l) { // notify whenOperation listeners (by id)
var listener = l[key] var sid = JSON.stringify([op.id[0], op.id[1] + i])
if (--listener.missing === 0) { var l = this.listenersById[sid]
this.whenOperationsExist([], listener.op) delete this.listenersById[sid]
if (l != null) {
for (var key in l) {
var listener = l[key]
if (--listener.missing === 0) {
this.whenOperationsExist([], listener.op)
}
} }
} }
} }
} var t = this.initializedTypes[JSON.stringify(op.parent)]
var t = this.initializedTypes[JSON.stringify(op.parent)]
// if parent is deleted, mark as gc'd and return // if parent is deleted, mark as gc'd and return
if (op.parent != null) { if (op.parent != null) {
var parentIsDeleted = yield* transaction.isDeleted(op.parent) var parentIsDeleted = yield* transaction.isDeleted(op.parent)
if (parentIsDeleted) { if (parentIsDeleted) {
yield* transaction.deleteList(op.id) yield* transaction.deleteList(op.id)
return return
}
} }
}
// notify parent, if it was instanciated as a custom type // notify parent, if it was instanciated as a custom type
if (t != null) { if (t != null) {
let o = Y.utils.copyOperation(op) let o = Y.utils.copyOperation(op)
yield* t._changed(transaction, o) yield* t._changed(transaction, o)
} }
if (!op.deleted) { if (!op.deleted) {
// Delete if DS says this is actually deleted // Delete if DS says this is actually deleted
var len = op.content != null ? op.content.length : 1 var len = op.content != null ? op.content.length : 1
var startId = op.id // You must not use op.id in the following loop, because op will change when deleted var startId = op.id // You must not use op.id in the following loop, because op will change when deleted
for (let i = 0; i < len; i++) { for (let i = 0; i < len; i++) {
var id = [startId[0], startId[1] + i] var id = [startId[0], startId[1] + i]
var opIsDeleted = yield* transaction.isDeleted(id) var opIsDeleted = yield* transaction.isDeleted(id)
if (opIsDeleted) { if (opIsDeleted) {
var delop = { var delop = {
struct: 'Delete', struct: 'Delete',
target: id target: id
}
yield* this.tryExecute.call(transaction, delop)
} }
yield* this.tryExecute.call(transaction, delop)
} }
} }
} }
@@ -1741,14 +1758,11 @@ module.exports = function (Y/* :any */) {
right = null right = null
} }
if (callType && !preventCallType) { if (callType && !preventCallType) {
var type = this.store.initializedTypes[JSON.stringify(target.parent)] yield* this.store.operationAdded(this, {
if (type != null) { struct: 'Delete',
yield* type._changed(this, { target: target.id,
struct: 'Delete', length: targetLength
target: target.id, })
length: targetLength
})
}
} }
// need to gc in the end! // need to gc in the end!
yield* this.store.addToGarbageCollector.call(this, target, left) yield* this.store.addToGarbageCollector.call(this, target, left)
@@ -3214,6 +3228,7 @@ function requestModules (modules) {
}) })
promises.push(requireModule.promise) promises.push(requireModule.promise)
} else { } else {
console.info('YJS: Please do not depend on automatic requiring of modules anymore! Extend modules as follows `require(\'y-modulename\')(Y)`')
require(modulename)(Y) require(modulename)(Y)
} }
} else { } else {
@@ -3260,23 +3275,25 @@ function Y (opts/* :YOptions */) /* :Promise<YConfig> */ {
modules.push(opts.share[name]) modules.push(opts.share[name])
} }
Y.sourceDir = opts.sourceDir Y.sourceDir = opts.sourceDir
return Y.requestModules(modules).then(function () { return new Promise(function (resolve, reject) {
return new Promise(function (resolve, reject) { setTimeout(function () {
if (opts == null) reject('An options object is expected! ') Y.requestModules(modules).then(function () {
else if (opts.connector == null) reject('You must specify a connector! (missing connector property)') if (opts == null) reject('An options object is expected! ')
else if (opts.connector.name == null) reject('You must specify connector name! (missing connector.name property)') else if (opts.connector == null) reject('You must specify a connector! (missing connector property)')
else if (opts.db == null) reject('You must specify a database! (missing db property)') else if (opts.connector.name == null) reject('You must specify connector name! (missing connector.name property)')
else if (opts.connector.name == null) reject('You must specify db name! (missing db.name property)') else if (opts.db == null) reject('You must specify a database! (missing db property)')
else if (opts.share == null) reject('You must specify a set of shared types!') else if (opts.connector.name == null) reject('You must specify db name! (missing db.name property)')
else { else if (opts.share == null) reject('You must specify a set of shared types!')
var yconfig = new YConfig(opts) else {
yconfig.db.whenUserIdSet(function () { var yconfig = new YConfig(opts)
yconfig.init(function () { yconfig.db.whenUserIdSet(function () {
resolve(yconfig) yconfig.init(function () {
resolve(yconfig)
})
}) })
}) }
} }).catch(reject)
}) }, 0)
}) })
} }

File diff suppressed because one or more lines are too long

6
y.js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long