From eac754016eb8ec2d441bee7cfc952742edec744f Mon Sep 17 00:00:00 2001 From: Zixuan Chen Date: Sun, 10 Nov 2024 00:16:56 +0800 Subject: [PATCH] docs: update readme --- crates/loro-wasm/README.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/crates/loro-wasm/README.md b/crates/loro-wasm/README.md index 6ba43dba..9ab8c6f0 100644 --- a/crates/loro-wasm/README.md +++ b/crates/loro-wasm/README.md @@ -42,11 +42,11 @@ ✨ Loro 1.0 is out! Read the announcement. -Loro is a [CRDTs(Conflict-free Replicated Data Types)](https://crdt.tech/) library that makes building [local-first apps][local-first] easier. It is currently available for JavaScript (via WASM) and Rust developers. +Loro is a [CRDTs(Conflict-free Replicated Data Types)](https://crdt.tech/) library that makes building [local-first][local-first] and collaborative apps easier. You can now use it in Rust, JS (via WASM), and Swift. # Features -**Basic Features Provided by CRDTs** +**Features Provided by CRDTs** - P2P Synchronization - Automatic Merging @@ -61,10 +61,10 @@ Loro is a [CRDTs(Conflict-free Replicated Data Types)](https://crdt.tech/) libra - 🌲 [Moveable Tree](https://loro.dev/docs/tutorial/tree) - πŸš— [Moveable List](https://loro.dev/docs/tutorial/list) - πŸ—ΊοΈ [Last-Write-Wins Map](https://loro.dev/docs/tutorial/map) -- πŸ”„ [Replayable Event Graph](https://loro.dev/docs/advanced/replayable_event_graph) **Advanced Features in Loro** +- πŸš€ [Fast Document Loading](https://loro.dev/blog/v1.0) - ⏱️ Fast [Time Travel](https://loro.dev/docs/tutorial/time_travel) Through History - πŸ›οΈ [Version Control with Real-Time Collaboration](https://loro.dev/blog/v1.0#version-control) - πŸ“¦ [Shallow Snapshot](https://loro.dev/docs/advanced/shallow_snapshot) that Works like Git Shallow Clone @@ -82,9 +82,8 @@ import { expect, test } from 'vitest'; import { LoroDoc, LoroList } from 'loro-crdt'; test('sync example', () => { - /** - * Demonstrates synchronization of two documents with two rounds of exchanges. - */ + // Sync two docs with two rounds of exchanges + // Initialize document A const docA = new LoroDoc(); const listA: LoroList = docA.getList('list'); @@ -92,34 +91,36 @@ test('sync example', () => { listA.insert(1, 'B'); listA.insert(2, 'C'); - // Export the state of document A as a byte array + // Export all updates from docA const bytes: Uint8Array = docA.export({ mode: 'update' }); // Simulate sending `bytes` across the network to another peer, B + const docB = new LoroDoc(); // Peer B imports the updates from A docB.import(bytes); - // Verify that B's state matches A's state + // B's state matches A's state expect(docB.toJSON()).toStrictEqual({ list: ['A', 'B', 'C'], }); - // Get the current operation log version of document B + // Get the current version of docB const version = docB.oplogVersion(); // Simulate editing at B: delete item 'B' const listB: LoroList = docB.getList('list'); listB.delete(1, 1); - // Export the updates from B since the last synchronization point + // Export the updates from B since the last sync point const bytesB: Uint8Array = docB.export({ mode: 'update', from: version }); // Simulate sending `bytesB` back across the network to A + // A imports the updates from B docA.import(bytesB); - // Verify that the list at A now matches the list at B after merging + // A has the same state as B expect(docA.toJSON()).toStrictEqual({ list: ['A', 'C'], });