persistence updates + make Persistence.init async
This commit is contained in:
parent
c8f0cf5556
commit
0b510b64a3
@ -4,14 +4,14 @@ window.onload = function () {
|
||||
window.yXmlType.bindToDom(document.body)
|
||||
}
|
||||
|
||||
let persistence = null // new Y.IndexedDBPersistence()
|
||||
const persistence = new Y.IndexedDB()
|
||||
|
||||
// initialize a shared object. This function call returns a promise!
|
||||
let y = new Y({
|
||||
let y = new Y('htmleditor', {
|
||||
connector: {
|
||||
name: 'websockets-client',
|
||||
url: 'http://127.0.0.1:1234',
|
||||
room: 'x'
|
||||
room: 'html-editor'
|
||||
// maxBufferLength: 100
|
||||
}
|
||||
}, persistence)
|
||||
|
@ -1,24 +1,18 @@
|
||||
/* global Y, CodeMirror */
|
||||
|
||||
// initialize a shared object. This function call returns a promise!
|
||||
Y({
|
||||
db: {
|
||||
name: 'memory'
|
||||
},
|
||||
const persistence = new Y.IndexedDB()
|
||||
const connector = {
|
||||
connector: {
|
||||
name: 'websockets-client',
|
||||
room: 'codemirror-example'
|
||||
},
|
||||
sourceDir: '/bower_components',
|
||||
share: {
|
||||
codemirror: 'Text' // y.share.codemirror is of type Y.Text
|
||||
}
|
||||
}).then(function (y) {
|
||||
window.yCodeMirror = y
|
||||
}
|
||||
// initialize a shared object. This function call returns a promise!
|
||||
const y = Y('codemirror-example', connector, persistence)
|
||||
window.yCodeMirror = y
|
||||
|
||||
var editor = CodeMirror(document.querySelector('#codeMirrorContainer'), {
|
||||
mode: 'javascript',
|
||||
lineNumbers: true
|
||||
})
|
||||
y.share.codemirror.bindCodeMirror(editor)
|
||||
var editor = CodeMirror(document.querySelector('#codeMirrorContainer'), {
|
||||
mode: 'javascript',
|
||||
lineNumbers: true
|
||||
})
|
||||
y.share.codemirror.bindCodeMirror(editor)
|
||||
|
@ -1,9 +1,9 @@
|
||||
|
||||
import Y from '../src/Y.js'
|
||||
import yWebsocketsClient from '../../y-websockets-client/src/y-websockets-client.js'
|
||||
import IndexedDBPersistence from '../../y-indexeddb/src/y-indexeddb.js'
|
||||
import extendYIndexedDBPersistence from '../../y-indexeddb/src/y-indexeddb.js'
|
||||
|
||||
Y.extend(yWebsocketsClient)
|
||||
Y.IndexedDBPersistence = IndexedDBPersistence
|
||||
extendYIndexedDBPersistence(Y)
|
||||
|
||||
export default Y
|
||||
|
@ -25,24 +25,26 @@ export default class AbstractPersistence {
|
||||
if (cnf === undefined) {
|
||||
cnf = getFreshCnf()
|
||||
this.ys.set(y, cnf)
|
||||
this.init(y)
|
||||
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(), transaction)
|
||||
let _cnf = getFreshCnf()
|
||||
for (let key in _cnf) {
|
||||
cnf[key] = _cnf[key]
|
||||
return this.init(y).then(() => {
|
||||
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(), transaction)
|
||||
let _cnf = getFreshCnf()
|
||||
for (let key in _cnf) {
|
||||
cnf[key] = _cnf[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
return this.retrieve(y)
|
||||
}).then(function () {
|
||||
return Promise.resolve(cnf)
|
||||
})
|
||||
}
|
||||
return this.retrieve(y).then(function () {
|
||||
} else {
|
||||
return Promise.resolve(cnf)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
deinit (y) {
|
||||
this.ys.delete(y)
|
||||
}
|
||||
|
4
src/Y.js
4
src/Y.js
@ -5,6 +5,7 @@ import { generateUserID } from './Util/generateUserID.js'
|
||||
import RootID from './Util/RootID.js'
|
||||
import NamedEventHandler from './Util/NamedEventHandler.js'
|
||||
import UndoManager from './Util/UndoManager.js'
|
||||
import { integrateRemoteStructs } from './MessageHandler/integrateRemoteStructs.js'
|
||||
|
||||
import { messageToString, messageToRoomname } from './MessageHandler/messageToString.js'
|
||||
|
||||
@ -192,7 +193,8 @@ Y.utils = {
|
||||
UndoManager,
|
||||
getRelativePosition,
|
||||
fromRelativePosition,
|
||||
addType
|
||||
addType,
|
||||
integrateRemoteStructs
|
||||
}
|
||||
|
||||
Y.debug = debug
|
||||
|
Loading…
x
Reference in New Issue
Block a user