Currently many events are emitted synchronously in response to local function calls, for example submitOp emits an op event synchronously. This leads to some unexpected behaviours, for example:
doc.on((op, source) => { if (source === '1') submitOp(op1, '2') })
doc.on((op, source) => console.log(source))
doc.submitOp(op1, '1')
prints:
instead of:
which reflects the actual order of operations.
Here's what happens in the example above:
op1 is submitted.
- An
'op' event is emitted with source '1'.
- The first handler is called with source
'1' and submits op2.
- An
'op' event is emitted with source '2'.
- The first handler is called with source
'2' and exits.
- The second handler is called with source
'2' and prints it.
- The second handler is called with source
'1' and prints it.
In order to deal with this issue perhaps we could use an approach similar to MutationObserver, where synchronous operations are recorded in an Array and then a single event is emitted asynchronously with the list as a parameter?
Related issues:
Currently many events are emitted synchronously in response to local function calls, for example
submitOpemits anopevent synchronously. This leads to some unexpected behaviours, for example:prints:
instead of:
which reflects the actual order of operations.
Here's what happens in the example above:
op1is submitted.'op'event is emitted with source'1'.'1'and submitsop2.'op'event is emitted with source'2'.'2'and exits.'2'and prints it.'1'and prints it.In order to deal with this issue perhaps we could use an approach similar to MutationObserver, where synchronous operations are recorded in an Array and then a single event is emitted asynchronously with the list as a parameter?
Related issues: