Commit a14175d
Alec Gibson
Add batch op events
This change adds two events:
- `before op batch` - fired once before any set of ops is applied.
- `op batch` - fired once after any set of ops is applied. This may
follow multiple `op` events if the op had multiple `json0` components
This is a non-breaking change that should allow clients to process ops
in their entirety.
There has already been some discussion around this:
- #129
- #396
This is a much simpler approach than the existing pull request. Here we
try not to change existing behaviour, and only add new, non-breaking
events.
Motivation for such an event would include clients applying some form of
validation logic, which doesn't make sense if an op is shattered.
For example, consider a client that wants to ensure a field
`mustBePresent` is always populated:
```js
doc.on('op', () => {
if (!doc.data.mustBePresent) throw new Error('invalid');
});
remoteDoc.submitOp([
{p: ['mustBePresent', 0], sd: 'existing value'},
{p: ['mustBePresent', 0], si: 'new value'},
]);
```
In the above example, the submitted op is clearly attempting to perform
a replacement. However, the receiving `doc` only receives this
replacement in parts, so it looks like the document reaches an invalid
state, when actually the submitted op is perfectly valid.
In this case we `throw`, but we could have also attempted to populate
with a default value, which could interfere with the desired value.
This change fixes the above issue, because now we can just listen for
the `op batch` event, and consider the document once all the components
of a given op have been applied.1 parent 346eb0c commit a14175d
3 files changed
+69
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
364 | 364 | | |
365 | 365 | | |
366 | 366 | | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
367 | 373 | | |
368 | 374 | | |
369 | 375 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
581 | 581 | | |
582 | 582 | | |
583 | 583 | | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
584 | 588 | | |
585 | 589 | | |
586 | 590 | | |
| |||
614 | 618 | | |
615 | 619 | | |
616 | 620 | | |
| 621 | + | |
617 | 622 | | |
618 | 623 | | |
619 | 624 | | |
| |||
630 | 635 | | |
631 | 636 | | |
632 | 637 | | |
| 638 | + | |
633 | 639 | | |
634 | 640 | | |
635 | 641 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
266 | 267 | | |
267 | 268 | | |
268 | 269 | | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
269 | 326 | | |
270 | 327 | | |
271 | 328 | | |
| |||
0 commit comments