Skip to content

Commit

Permalink
fix: add explanation about mutation behavior to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin-Alexa Robinson committed Dec 5, 2024
1 parent 5a8a6aa commit 0bc252a
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/@atjson/peritext/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ let doc = block(Div, {}, (paragraph = block(Paragraph, {}, "Hello!")));

return insertBefore(doc, paragraph.getValue().id, HorizontalRule, {});
```

## Mutation

All of the functions that construct and modify documents have the property that they shallowly copy any _peritext documents_ in their arguments, but **directly mutate** any _blocks_ and _marks_ on that document. This potentially-surprising behavior is intentional: this way, one can store the results of intermediate build steps and any such references to marks and blocks in the document will remain accurate after applying further build steps. documents are shallowly-copied in order for the behavior of functions like `concat` (which take multiple document objects and so could only mutate one of them anyway) to be consistent with the behavior of functions like `groupChildren` (which could in principle simply mutate the input document directly)

0 comments on commit 0bc252a

Please sign in to comment.