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)
|
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!
|
// initialize a shared object. This function call returns a promise!
|
||||||
let y = new Y({
|
let y = new Y('htmleditor', {
|
||||||
connector: {
|
connector: {
|
||||||
name: 'websockets-client',
|
name: 'websockets-client',
|
||||||
url: 'http://127.0.0.1:1234',
|
url: 'http://127.0.0.1:1234',
|
||||||
room: 'x'
|
room: 'html-editor'
|
||||||
// maxBufferLength: 100
|
// maxBufferLength: 100
|
||||||
}
|
}
|
||||||
}, persistence)
|
}, persistence)
|
||||||
|
@ -1,24 +1,18 @@
|
|||||||
/* global Y, CodeMirror */
|
/* global Y, CodeMirror */
|
||||||
|
|
||||||
// initialize a shared object. This function call returns a promise!
|
const persistence = new Y.IndexedDB()
|
||||||
Y({
|
const connector = {
|
||||||
db: {
|
|
||||||
name: 'memory'
|
|
||||||
},
|
|
||||||
connector: {
|
connector: {
|
||||||
name: 'websockets-client',
|
name: 'websockets-client',
|
||||||
room: 'codemirror-example'
|
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'), {
|
var editor = CodeMirror(document.querySelector('#codeMirrorContainer'), {
|
||||||
mode: 'javascript',
|
mode: 'javascript',
|
||||||
lineNumbers: true
|
lineNumbers: true
|
||||||
})
|
|
||||||
y.share.codemirror.bindCodeMirror(editor)
|
|
||||||
})
|
})
|
||||||
|
y.share.codemirror.bindCodeMirror(editor)
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
import Y from '../src/Y.js'
|
import Y from '../src/Y.js'
|
||||||
import yWebsocketsClient from '../../y-websockets-client/src/y-websockets-client.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.extend(yWebsocketsClient)
|
||||||
Y.IndexedDBPersistence = IndexedDBPersistence
|
extendYIndexedDBPersistence(Y)
|
||||||
|
|
||||||
export default Y
|
export default Y
|
||||||
|
@ -25,24 +25,26 @@ export default class AbstractPersistence {
|
|||||||
if (cnf === undefined) {
|
if (cnf === undefined) {
|
||||||
cnf = getFreshCnf()
|
cnf = getFreshCnf()
|
||||||
this.ys.set(y, cnf)
|
this.ys.set(y, cnf)
|
||||||
this.init(y)
|
return this.init(y).then(() => {
|
||||||
y.on('afterTransaction', (y, transaction) => {
|
y.on('afterTransaction', (y, transaction) => {
|
||||||
let cnf = this.ys.get(y)
|
let cnf = this.ys.get(y)
|
||||||
if (cnf.len > 0) {
|
if (cnf.len > 0) {
|
||||||
cnf.buffer.setUint32(0, cnf.len)
|
cnf.buffer.setUint32(0, cnf.len)
|
||||||
this.saveUpdate(y, cnf.buffer.createBuffer(), transaction)
|
this.saveUpdate(y, cnf.buffer.createBuffer(), transaction)
|
||||||
let _cnf = getFreshCnf()
|
let _cnf = getFreshCnf()
|
||||||
for (let key in _cnf) {
|
for (let key in _cnf) {
|
||||||
cnf[key] = _cnf[key]
|
cnf[key] = _cnf[key]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
return this.retrieve(y)
|
||||||
|
}).then(function () {
|
||||||
|
return Promise.resolve(cnf)
|
||||||
})
|
})
|
||||||
}
|
} else {
|
||||||
return this.retrieve(y).then(function () {
|
|
||||||
return Promise.resolve(cnf)
|
return Promise.resolve(cnf)
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit (y) {
|
deinit (y) {
|
||||||
this.ys.delete(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 RootID from './Util/RootID.js'
|
||||||
import NamedEventHandler from './Util/NamedEventHandler.js'
|
import NamedEventHandler from './Util/NamedEventHandler.js'
|
||||||
import UndoManager from './Util/UndoManager.js'
|
import UndoManager from './Util/UndoManager.js'
|
||||||
|
import { integrateRemoteStructs } from './MessageHandler/integrateRemoteStructs.js'
|
||||||
|
|
||||||
import { messageToString, messageToRoomname } from './MessageHandler/messageToString.js'
|
import { messageToString, messageToRoomname } from './MessageHandler/messageToString.js'
|
||||||
|
|
||||||
@ -192,7 +193,8 @@ Y.utils = {
|
|||||||
UndoManager,
|
UndoManager,
|
||||||
getRelativePosition,
|
getRelativePosition,
|
||||||
fromRelativePosition,
|
fromRelativePosition,
|
||||||
addType
|
addType,
|
||||||
|
integrateRemoteStructs
|
||||||
}
|
}
|
||||||
|
|
||||||
Y.debug = debug
|
Y.debug = debug
|
||||||
|
Loading…
x
Reference in New Issue
Block a user