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

Update core bindings to Yrs v0.18 #94

Merged
merged 75 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
e3ed5e9
feat: introduce `SubscriptionChannel` to bind `yunobserve()`
LSViana Mar 15, 2024
117872e
feat: update `EventSubscriber` to match `SubscriptionChannel.Unobserv…
LSViana Mar 15, 2024
c375712
feat: update `Array` to use `SubscriptionChannel.Unobserve`
LSViana Mar 15, 2024
aa521ee
feat: update `Branch` to use `SubscriptionChannel.Unobserve`
LSViana Mar 15, 2024
1ff4382
feat: update `Map` to use `SubscriptionChannel.Unobserve`
LSViana Mar 15, 2024
f67d5ca
feat: update `Text` to use `SubscriptionChannel.Unobserve`
LSViana Mar 15, 2024
1f70710
feat: update `XmlElement` to use `SubscriptionChannel.Unobserve`
LSViana Mar 15, 2024
81baa39
feat: update `XmlText` to use `SubscriptionChannel.Unobserve`
LSViana Mar 15, 2024
8efa594
feat: update `UndoManager` to use `SubscriptionChannel.Unobserve`
LSViana Mar 15, 2024
9efa7a6
feat: update `Doc` to use `SubscriptionChannel.Unobserve`
LSViana Mar 15, 2024
1f9415d
test: dispose subscription on tests for `Text.ObserveDeep()`
LSViana Mar 15, 2024
e99603c
style: fix access modifier order in `Branch`
LSViana Mar 15, 2024
fbc9c06
fix: remove unnecessary null conditional operator from `XmlText.Forma…
LSViana Mar 15, 2024
5567037
feat: add the `OutputTag.XmlFragment` constant
LSViana Mar 17, 2024
27e516c
feat: update `EventBranchTag` to include `XmlFragment` and synchroniz…
LSViana Mar 17, 2024
55c6481
feat: synchronize `BranchKind` with `OutputTag`
LSViana Mar 17, 2024
83aae2d
feat: introduce `XmlFragment` and `XmlFragmentEvent`
LSViana Mar 17, 2024
84a04fb
feat: update `XmlElement` and `XmlElementEvent` to inherit from their…
LSViana Mar 17, 2024
90a9a2e
feat: update `Doc` and `DocChannel` to only allow getting root-level …
LSViana Mar 17, 2024
1be876a
feat: update `Transaction` to only allow getting root-level `XmlFragm…
LSViana Mar 17, 2024
7ef9c0d
feat: update `EventBranch` to expose `XmlFragmentEvent`
LSViana Mar 17, 2024
fa0c563
test: update existing unit tests to use root-level `XmlFragment` when…
LSViana Mar 17, 2024
fee50a1
test: introduce unit tests for `XmlFragment`
LSViana Mar 17, 2024
0c4fee3
test: introduce unit tests for `ObserveDeep()` in `XmlFragment`
LSViana Mar 17, 2024
b3ebc36
feat: use exact type comparison to prevent inheritance from allowing …
LSViana Mar 20, 2024
77173f7
feat: drop `BranchChannel.WriteTransaction()`
LSViana Mar 21, 2024
88c8a9e
feat: update `Branch.WriteTransaction()` to use `Doc.WriteTransaction()`
LSViana Mar 21, 2024
a7a70fd
chore: fix typos in `Branch` and `Doc`
LSViana Mar 21, 2024
8d4299f
feat: drop `BranchChannel.ReadTransaction()`
LSViana Mar 21, 2024
98ac727
feat: update `Branch.ReadTransaction()` to use `Doc.ReadTransaction()`
LSViana Mar 21, 2024
b82e13b
feat: update `XmlElement.Parent()` to only return a value if the pare…
LSViana Mar 21, 2024
08b7c5a
test: fix unit tests of `XmlFragment.ObserveDeep()`
LSViana Mar 21, 2024
4cb5cdc
feat: introduce `BranchIdNative*` structs
LSViana Mar 23, 2024
a4bd1ab
feat: introduce `BranchChannel.Id()`
LSViana Mar 23, 2024
85a8c02
feat: introduce `BranchId` class
LSViana Mar 23, 2024
4fa7656
feat: introduce `Branch.Id()` method
LSViana Mar 23, 2024
8e27e88
test: introduce tests for `Branch.Id()`
LSViana Mar 23, 2024
67d0409
feat: drop `BranchId.Length` and rename `HasLengthAndName` to `HasName`
LSViana Mar 23, 2024
80bcf59
docs: add documentation for `BranchId` class and properties
LSViana Mar 23, 2024
aeb97d3
docs: add documentation for `Branch.Id()`
LSViana Mar 23, 2024
30e19c0
test: update unit tests of `Branch.Id()` after API changes on `BranchId`
LSViana Mar 23, 2024
241b8d4
feat: adjust `BranchId` to store a reference to the related `Doc`
LSViana Mar 23, 2024
ffff081
feat: introduce `BranchId.Get()` and `Get()` and `Alive()` in `Branch…
LSViana Mar 23, 2024
97d5cf9
test: introduce tests for `BranchId.Get()`
LSViana Mar 23, 2024
42a989f
feat: introduce `Branch.Alive()`
LSViana Mar 23, 2024
a78770b
test: introduce tests for `Branch.Alive()`
LSViana Mar 23, 2024
94dc35c
revert: use constant numbers in `BranchKind`
LSViana Mar 26, 2024
76cfddc
style: format `Transaction`
LSViana Mar 26, 2024
bdc8975
Test change.
SebastianStehle Apr 14, 2024
a8e313f
feat: remove unused tests and classes
LSViana Apr 24, 2024
4f37b4a
feat: update `Branch` to hold a `BranchIdNative` and expose the `GetH…
LSViana Apr 24, 2024
bc8846d
test: update unit tests to adapt to the new API of `Array.Length()`
LSViana Apr 24, 2024
7a7c2bc
style: inline usages of `GetHandle()` in `Array`
LSViana May 1, 2024
c025081
style: update accessors and code style in `UnmanagedResource`
LSViana May 1, 2024
e3002cb
feat: replace `this.Handle` with `this.GetHandle()` in `Map`
LSViana May 1, 2024
0c810bc
chore: update the demo code to match the new API of `Array`
LSViana May 1, 2024
5a6c00d
feat: replace `this.Handle` with `this.GetHandle()` in `Text`
LSViana May 1, 2024
ebcefa7
fix: use correct handle when reading `XmlTextEvent.Target`
LSViana May 1, 2024
5c8a156
feat: replace `this.Handle` with `this.GetHandle()` in `XmlElement`
LSViana May 1, 2024
4e40f96
feat: replace `this.Handle` with `this.GetHandle()` in `XmlFragment`
LSViana May 1, 2024
02a3120
feat: replace `this.Handle` with `this.GetHandle()` in `XmlText`
LSViana May 1, 2024
f4cb4d3
style: format `Branch` and `UnmanagedResource`
LSViana May 1, 2024
d2499f5
test: update unit tests after migrating `Branch` types to `GetHandle()`
LSViana May 1, 2024
fdef318
test: fix tests for `Doc.ReadTransaction()`
LSViana May 1, 2024
dadf019
feat: drop `Insertions` and `Deletions` from `UndoEvent` and `UndoEve…
LSViana May 1, 2024
0658f50
test: fix tests for `ObserveAdded()` and `ObservePopped()` of `UndoMa…
LSViana May 1, 2024
4792552
ci: fix build patch
LSViana May 1, 2024
33a37b5
ci: fix matrix definition for macOS x86
LSViana May 1, 2024
3deb5d5
feat: replace `EventSubscriber` with `EventSubscriberFromId` in `Map`…
LSViana May 13, 2024
9d88a19
style: use `default` instead of `null` when fetching the `BranchId`
LSViana May 13, 2024
9298507
feat: make `Branch.BranchId` a `private` property
LSViana May 13, 2024
d3e35ce
feat: apply `using` to make the scope of `handle` clearer in `Branch.…
LSViana May 13, 2024
93ff21b
chore: fix warnings throughout the project
LSViana Jun 6, 2024
fb8af80
test: fix unit tests that used `Transaction` incorrectly
LSViana Jun 7, 2024
ba69d10
chore: fix typo in comments of `Transaction.Commit()`
LSViana Jun 7, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
os: ubuntu-latest

