Skip to content

Commit b18cde7

Browse files
committed
docs: refine docs
1 parent 3ecb5ac commit b18cde7

File tree

3 files changed

+11
-40
lines changed

3 files changed

+11
-40
lines changed

pages/docs/concepts/attached_detached.mdx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ doc.getText("text").insert(2, " -> v2");
4545
doc.checkout(v1);
4646
console.log(doc.isDetached()); // true
4747
console.log(doc.getText("text").toString()); // "v1"
48+
```
4849

4950

5051
## Container States
5152

5253
### Detached (Standalone)
5354
- Created with constructors (`new LoroMap()`)
5455
- Not part of any document
55-
- No ContainerID
56+
- No valid ContainerID
5657
- Used as templates
5758

5859
```ts twoslash
@@ -87,7 +88,7 @@ console.log(attached.isAttached()); // true - new attached copy
8788
| **Purpose** | Version control | Document membership |
8889
| **When** | Time travel, branching | Adding to document |
8990
| **Independence** | N/A | Independent from doc state |
90-
| **Editing** | Restricted when detached | Always allowed if attached |
91+
| **Editing** | Restricted when detached | Always allowed |
9192

9293
## Common Use Cases
9394

@@ -116,15 +117,8 @@ list.insertContainer(0, template);
116117
list.insertContainer(1, template);
117118
```
118119

119-
## Best Practices
120-
121-
- **Check before editing**: `if (doc.isDetached()) doc.attach()`
122-
- **Use templates**: Keep containers detached for reuse
123-
- **Remember attachment is one-way**: Original stays detached
124-
- **Re-attach after time travel**: Don't forget to return to latest
125-
126120
## Related Documentation
127121

128122
- [OpLog and DocState](./oplog_docstate) - Understanding version states
129123
- [Containers](./container) - Container types and usage
130-
- [Time Travel](../user-guide/time-travel) - Using checkout and branching
124+
- [Time Travel](../user-guide/time-travel) - Using checkout and branching

pages/docs/concepts/cursor_stable_positions.mdx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ description: "Understanding cursor and stable position systems in Loro for maint
77

88
## Quick Reference
99

10-
**Cursors** maintain stable positions across concurrent edits by anchoring to operation IDs instead of indices. Essential for collaborative editing features like shared cursors and persistent annotations.
10+
**Cursors** maintain stable positions across concurrent edits by anchoring to operation IDs instead of indices. Essential for collaborative editing features like collaborative cursors and persistent annotations.
1111

1212
## How It Works
1313

14-
Cursors anchor to operation IDs, not indices:
14+
Cursors anchor to operation IDs and ContainerIDs, not indices:
1515

1616
```
1717
Text: H e l l o W o r l d
@@ -40,9 +40,10 @@ text.insert(0, "ABC");
4040
const cursor = text.getCursor(1, -1); // Before 'B'
4141
text.insert(1, "X"); // Insert at cursor
4242
// Result: "AXBC", cursor still before 'B'
43+
const pos = text.getCursorPos(cursor);
44+
console.log(pos); // { offset: 2, side: Side.Before }
4345
```
4446

45-
4647
## Common Use Cases
4748

4849
### Text Selections
@@ -66,15 +67,14 @@ const doc = new LoroDoc();
6667
const list = doc.getList("items");
6768
list.insert(0, ["a", "b", "c"]);
6869

69-
const cursor = list.getCursor(1, 0); // After "a"
70+
const cursor = list.getCursor(0, 1); // After "a"
7071
list.insert(0, "new"); // Cursor adjusts automatically
7172
```
7273

7374
## Code Example
7475

7576
```ts twoslash
7677
import { LoroDoc, LoroText, Cursor } from "loro-crdt";
77-
// ---cut---
7878
class CollaborativeSelection {
7979
private anchor!: Cursor;
8080
private head!: Cursor;
@@ -105,15 +105,8 @@ class CollaborativeSelection {
105105
}
106106
```
107107

108-
## Best Practices
109-
110-
- **Side parameters**: Use -1 for starts, 1 for ends, 0 for simple positions
111-
- **Handle updates**: Check for and persist cursor updates
112-
- **Account for deletions**: Check `position.side` for deleted content
113-
- **UTF-16 awareness**: Emoji and special chars use multiple indices
114-
115108
## Related Documentation
116109

117110
- [Text Container](../containers/text) - Text editing with cursors
118111
- [Collaborative Editing](../user-guide/collaborative-editing) - Building editors
119-
- [Events](../user-guide/events) - Cursor change events
112+
- [Events](../user-guide/events) - Cursor change events

pages/docs/concepts/event_graph_walker.mdx

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,14 @@ Eg-Walker handles this by:
120120

121121
| Aspect | Traditional CRDT | Eg-Walker |
122122
|--------|-----------------|-----------|
123-
| Per-operation metadata | 20-50 bytes | 4-8 bytes |
124123
| Tombstone storage | Permanent | Can be garbage collected |
125124
| Document growth | Linear with all operations | Linear with active operations |
126125

127126
### 2. **Faster Local Updates**
128127

129128
- **No metadata computation**: Direct index-based operations
130129
- **No tombstone traversal**: Clean document state
131-
- **Predictable performance**: O(1) for most local operations
130+
- **Predictable performance**: O(1) or O(logN) for most local operations
132131

133132
### 3. **Efficient Synchronization**
134133

@@ -184,18 +183,3 @@ The algorithm has been proven to:
184183
- Maintain strong eventual consistency
185184
- Preserve all CRDT correctness properties
186185
- Significantly reduce computational and storage overhead
187-
188-
## Key Takeaways
189-
190-
1. **Simplicity**: Replace complex metadata with simple indices
191-
2. **Efficiency**: Replay only what's necessary, when necessary
192-
3. **Scalability**: Bounded storage growth with safe garbage collection
193-
4. **Performance**: Fast local operations, efficient synchronization
194-
5. **Innovation**: Fundamental rethinking of CRDT implementation
195-
196-
Eg-Walker represents a breakthrough in collaborative editing technology, making CRDTs more practical and performant for real-world applications. While Loro is not a strict Eg-Walker implementation, it has been profoundly influenced by Eg-Walker's design philosophy and achieves many of the same benefits through this inspiration. By cleverly leveraging the causal history already present in collaborative systems, both Eg-Walker and Loro-inspired approaches achieve the seemingly impossible: simpler data structures with better performance.
197-
198-
[Lamport]: https://en.wikipedia.org/wiki/Lamport_timestamp
199-
[Fugue]: https://arxiv.org/abs/2305.00583
200-
[RGA algorithm]: https://www.sciencedirect.com/science/article/abs/pii/S0743731510002716
201-
[Yjs]: https://github.com/yjs/yjs

0 commit comments

Comments
 (0)