Skip to content

Commit

Permalink
Fix a bug with Tuple<T1, T2, T3> attributes when the first member …
Browse files Browse the repository at this point in the history
…is a reference type. This caused temporary IDs to not

be resolved correctly when the temporary ID was resolved
  • Loading branch information
halgari committed Aug 19, 2024
1 parent 9013812 commit 5fe612d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

### 0.9.79 - 19/08/2024
* Fix a bug with `Tuple<T1, T2, T3>` attributes when the first member is a reference type. This caused temporary IDs to not
be resolved correctly when the temporary ID was resolved

### 0.9.78 - 15/08/2024
* `Model.ObserveAll` now returns `IObservable<IChangeSet<ReadOnly, EntityId>>` instead of `IObservable<IChangeSet<ReadOnly, DatomKey>>` which makes it
easier to use in projects without polluting the code with `DatomKey` references. `Connection.ObserveDatoms` still returns `IObservable<IChangeSet<Datom, DatomKey>>`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ protected virtual (T1HighLevel, T2HighLevel) FromLowLevel((T1LowLevel, T2LowLeve
throw new NotSupportedException("You must override this method to support low-level conversion.");
}

/// <inheritdoc />
public override void Remap(Func<EntityId, EntityId> remapper, Span<byte> valueSpan)
{
if (_tag1 == ValueTags.Reference)
Expand All @@ -55,7 +56,7 @@ public override void Remap(Func<EntityId, EntityId> remapper, Span<byte> valueSp
}
else if (_tag2 == ValueTags.Reference)
{
throw new NotImplementedException();
throw new NotSupportedException("This attribute does not support remapping of the second element.");
}
}

Expand Down Expand Up @@ -122,17 +123,18 @@ protected virtual (T1HighLevel, T2HighLevel, T3HighLevel) FromLowLevel((T1LowLev
throw new NotSupportedException("You must override this method to support low-level conversion.");
}

/// <inheritdoc />
public override void Remap(Func<EntityId, EntityId> remapper, Span<byte> valueSpan)
{
if (_tag1 == ValueTags.Reference)
{
var entityId = MemoryMarshal.Read<EntityId>(valueSpan.SliceFast(2));
var entityId = MemoryMarshal.Read<EntityId>(valueSpan.SliceFast(3));
var newEntityId = remapper(entityId);
MemoryMarshal.Write(valueSpan.SliceFast(2), newEntityId);
MemoryMarshal.Write(valueSpan.SliceFast(3), newEntityId);
}
else if (_tag2 == ValueTags.Reference)
if (_tag2 == ValueTags.Reference || _tag3 == ValueTags.Reference)
{
throw new NotImplementedException();
throw new NotSupportedException("This attribute does not support remapping of the second or third element.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ public static IObservable<ReadOnly> Observe(IConnection conn, EntityId id)
/// <summary>
/// Observe all models of this type from the database
/// </summary>
public static IObservable<DynamicData.IChangeSet<ReadOnly, DatomKey>> ObserveAll(IConnection conn)
public static IObservable<DynamicData.IChangeSet<ReadOnly, EntityId>> ObserveAll(IConnection conn)
{
return conn.ObserveDatoms(PrimaryAttribute)
.AsEntityIds()
.Transform(d => Load(conn.Db, d.E));
}

Expand Down

0 comments on commit 5fe612d

Please sign in to comment.