# macOS
- build: macos-x86_64
- build: macos-aarch64
os: macos-latest

steps:
Expand Down
102 changes: 55 additions & 47 deletions Demo/Callback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,69 +35,77 @@ public ValueTask OnDocumentLoadedAsync(DocumentLoadEvent @event)

var map = @event.Document.Map("increment");

map?.ObserveDeep(changes =>
{
foreach (var change in changes)
map?.ObserveDeep(
changes =>
{
var key = change.MapEvent?.Keys.FirstOrDefault(x => x.Key == "value" && x.Tag != EventKeyChangeTag.Remove);

if (key != null)
foreach (var change in changes)
{
var valueOld = key.OldValue?.Double;
var valueNew = key.NewValue?.Double;
var key = change.MapEvent?.Keys.FirstOrDefault(
x => x.Key == "value" && x.Tag != EventKeyChangeTag.Remove);

if (valueOld == valueNew)
if (key != null)
{
continue;
}
var valueOld = key.OldValue?.Double;
var valueNew = key.NewValue?.Double;

if (valueOld == valueNew)
{
continue;
}

log.LogInformation("Counter updated from {oldValue} to {newValue}.", valueOld, valueNew);
log.LogInformation("Counter updated from {oldValue} to {newValue}.", valueOld, valueNew);
}
}
}
});
});

