integrate ydb client and adapt some demos

This commit is contained in:
Kevin Jahns
2018-10-13 14:38:29 +02:00
parent 3b08267daa
commit 4c01a34d09
27 changed files with 314 additions and 91 deletions

View File

@@ -69,9 +69,10 @@ export default class DomBinding extends Binding {
subtree: true
})
this._currentSel = null
document.addEventListener('selectionchange', () => {
this._selectionchange = () => {
this._currentSel = getCurrentRelativeSelection(this)
})
}
document.addEventListener('selectionchange', this._selectionchange)
const y = type._y
this.y = y
// Force flush dom changes before Type changes are applied (they might
@@ -193,6 +194,7 @@ export default class DomBinding extends Binding {
y.off('beforeTransaction', this._beforeTransactionHandler)
y.off('beforeObserverCalls', this._beforeObserverCallsHandler)
y.off('afterTransaction', this._afterTransactionHandler)
document.removeEventListener('selectionchange', this._selectionchange)
super.destroy()
}
}

View File

@@ -107,3 +107,35 @@ export function integrateRemoteStructs (y, decoder) {
}
}
}
// TODO: use this above / refactor
export function integrateRemoteStruct (y, decoder) {
let reference = decoder.readVarUint()
let Constr = getStruct(reference)
let struct = new Constr()
let decoderPos = decoder.pos
let missing = struct._fromBinary(y, decoder)
if (missing.length === 0) {
while (struct != null) {
_integrateRemoteStructHelper(y, struct)
struct = y._readyToIntegrate.shift()
}
} else {
let _decoder = new BinaryDecoder(decoder.uint8arr)
_decoder.pos = decoderPos
let missingEntry = new MissingEntry(_decoder, missing, struct)
let missingStructs = y._missingStructs
for (let i = missing.length - 1; i >= 0; i--) {
let m = missing[i]
if (!missingStructs.has(m.user)) {
missingStructs.set(m.user, new Map())
}
let msu = missingStructs.get(m.user)
if (!msu.has(m.clock)) {
msu.set(m.clock, [])
}
let mArray = msu = msu.get(m.clock)
mArray.push(missingEntry)
}
}
}

View File

@@ -60,18 +60,13 @@ export default class Transaction {
*/
this.changedParentTypes = new Map()
this.encodedStructsLen = 0
this._encodedStructs = new BinaryEncoder()
this._encodedStructs.writeUint32(0)
}
get encodedStructs () {
this._encodedStructs.setUint32(0, this.encodedStructsLen)
return this._encodedStructs
this.encodedStructs = new BinaryEncoder()
}
}
export function writeStructToTransaction (transaction, struct) {
transaction.encodedStructsLen++
struct._toBinary(transaction._encodedStructs)
struct._toBinary(transaction.encodedStructs)
}
/**

View File

@@ -36,21 +36,8 @@ export default class Y extends NamedEventHandler {
* @type {String}
*/
this.room = room
<<<<<<< HEAD:src/Y.js
if (opts != null && opts.connector != null) {
opts.connector.room = room
}
this._contentReady = false
this._opts = opts
if (opts == null || typeof opts.userID !== 'number') {
this.userID = generateRandomUint32()
} else {
this.userID = opts.userID
}
=======
this._contentReady = false
this.userID = generateRandomUint32()
>>>>>>> experimental-connectors:src/Y.mjs
// TODO: This should be a Map so we can use encodables as keys
this.share = {}
this.ds = new DeleteStore(this)