refactoring
This commit is contained in:
@@ -48,8 +48,10 @@ export default {
|
|||||||
getSendableSteps: debounce(function (state) {
|
getSendableSteps: debounce(function (state) {
|
||||||
const sendable = sendableSteps(state)
|
const sendable = sendableSteps(state)
|
||||||
|
|
||||||
|
this.prevState = state
|
||||||
|
|
||||||
if (sendable) {
|
if (sendable) {
|
||||||
this.socket.emit('message', sendable)
|
this.socket.emit('update', sendable)
|
||||||
|
|
||||||
const transaction = receiveTransaction(
|
const transaction = receiveTransaction(
|
||||||
this.editor.state,
|
this.editor.state,
|
||||||
@@ -82,20 +84,38 @@ export default {
|
|||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.socket = io('wss://tiptap-sockets-2.glitch.me')
|
this.socket = io('wss://tiptap-sockets-2.glitch.me')
|
||||||
|
|
||||||
this.socket
|
|
||||||
.on('connect', () => {
|
.on('connect', () => {
|
||||||
console.log('connected')
|
console.log('connected')
|
||||||
})
|
})
|
||||||
.on('disconnect', () => {
|
.on('disconnect', () => {
|
||||||
console.log('disconnected')
|
console.log('disconnected')
|
||||||
})
|
})
|
||||||
.on('message', data => {
|
.on('document', data => {
|
||||||
if (data.doc) {
|
|
||||||
this.initEditor(data)
|
this.initEditor(data)
|
||||||
} else {
|
})
|
||||||
|
.on('update', data => {
|
||||||
this.receiveData(data)
|
this.receiveData(data)
|
||||||
}
|
})
|
||||||
|
.on('versionMismatch', () => {
|
||||||
|
// set state to the latest synced version?
|
||||||
|
// this.editor.view.updateState(this.prevState)
|
||||||
|
|
||||||
|
const currentVersion = getVersion(this.editor.state)
|
||||||
|
console.log('should poll version', currentVersion)
|
||||||
|
|
||||||
|
this.socket.emit('getVersionSteps', currentVersion)
|
||||||
|
})
|
||||||
|
.on('versionSteps', data => {
|
||||||
|
console.log('versionSteps', data)
|
||||||
|
const { state, view, schema } = this.editor
|
||||||
|
|
||||||
|
const transaction = receiveTransaction(
|
||||||
|
state,
|
||||||
|
data.map(item => Step.fromJSON(schema, item.step)),
|
||||||
|
data.map(item => item.clientID),
|
||||||
|
)
|
||||||
|
|
||||||
|
view.dispatch(transaction)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user