var chat = @event.Document.Array("stream");

chat?.ObserveDeep(async changes =>
{
var newNotificationsRaw =
changes
.Where(x => x.Tag == EventBranchTag.Array)
.Select(x => x.ArrayEvent)
.SelectMany(x => x.Delta.Where(x => x.Tag == EventChangeTag.Add))
.SelectMany(x => x.Values)
.ToArray();

if (newNotificationsRaw.Length == 0)
chat?.ObserveDeep(
async changes =>
{
return;
}

await Task.Delay(100);

var notificationCtx = new DocumentContext("notifications", 0);

await @event.Source.UpdateDocAsync(notificationCtx, (doc) =>
{
List<Notification> notifications;

// Keep the transaction open as short as possible.
using (var transaction = @event.Document.ReadTransaction())
var newNotificationsRaw =
changes
.Where(x => x.Tag == EventBranchTag.Array)
.Select(x => x.ArrayEvent)
.SelectMany(x => x.Delta.Where(x => x.Tag == EventChangeTag.Add))
.SelectMany(x => x.Values)
.ToArray();

if (newNotificationsRaw.Length == 0)
{
notifications = newNotificationsRaw.Select(x => x.To<Notification>(transaction)).ToList();
return;
}

var array = doc.Array("stream");
await Task.Delay(millisecondsDelay: 100);

notifications = notifications.Select(x => new Notification { Text = $"You got the follow message: {x.Text}" }).ToList();
var notificationCtx = new DocumentContext("notifications", ClientId: 0);

// Keep the transaction open as short as possible.
using (var transaction = doc.WriteTransaction())
{
array.InsertRange(transaction, array.Length, notifications.Select(x => x.ToInput()).ToArray());
}
await @event.Source.UpdateDocAsync(
notificationCtx, doc =>
{
List<Notification> notifications;

// Keep the transaction open as short as possible.
using (var transaction = @event.Document.ReadTransaction())
{
notifications = newNotificationsRaw.Select(x => x.To<Notification>(transaction)).ToList();
}

var array = doc.Array("stream");

notifications = notifications.Select(
x => new Notification { Text = $"You got the follow message: {x.Text}" })
.ToList();

// Keep the transaction open as short as possible.
using (var transaction = doc.WriteTransaction())
{
array.InsertRange(
transaction, array.Length(transaction),
notifications.Select(x => x.ToInput()).ToArray());
}
});
});
});


return default;
Expand Down
5 changes: 4 additions & 1 deletion Tests/YDotNet.Tests.Unit/Arrays/CreateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ public void Create()

// Act
var array = doc.Array("array");
var transaction = doc.ReadTransaction();
var length = array.Length(transaction);
transaction.Commit();

// Assert
Assert.That(array.Handle, Is.GreaterThan(nint.Zero));
Assert.That(array.Length, Is.EqualTo(expected: 0));
Assert.That(length, Is.EqualTo(expected: 0));
}
}
20 changes: 8 additions & 12 deletions Tests/YDotNet.Tests.Unit/Arrays/InsertRangeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ public void InsertEmptyRange()
// Act
var transaction = doc.WriteTransaction();
array.InsertRange(transaction, index: 0);
var length = array.Length(transaction);
transaction.Commit();

