loaded event when loaded from persistence adapter

This commit is contained in:
Kevin Jahns 2018-01-08 02:28:46 +01:00
parent 445dd3e0da
commit 5a68b9f4ad
5 changed files with 23 additions and 3 deletions

View File

@ -132,6 +132,7 @@ export default class AbstractConnector {
f()
}
this.whenSyncedListeners = []
this.y.loaded = true
this.y.emit('synced')
}
}

View File

@ -66,10 +66,12 @@ export default class AbstractPersistence {
y.transact(function () {
if (model != null) {
fromBinary(y, new BinaryDecoder(new Uint8Array(model)))
y.loaded = true
}
if (updates != null) {
for (let i = 0; i < updates.length; i++) {
integrateRemoteStructs(y, new BinaryDecoder(new Uint8Array(updates[i])))
y.loaded = true
}
}
})

View File

@ -185,6 +185,9 @@ export default class YXmlFragment extends YArray {
this._dom._yxml = null
this._dom = null
}
if (this._beforeTransactionHandler !== undefined) {
this._y.off('beforeTransaction', this._beforeTransactionHandler)
}
}
insertDomElementsAfter (prev, doms, _document) {
const types = domToYXml(this, doms, _document)
@ -275,9 +278,10 @@ export default class YXmlFragment extends YArray {
})
// Apply Dom changes on Y.Xml
if (typeof MutationObserver !== 'undefined') {
this._y.on('beforeTransaction', () => {
this._beforeTransactionHandler = () => {
this._domObserverListener(this._domObserver.takeRecords())
})
}
this._y.on('beforeTransaction', this._beforeTransactionHandler)
this._domObserverListener = mutations => {
this._mutualExclude(() => {
this._y.transact(() => {

View File

@ -27,7 +27,8 @@ export default class NamedEventHandler {
}
const listener = this._eventListener.get(name)
if (listener !== undefined) {
listener.remove(f)
listener.on.delete(f)
listener.once.delete(f)
}
}
emit (name, ...args) {

View File

@ -21,9 +21,12 @@ import { addStruct as addType } from './Util/structReferences.js'
import debug from 'debug'
import Transaction from './Transaction.js'
import YIndexedDB from '../../y-indexeddb/src/y-indexeddb.js'
export default class Y extends NamedEventHandler {
constructor (opts, persistence) {
super()
this._loaded = false
this._opts = opts
this.userID = opts._userID != null ? opts._userID : generateUserID()
this.share = {}
@ -47,6 +50,15 @@ export default class Y extends NamedEventHandler {
initConnection()
}
}
get loaded () {
return this._loaded
}
set loaded (val) {
if (this._loaded === false && val) {
this._loaded = true
this.emit('loaded')
}
}
_beforeChange () {}
transact (f, remote = false) {
let initialCall = this._transaction === null