-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add lots of documentation and cleanups
- Loading branch information
Showing
10 changed files
with
686 additions
and
415 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::rc::Rc; | ||
|
||
struct MyProvider { | ||
doc: yrs::Doc | ||
} | ||
|
||
impl yrs::Subscriber<yrs::events::UpdateEvent> for MyProvider { | ||
fn on_change (&self, event: yrs::events::UpdateEvent) { | ||
self.doc.apply_update(&event.update); | ||
} | ||
} | ||
|
||
fn main () { | ||
let doc1 = yrs::Doc::new(); | ||
let doc2 = yrs::Doc::new(); | ||
|
||
// register update observer | ||
let provider = Rc::from(MyProvider { | ||
doc: doc2.clone() | ||
}); | ||
doc1.on_update(Rc::downgrade(&provider)); | ||
|
||
let my_type = doc1.get_type("my first shared type"); | ||
|
||
{ | ||
// All changes must happen within a transaction. | ||
// When the transaction is dropped, the yrs::Doc fires event (e.g. the update event) | ||
let tr = doc1.transact(); | ||
my_type.insert(&tr, 0, 'a'); | ||
} // transaction is dropped and changes are automatically synced to doc2 | ||
|
||
println!("synced document state: {}", doc2.get_type("my first shared type").to_string()); | ||
assert_eq!(doc2.get_type("my first shared type").to_string(), "a"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.