// Assert
Assert.That(array.Length, Is.EqualTo(expected: 0));
Assert.That(length, Is.EqualTo(expected: 0));
}

[Test]
Expand All @@ -32,14 +33,12 @@ public void InsertSingleItemRange()
// Act
var transaction = doc.WriteTransaction();
array.InsertRange(
transaction, index: 0, new[]
{
Input.Boolean(value: true)
});
transaction, index: 0, Input.Boolean(value: true));
var length = array.Length(transaction);
transaction.Commit();

// Assert
Assert.That(array.Length, Is.EqualTo(expected: 1));
Assert.That(length, Is.EqualTo(expected: 1));
}

[Test]
Expand All @@ -52,14 +51,11 @@ public void InsertMultiItemRange()
// Act
var transaction = doc.WriteTransaction();
array.InsertRange(
transaction, index: 0, new[]
{
Input.Boolean(value: true),
Input.Long(value: 2469L)
});
transaction, index: 0, Input.Boolean(value: true), Input.Long(value: 2469L));
var length = array.Length(transaction);
transaction.Commit();

// Assert
Assert.That(array.Length, Is.EqualTo(expected: 2));
Assert.That(length, Is.EqualTo(expected: 2));
}
}
33 changes: 14 additions & 19 deletions Tests/YDotNet.Tests.Unit/Arrays/LengthTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public void InitialLengthIsZero()
var array = doc.Array("array");

// Act
var length = array.Length;
var transaction = doc.ReadTransaction();
var length = array.Length(transaction);
transaction.Commit();

// Assert
Assert.That(length, Is.EqualTo(expected: 0));
Expand All @@ -30,26 +32,22 @@ public void IncreasesWhenAdded()
// Act
var transaction = doc.WriteTransaction();
array.InsertRange(
transaction, index: 0, new[]
{
Input.Boolean(value: true)
});
transaction, index: 0, Input.Boolean(value: true));
var length = array.Length(transaction);
transaction.Commit();

// Assert
Assert.That(array.Length, Is.EqualTo(expected: 1));
Assert.That(length, Is.EqualTo(expected: 1));

// Act
transaction = doc.WriteTransaction();
array.InsertRange(
transaction, index: 0, new[]
{
Input.Boolean(value: true)
});
transaction, index: 0, Input.Boolean(value: true));
length = array.Length(transaction);
transaction.Commit();

// Assert
Assert.That(array.Length, Is.EqualTo(expected: 2));
Assert.That(length, Is.EqualTo(expected: 2));
}

