From 543387018388e56a7482e552aa6eb3fb7f4afae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 3 May 2019 14:04:37 +0200 Subject: [PATCH] add something broken --- .../Routes/Collaboration3/index.vue | 47 +++++++++++++++---- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/examples/Components/Routes/Collaboration3/index.vue b/examples/Components/Routes/Collaboration3/index.vue index cac658d8..471909ec 100644 --- a/examples/Components/Routes/Collaboration3/index.vue +++ b/examples/Components/Routes/Collaboration3/index.vue @@ -47,15 +47,19 @@ export default { // this.editor.view.updateState(this.state.edit) // return false // }, - onUpdate: ({ state }) => { - this.getSendableSteps(state) + onUpdate: ({ state, oldState }) => { + this.getSendableSteps(state, oldState) }, }) }, - getSendableSteps: debounce(function (state) { + getSendableSteps: debounce(function (state, oldState) { const sendable = sendableSteps(state) + console.log('update editor', { sendable }) + + // console.log({ state, oldState }) + if (sendable) { this.socket.emit('update', sendable) @@ -63,7 +67,7 @@ export default { const clientIDs = this.repeat(sendable.clientID, steps.length) this.history.push({ - state, + state: oldState, version: getVersion(state), steps, clientIDs, @@ -116,7 +120,7 @@ export default { console.log('version in sync', version) // TODO remove steps older than version }) - .on('versionMismatch', ({ version, data }) => { + .on('versionMismatch', ({ version, data, doc }) => { console.log('version mismatch', version) // TODO: go back to `version`, apply `steps`, apply unmerged `steps` @@ -124,20 +128,47 @@ export default { const { state, view, schema } = this.editor - view.updateState(history.state) + // view.updateState(history.state) - view.dispatch(receiveTransaction( + console.log('other steps', { data }) + // console.log(getVersion(view.state)) + + const newstate = history.state.apply(receiveTransaction( history.state, data.map(item => Step.fromJSON(schema, item.step)), data.map(item => item.clientID), )) + view.updateState(newstate) + + // const newstate2 = newstate.apply(receiveTransaction( + // newstate, + // history.steps, + // history.clientIDs, + // )) + view.dispatch(receiveTransaction( - history.state, + state, history.steps, history.clientIDs, )) + // view.updateState(newstate2) + + // view.dispatch(receiveTransaction( + // view.state, + // data.map(item => Step.fromJSON(schema, item.step)), + // data.map(item => item.clientID), + // )) + + // console.log('own', { history }) + + // view.dispatch(receiveTransaction( + // history.state, + // history.steps, + // history.clientIDs, + // )) + // const transaction = receiveTransaction( // state, // steps,