Skip to content

Commit

Permalink
📝 Add documentions about compering old and new version of snapshot
Browse files Browse the repository at this point in the history
As per this discussion:
- #667 (comment)
  • Loading branch information
Dawidpol committed Jul 9, 2024
1 parent dcef549 commit 1c146b8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/middleware/op-submission.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,21 @@ backend.use('apply', (request, next) => {

{: .warn :}
The `request.$fixup()` method may throw an error, which should be handled appropriately, usually by passing directly to the `next()` callback.

## Comparing old snapshot version with new version

Frequently, it becomes necessary to verify the changes made. This can be accomplished by leveraging two hooks, `apply` and `commit`, and creating a snapshot clone within the `apply` hook.

```js
backend.use('apply', (request, next) => {
request.snapshotBeforeApply = utils.clone(request.snapshot);
next(error);
});

backend.use('commit', (request, next) => {
// Snapshot without ops and $fixupOps applied is now available as snapshotBeforeApply
// Snapshot with ops and $fixupOps applied is still available as snapshot
console.log(request.snapshotBeforeApply)
next(error);
});
```

0 comments on commit 1c146b8

Please sign in to comment.