From fa3c92f44c96d72a3a129fc58fb088f9594fa857 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Fri, 19 Apr 2019 23:36:00 +0200 Subject: [PATCH] change parameter order of transaction events --- README.v13.md | 23 +++++++++++++++-------- src/utils/Transaction.js | 8 ++++---- src/utils/Y.js | 15 +++++++++++++++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/README.v13.md b/README.v13.md index 109fa107..ae8b1fde 100644 --- a/README.v13.md +++ b/README.v13.md @@ -11,15 +11,22 @@ Yjs is **network agnostic** (p2p!), supports many existing **rich text editors** ### Supported Editors: -| Name                                                   | Cursors | Demo | -|---|:-:|---| -| [ProseMirror](https://prosemirror.net/) | ✔ | [link](https://yjs.website/tutorial-prosemirror.html) | -| [Quill](https://quilljs.com/) | | [link](https://yjs.website/tutorial-quill.html) | -| [CodeMirror](https://codemirror.net/) | ✔ | [link](https://yjs.website/tutorial-codemirror.html) | -| [Ace](https://ace.c9.io/) | | [link]() | -| [Monaco](https://microsoft.github.io/monaco-editor/) | | [link]() | +| Name                                                   | Cursors | Binding | Demo | +|---|:-:|---|---| +| [ProseMirror](https://prosemirror.net/) | ✔ | [y-prosemirror](http://github.com/y-js/y-prosemirror) | [link](https://yjs.website/tutorial-prosemirror.html) | +| [Quill](https://quilljs.com/) | | [y-quill](http://github.com/y-js/y-quill) | [link](https://yjs.website/tutorial-quill.html) | +| [CodeMirror](https://codemirror.net/) | ✔ | [y-codemirror](http://github.com/y-js/y-codemirror) | [link](https://yjs.website/tutorial-codemirror.html) | +| [Ace](https://ace.c9.io/) | | [y-ace](http://github.com/y-js/y-ace) | [link]() | +| [Monaco](https://microsoft.github.io/monaco-editor/) | | [y-monaco](http://github.com/y-js/y-monaco) | [link]() | + +### Providers + +Setting up the communication between clients, managing awareness information, and storing shared data for offline usage is quite a hassle. *Providers* manage all that for you and are a good off-the-shelf solution + +* [y-websockets](http://github.com/y-js/y-websockets) +* [y-webrtc](http://github.com/y-js/y-webrtc) +* [y-dat](http://github.com/y-js/y-dat) -### Network providers ### Shared Types diff --git a/src/utils/Transaction.js b/src/utils/Transaction.js index 94793fca..68221ef7 100644 --- a/src/utils/Transaction.js +++ b/src/utils/Transaction.js @@ -133,7 +133,7 @@ export const transact = (y, f) => { if (y._transaction === null) { initialCall = true y._transaction = new Transaction(y) - y.emit('beforeTransaction', [y, y._transaction]) + y.emit('beforeTransaction', [y._transaction, y]) } const transaction = y._transaction try { @@ -141,7 +141,7 @@ export const transact = (y, f) => { } finally { if (initialCall) { y._transaction = null - y.emit('beforeObserverCalls', [y, y._transaction]) + y.emit('beforeObserverCalls', [transaction, y]) // emit change events on changed types transaction.changed.forEach((subs, itemtype) => { itemtype._callObserver(transaction, subs) @@ -167,7 +167,7 @@ export const transact = (y, f) => { const ds = transaction.deleteSet // replace deleted items with ItemDeleted / GC sortAndMergeDeleteSet(ds) - y.emit('afterTransaction', [y, transaction]) + y.emit('afterTransaction', [transaction, y]) for (const [client, deleteItems] of ds.clients) { /** * @type {Array} @@ -238,7 +238,7 @@ export const transact = (y, f) => { tryToMergeWithLeft(structs, replacedStructPos) } } - y.emit('afterTransactionCleanup', [y, transaction]) + y.emit('afterTransactionCleanup', [transaction, y]) } } } diff --git a/src/utils/Y.js b/src/utils/Y.js index fe49b82d..ea8a7d6d 100644 --- a/src/utils/Y.js +++ b/src/utils/Y.js @@ -27,6 +27,7 @@ export class Y extends Observable { */ constructor (conf = {}) { super() + // todo: change to clientId this.clientID = random.uint32() /** * @type {Map>} @@ -151,4 +152,18 @@ export class Y extends Observable { this.emit('destroyed', [true]) super.destroy() } + /** + * @param {string} eventName + * @param {function} f + */ + on (eventName, f) { + super.on(eventName, f) + } + /** + * @param {string} eventName + * @param {function} f + */ + off (eventName, f) { + super.off(eventName, f) + } }