[Test]
Expand All @@ -60,23 +58,20 @@ public void DecreasesWhenRemoved()
var array = doc.Array("array");
var transaction = doc.WriteTransaction();
array.InsertRange(
transaction, index: 0, new[]
{
Input.Boolean(value: true),
Input.Long(value: 2469L),
Input.Undefined()
});
transaction, index: 0, Input.Boolean(value: true), Input.Long(value: 2469L), Input.Undefined());
var length = array.Length(transaction);
transaction.Commit();

// Assert
Assert.That(array.Length, Is.EqualTo(expected: 3));
Assert.That(length, Is.EqualTo(expected: 3));

// Act
transaction = doc.WriteTransaction();
array.RemoveRange(transaction, index: 1, length: 2);
length = array.Length(transaction);
transaction.Commit();

// Assert
Assert.That(array.Length, Is.EqualTo(expected: 1));
Assert.That(length, Is.EqualTo(expected: 1));
}
}
13 changes: 4 additions & 9 deletions Tests/YDotNet.Tests.Unit/Arrays/MoveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void MoveFromBeginningToEnding()

// Act
var transaction = doc.WriteTransaction();
array.Move(transaction, sourceIndex: 0, array.Length);
array.Move(transaction, sourceIndex: 0, array.Length(transaction));
transaction.Commit();

// Assert
Expand All @@ -30,7 +30,7 @@ public void MoveFromEndingToBeginning()

// Act
var transaction = doc.WriteTransaction();
array.Move(transaction, array.Length - 1, targetIndex: 0);
array.Move(transaction, array.Length(transaction) - 1, targetIndex: 0);
transaction.Commit();

// Assert
Expand Down Expand Up @@ -74,13 +74,8 @@ public void MoveToTheSameIndex()

var transaction = doc.WriteTransaction();
array.InsertRange(
transaction, index: 0, new[]
{
Input.Long(value: 1),
Input.Long(value: 2),
Input.Long(value: 3),
Input.Long(value: 4)
});
transaction, index: 0, Input.Long(value: 1), Input.Long(value: 2), Input.Long(value: 3),
Input.Long(value: 4));
transaction.Commit();

return (doc, array);
Expand Down
16 changes: 7 additions & 9 deletions Tests/YDotNet.Tests.Unit/Arrays/RemoveRangeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ public void RemoveEmptyRange()
// Act
var transaction = doc.WriteTransaction();
array.RemoveRange(transaction, index: 0, length: 0);
var length = array.Length(transaction);
transaction.Commit();

// Assert
Assert.That(array.Length, Is.EqualTo(expected: 3));
Assert.That(length, Is.EqualTo(expected: 3));
}

[Test]
Expand All @@ -31,10 +32,11 @@ public void RemoveSingleItemRange()
// Act
var transaction = doc.WriteTransaction();
array.RemoveRange(transaction, index: 1, length: 1);
var length = array.Length(transaction);
transaction.Commit();

// Assert
Assert.That(array.Length, Is.EqualTo(expected: 2));
Assert.That(length, Is.EqualTo(expected: 2));
}

[Test]
Expand All @@ -46,10 +48,11 @@ public void RemoveMultiItemRange()
// Act
var transaction = doc.WriteTransaction();
array.RemoveRange(transaction, index: 0, length: 3);
var length = array.Length(transaction);
transaction.Commit();

// Assert
Assert.That(array.Length, Is.EqualTo(expected: 0));
Assert.That(length, Is.EqualTo(expected: 0));
}

private (Doc, Array) ArrangeDoc()
Expand All @@ -59,12 +62,7 @@ public void RemoveMultiItemRange()

var transaction = doc.WriteTransaction();
array.InsertRange(
transaction, index: 0, new[]
{
Input.Long(value: 420L),
Input.Boolean(value: true),
Input.Null()
});
transaction, index: 0, Input.Long(value: 420L), Input.Boolean(value: true), Input.Null());
transaction.Commit();

return (doc, array);
Expand Down
Loading
Loading