loaded event when loaded from persistence adapter
This commit is contained in:
parent
445dd3e0da
commit
5a68b9f4ad
@ -132,6 +132,7 @@ export default class AbstractConnector {
|
|||||||
f()
|
f()
|
||||||
}
|
}
|
||||||
this.whenSyncedListeners = []
|
this.whenSyncedListeners = []
|
||||||
|
this.y.loaded = true
|
||||||
this.y.emit('synced')
|
this.y.emit('synced')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,10 +66,12 @@ export default class AbstractPersistence {
|
|||||||
y.transact(function () {
|
y.transact(function () {
|
||||||
if (model != null) {
|
if (model != null) {
|
||||||
fromBinary(y, new BinaryDecoder(new Uint8Array(model)))
|
fromBinary(y, new BinaryDecoder(new Uint8Array(model)))
|
||||||
|
y.loaded = true
|
||||||
}
|
}
|
||||||
if (updates != null) {
|
if (updates != null) {
|
||||||
for (let i = 0; i < updates.length; i++) {
|
for (let i = 0; i < updates.length; i++) {
|
||||||
integrateRemoteStructs(y, new BinaryDecoder(new Uint8Array(updates[i])))
|
integrateRemoteStructs(y, new BinaryDecoder(new Uint8Array(updates[i])))
|
||||||
|
y.loaded = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -185,6 +185,9 @@ export default class YXmlFragment extends YArray {
|
|||||||
this._dom._yxml = null
|
this._dom._yxml = null
|
||||||
this._dom = null
|
this._dom = null
|
||||||
}
|
}
|
||||||
|
if (this._beforeTransactionHandler !== undefined) {
|
||||||
|
this._y.off('beforeTransaction', this._beforeTransactionHandler)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
insertDomElementsAfter (prev, doms, _document) {
|
insertDomElementsAfter (prev, doms, _document) {
|
||||||
const types = domToYXml(this, doms, _document)
|
const types = domToYXml(this, doms, _document)
|
||||||
@ -275,9 +278,10 @@ export default class YXmlFragment extends YArray {
|
|||||||
})
|
})
|
||||||
// Apply Dom changes on Y.Xml
|
// Apply Dom changes on Y.Xml
|
||||||
if (typeof MutationObserver !== 'undefined') {
|
if (typeof MutationObserver !== 'undefined') {
|
||||||
this._y.on('beforeTransaction', () => {
|
this._beforeTransactionHandler = () => {
|
||||||
this._domObserverListener(this._domObserver.takeRecords())
|
this._domObserverListener(this._domObserver.takeRecords())
|
||||||
})
|
}
|
||||||
|
this._y.on('beforeTransaction', this._beforeTransactionHandler)
|
||||||
this._domObserverListener = mutations => {
|
this._domObserverListener = mutations => {
|
||||||
this._mutualExclude(() => {
|
this._mutualExclude(() => {
|
||||||
this._y.transact(() => {
|
this._y.transact(() => {
|
||||||
|
@ -27,7 +27,8 @@ export default class NamedEventHandler {
|
|||||||
}
|
}
|
||||||
const listener = this._eventListener.get(name)
|
const listener = this._eventListener.get(name)
|
||||||
if (listener !== undefined) {
|
if (listener !== undefined) {
|
||||||
listener.remove(f)
|
listener.on.delete(f)
|
||||||
|
listener.once.delete(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
emit (name, ...args) {
|
emit (name, ...args) {
|
||||||
|
12
src/Y.js
12
src/Y.js
@ -21,9 +21,12 @@ import { addStruct as addType } from './Util/structReferences.js'
|
|||||||
import debug from 'debug'
|
import debug from 'debug'
|
||||||
import Transaction from './Transaction.js'
|
import Transaction from './Transaction.js'
|
||||||
|
|
||||||
|
import YIndexedDB from '../../y-indexeddb/src/y-indexeddb.js'
|
||||||
|
|
||||||
export default class Y extends NamedEventHandler {
|
export default class Y extends NamedEventHandler {
|
||||||
constructor (opts, persistence) {
|
constructor (opts, persistence) {
|
||||||
super()
|
super()
|
||||||
|
this._loaded = false
|
||||||
this._opts = opts
|
this._opts = opts
|
||||||
this.userID = opts._userID != null ? opts._userID : generateUserID()
|
this.userID = opts._userID != null ? opts._userID : generateUserID()
|
||||||
this.share = {}
|
this.share = {}
|
||||||
@ -47,6 +50,15 @@ export default class Y extends NamedEventHandler {
|
|||||||
initConnection()
|
initConnection()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
get loaded () {
|
||||||
|
return this._loaded
|
||||||
|
}
|
||||||
|
set loaded (val) {
|
||||||
|
if (this._loaded === false && val) {
|
||||||
|
this._loaded = true
|
||||||
|
this.emit('loaded')
|
||||||
|
}
|
||||||
|
}
|
||||||
_beforeChange () {}
|
_beforeChange () {}
|
||||||
transact (f, remote = false) {
|
transact (f, remote = false) {
|
||||||
let initialCall = this._transaction === null
|
let initialCall = this._transaction === null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user