diff --git a/examples/html-editor/index.js b/examples/html-editor/index.js
index 3a7c8b66..4b69b9c8 100644
--- a/examples/html-editor/index.js
+++ b/examples/html-editor/index.js
@@ -4,14 +4,14 @@ window.onload = function () {
window.yXmlType.bindToDom(document.body)
}
-let persistence = new Y.IndexedDBPersistence()
+let persistence = null // new Y.IndexedDBPersistence()
// initialize a shared object. This function call returns a promise!
let y = new Y({
connector: {
name: 'websockets-client',
url: 'http://127.0.0.1:1234',
- room: 'html-editor-example6'
+ room: 'x'
// maxBufferLength: 100
}
}, persistence)
diff --git a/src/Connector.js b/src/Connector.js
index 23c30405..835528c1 100644
--- a/src/Connector.js
+++ b/src/Connector.js
@@ -132,7 +132,7 @@ export default class AbstractConnector {
f()
}
this.whenSyncedListeners = []
- this.y.loaded = true
+ this.y._setContentReady()
this.y.emit('synced')
}
}
diff --git a/src/Persistence.js b/src/Persistence.js
index d44bf9bf..be3acbd4 100644
--- a/src/Persistence.js
+++ b/src/Persistence.js
@@ -24,11 +24,11 @@ export default class AbstractPersistence {
cnf = getFreshCnf()
this.ys.set(y, cnf)
this.init(y)
- y.on('afterTransaction', () => {
+ y.on('afterTransaction', (y, transaction) => {
let cnf = this.ys.get(y)
if (cnf.len > 0) {
cnf.buffer.setUint32(0, cnf.len)
- this.saveUpdate(y, cnf.buffer.createBuffer())
+ this.saveUpdate(y, cnf.buffer.createBuffer(), transaction)
let _cnf = getFreshCnf()
for (let key in _cnf) {
cnf[key] = _cnf[key]
@@ -66,12 +66,12 @@ export default class AbstractPersistence {
y.transact(function () {
if (model != null) {
fromBinary(y, new BinaryDecoder(new Uint8Array(model)))
- y.loaded = true
+ y._setContentReady()
}
if (updates != null) {
for (let i = 0; i < updates.length; i++) {
integrateRemoteStructs(y, new BinaryDecoder(new Uint8Array(updates[i])))
- y.loaded = true
+ y._setContentReady()
}
}
})
diff --git a/src/Y.js b/src/Y.js
index ff00a838..ce83e8a4 100644
--- a/src/Y.js
+++ b/src/Y.js
@@ -21,12 +21,10 @@ 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._contentReady = false
this._opts = opts
this.userID = opts._userID != null ? opts._userID : generateUserID()
this.share = {}
@@ -41,8 +39,9 @@ export default class Y extends NamedEventHandler {
let initConnection = () => {
this.connector = new Y[opts.connector.name](this, opts.connector)
this.connected = true
+ this.emit('connectorReady')
}
- if (persistence !== undefined) {
+ if (persistence != null) {
this.persistence = persistence
persistence._init(this).then(initConnection)
} else {
@@ -50,13 +49,10 @@ 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')
+ _setContentReady () {
+ if (!this._contentReady) {
+ this._contentReady = true
+ this.emit('content')
}
}
_beforeChange () {}
@@ -177,7 +173,7 @@ Y.extend = function extendYjs () {
// TODO: The following assignments should be moved to yjs-dist
Y.AbstractConnector = Connector
-Y.Persisence = Persistence
+Y.AbstractPersistence = Persistence
Y.Array = YArray
Y.Map = YMap
Y.Text = YText