You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `Doc` op events are currently a little confusing: a `json0` "op" can
be shattered into multiple "component ops".
In the current naming, the "op" emits a `'op batch'` event, and the
"op component" emits an `'op'` event.
However, calling the op an "op batch" is a little bit misleading,
because the "batch" is always an op representing a single version number
increase, and potentially considered a single conceptual change.
For example, a remote client might submit a single op:
```js
[
{p: ['a'], oi: 'foo'},
{p: ['b'], oi: 'bar'},
]
```
Under the **current** naming scheme, this emits the following events:
1 `'before op batch'`: `[{p: ['a'], oi: 'foo'}, {p: ['b'], oi: 'bar'}]`
2 `'before op'`: `[{p: ['a'], oi: 'foo'}]`
3 `'op'`: `[{p: ['a'], oi: 'foo'}]`
4 `'before op'`: `[{p: ['b'], oi: 'bar'}]`
5 `'op'`: `[{p: ['b'], oi: 'bar'}]`
6 `'op batch'`: `[{p: ['a'], oi: 'foo'}, {p: ['b'], oi: 'bar'}]`
This can be considered a little surprising, and you may expect the
`'op'` event to be emitted after the whole op (not its shattered
components) have been applied.
Under the **new** naming scheme, the following events are emitted:
1 `'beforeOp'`: `[{p: ['a'], oi: 'foo'}, {p: ['b'], oi: 'bar'}]`
2 `'beforeOpComponent'`: `[{p: ['a'], oi: 'foo'}]`
3 `'opComponent'`: `[{p: ['a'], oi: 'foo'}]`
4 `'beforeOpComponent'`: `[{p: ['b'], oi: 'bar'}]`
5 `'opComponent'`: `[{p: ['b'], oi: 'bar'}]`
6 `'op'`: `[{p: ['a'], oi: 'foo'}, {p: ['b'], oi: 'bar'}]`
This way, you get the `'op'` event after the whole op has been applied.
It also makes it more explicit that you're actively listening out for
the shattered op components where applicable.
Note that we also move the events to camelCase to be consistent with
the Backend middleware actions.
The difference between thisevent and [`'op batch'`](#op-batch) is that for [`json0`]({{ site.baseurl }}{% link types/json0.md%}), the op will be shattered into its constituent parts.
400
+
The difference between thisevent and [`'op'`](#op) is that for [`json0`]({{ site.baseurl }}{% link types/json0.md%}), the op will be shattered into its constituent parts.
401
401
<br/>
402
402
For example, `[{p: ['list', 0], li: 'a'}, {p: ['list', 1], li: 'b'}]` would be split into two components:`[{p: ['list', 0], li: 'a'}]` and `[{p: ['list', 1], li: 'b'}]`.
403
403
<br/>
404
-
The `'op'`event will be called once for each of these op components, but `'op batch'` will only be called once.
404
+
The `'opComponent'`event will be called once for each of these op components, but `'op'` will only be called once.
405
405
406
406
`op`--Object
407
407
@@ -411,12 +411,12 @@ The `'op'` event will be called once for each of these op components, but `'op b
411
411
412
412
> {{ page.copy.event_source }}
413
413
414
-
### `'before op batch'`
414
+
### `'beforeOp'`
415
415
416
416
A potentially multi-part operation is about to be applied to the [`data`](#data--object).
417
417
418
418
```js
419
-
doc.on('before op batch', function(op, source) { ... })
0 commit comments