Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated yrs bindings to use version 0.17.2 #35

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions examples/Tuist/Dependencies.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import ProjectDescription

let packages: [Package] = [
.package(url: "https://github.com/y-crdt/yswift", from: "0.1.0"),
]
let dependencies = Dependencies(
swiftPackageManager: [
.remote(url: "https://github.com/y-crdt/yswift", requirement: .upToNextMajor(from: "0.1.0")),
],
swiftPackageManager: SwiftPackageManagerDependencies(
packages
),
platforms: [.iOS]
)
3 changes: 1 addition & 2 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ members = [
]

[dependencies]
lib0 = "0.16.4" # must match yrs version
thiserror = "1.0.38"
uniffi = "0.23.0"
yrs = "0.16.4"
yrs = "0.17.2"

[build-dependencies]
uniffi = { version = "0.23.0", features = [ "build" ] }
Expand Down
5 changes: 1 addition & 4 deletions lib/src/array.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use crate::transaction::YrsTransaction;
use crate::{change::YrsChange, error::CodingError};
use lib0::any::Any;
use std::cell::RefCell;
use std::fmt::Debug;
use std::sync::Arc;
use yrs::types::array::ArrayIter;
use yrs::{types::Value, Array, ArrayRef, Observable};
use yrs::{types::Value, Any, Array, ArrayRef, Observable};

pub(crate) struct YrsArray(RefCell<ArrayRef>);

Expand Down
14 changes: 9 additions & 5 deletions lib/src/attrs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use lib0::any::Any;
use std::collections::HashMap;
use std::ops::{Deref, DerefMut};
use std::rc::Rc;
use std::sync::Arc;
use yrs::types::Attrs;
use yrs::Any;

pub(crate) struct YrsAttrs(pub(crate) Attrs);

Expand All @@ -15,7 +16,10 @@ impl From<String> for YrsAttrs {
fn from(value: String) -> YrsAttrs {
let any = Any::from_json(value.as_str()).unwrap();
match any {
Any::Map(m) => YrsAttrs(m.into_iter().map(|(k, v)| (Rc::from(&k[..]), v)).collect()),
Any::Map(m) => {
let owned = Arc::try_unwrap(m).unwrap(); // unwrap is safe, we just deserialized this value
YrsAttrs(owned.into_iter().map(|(k, v)| (Arc::from(k), v)).collect())
},
_ => YrsAttrs(Attrs::new()),
}
}
Expand All @@ -24,12 +28,12 @@ impl From<String> for YrsAttrs {
impl From<YrsAttrs> for String {
fn from(value: YrsAttrs) -> String {
let mut buf = String::new();
let attrs_map = value
let attrs_map: HashMap<_,_> = value
.0
.iter()
.map(|(k, v)| (k.to_string(), v.clone()))
.collect();
let any_map = Any::Map(Box::new(attrs_map));
let any_map = Any::from(attrs_map);
any_map.to_json(&mut buf);
buf
}
Expand Down
1 change: 0 additions & 1 deletion lib/src/delta.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::attrs::YrsAttrs;
use std::collections::HashMap;
use yrs::types::{Delta, Value};

pub enum YrsDelta {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ unsafe impl Sync for YrsDoc {}
impl YrsDoc {
pub(crate) fn new() -> Self {
let mut options = Options::default();
options.offset_kind = OffsetKind::Utf32;
options.offset_kind = OffsetKind::Utf16;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We dropped support for Utf32, as it's wasn't used and it's not really useful. If Swift is using proper unicode, there are code points even longer than 4 bytes.

let doc = yrs::Doc::with_options(options);

Self(RefCell::from(doc))
Expand Down
1 change: 0 additions & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ mod transaction;

use crate::array::YrsArray;
use crate::array::YrsArrayEachDelegate;
// use crate::array::YrsArrayIterator;
use crate::array::YrsArrayObservationDelegate;
use crate::change::YrsChange;
use crate::delta::YrsDelta;
Expand Down
4 changes: 1 addition & 3 deletions lib/src/map.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::error::CodingError;
use crate::mapchange::{YrsEntryChange, YrsMapChange};
use crate::transaction::YrsTransaction;
use lib0::any::Any;
use std::cell::RefCell;
use std::fmt::Debug;
use yrs::types::Observable;
use yrs::{types::Value, Map, MapRef};
use yrs::{types::Value, Any, Map, MapRef};

pub(crate) struct YrsMap(RefCell<MapRef>);

Expand Down Expand Up @@ -283,7 +282,6 @@ impl YrsMap {
#[cfg(test)]
mod tests {
use crate::YrsDoc;
use lib0::any::{self, Any};

#[test]
fn verify_new_map_has_zero_count() {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/text.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::attrs::YrsAttrs;
use crate::delta::YrsDelta;
use crate::transaction::YrsTransaction;
use lib0::any::Any;
use yrs::Any;
use std::cell::RefCell;
use std::collections::HashMap;
use std::fmt::Debug;
use yrs::{GetString, Observable, Text, TextRef};

Expand Down
Loading