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
Copy file name to clipboardExpand all lines: docs/middleware/op-submission.md
+13-5Lines changed: 13 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -140,12 +140,20 @@ Since `'submitRequestEnd'` is an event -- not a middleware hook -- it provides n
140
140
141
141
## Mutating ops
142
142
143
-
{: .warn :}
144
-
Mutating ops in middleware is generally a **bad idea**, and should be avoided.
143
+
Ops may be amended in the `apply` middleware using the special `request.$fixup()` method:
145
144
146
-
The main reason for avoiding op mutation is that the client who submitted the op will not be informed of the mutation, so the client's doc will never receive the mutation.
The general workaround is to trigger a second op submission, rather than mutate the provided op. This obviously has the downside of op submissions being unatomic, but is the safest way to get the original client to receive the update.
154
+
next(error);
155
+
});
156
+
```
149
157
150
158
{: .warn :}
151
-
When submitting ops from the middleware, set careful conditions under which you submit ops in order to avoid infinite op submission loops, where submitting an op recursively triggers infinite op submissions.
159
+
The `request.$fixup()` method may throw an error, which should be handled appropriately, usually by passing directly to the `next()` callback.
0 commit comments