Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent order of events #233

Open
gkubisa opened this issue Jul 30, 2018 · 0 comments
Open

Inconsistent order of events #233

gkubisa opened this issue Jul 30, 2018 · 0 comments

Comments

@gkubisa
Copy link
Contributor

gkubisa commented Jul 30, 2018

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:

2
1

instead of:

1
2

which reflects the actual order of operations.

Here's what happens in the example above:

  1. op1 is submitted.
  2. An 'op' event is emitted with source '1'.
  3. The first handler is called with source '1' and submits op2.
  4. An 'op' event is emitted with source '2'.
  5. The first handler is called with source '2' and exits.
  6. The second handler is called with source '2' and prints it.
  7. 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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant